Exemplo n.º 1
0
/*
 *  call-seq:
 *    tag.target -> git_object
 */
static VALUE rb_git_tag_target(VALUE self)
{
	git_reference *ref, *resolved_ref;
	git_repository *repo;
	git_object *target;
	int error;
	VALUE rb_repo = rugged_owner(self);

	rugged_check_repo(rb_repo);
	Data_Get_Struct(self, git_reference, ref);
	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_reference_resolve(&resolved_ref, ref);
	rugged_exception_check(error);

	error = git_object_lookup(&target, repo, git_reference_target(resolved_ref), GIT_OBJ_ANY);
	git_reference_free(resolved_ref);
	rugged_exception_check(error);

	if (git_object_type(target) == GIT_OBJ_TAG) {
		git_object *annotation_target;

		error = git_tag_target(&annotation_target, (git_tag *)target);
		git_object_free(target);
		rugged_exception_check(error);

		return rugged_object_new(rb_repo, annotation_target);
	} else {
		return rugged_object_new(rb_repo, target);
	}
}
Exemplo n.º 2
0
static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object_id, void *data)
{
	VALUE rb_args = rb_ary_new2(2);
	struct rugged_cb_payload *payload = data;
	git_object *annotated_object;
	git_object *note_blob;

	git_repository *repo;

	Data_Get_Struct(payload->rb_data, git_repository, repo);

	rugged_exception_check(
		git_object_lookup(&annotated_object, repo, annotated_object_id, GIT_OBJ_ANY)
	);

	rugged_exception_check(
		git_object_lookup(&note_blob, repo, blob_id, GIT_OBJ_BLOB)
	);

	rb_ary_push(rb_args, rugged_object_new(payload->rb_data, note_blob));
	rb_ary_push(rb_args, rugged_object_new(payload->rb_data, annotated_object));

	rb_protect(rb_yield_splat, rb_args, &payload->exception);

	return payload->exception ? GIT_ERROR : GIT_OK;
}
Exemplo n.º 3
0
/*
 *  call-seq:
 *    walker.each { |commit| block }
 *    walker.each -> Iterator
 *
 *  Perform the walk through the repository, yielding each
 *  one of the commits found as a <tt>Rugged::Commit</tt> instance
 *  to +block+.
 *
 *  If no +block+ is given, an +Iterator+ will be returned.
 *
 *  The walker must have been previously set-up before a walk can be performed
 *  (i.e. at least one commit must have been pushed).
 *
 *    walker.push("92b22bbcb37caf4f6f53d30292169e84f5e4283b")
 *    walker.each { |commit| puts commit.oid }
 *
 *  generates:
 *
 *    92b22bbcb37caf4f6f53d30292169e84f5e4283b
 *    6b750d5800439b502de669465b385e5f469c78b6
 *    ef9207141549f4ffcd3c4597e270d32e10d0a6bc
 *    cb75e05f0f8ac3407fb3bd0ebd5ff07573b16c9f
 *    ...
 */
static VALUE rb_git_walker_each(VALUE self)
{
	git_revwalk *walk;
	git_commit *commit;
	git_repository *repo;
	git_oid commit_oid;
	int error;

	Data_Get_Struct(self, git_revwalk, walk);
	repo = git_revwalk_repository(walk);

	if (!rb_block_given_p())
		return rb_funcall(self, rb_intern("to_enum"), 0);

	while ((error = git_revwalk_next(&commit_oid, walk)) == 0) {
		error = git_commit_lookup(&commit, repo, &commit_oid);
		rugged_exception_check(error);

		rb_yield(rugged_object_new(rugged_owner(self), (git_object *)commit));
	}

	if (error != GIT_ITEROVER)
		rugged_exception_check(error);

	return Qnil;
}
Exemplo n.º 4
0
static VALUE rb_git_tag_target_GET(VALUE self)
{
	git_tag *tag;
	VALUE owner;

	RUGGED_OBJ_UNWRAP(self, git_tag, tag);
	RUGGED_OBJ_OWNER(self, owner);

	return rugged_object_new(owner, (git_object*)git_tag_target(tag));
}
Exemplo n.º 5
0
static VALUE rb_git_commit_tree_GET(VALUE self)
{
	git_commit *commit;
	const git_tree *tree;
	VALUE owner;

	RUGGED_OBJ_UNWRAP(self, git_commit, commit);
	RUGGED_OBJ_OWNER(self, owner);

	tree = git_commit_tree(commit);
	return tree ? rugged_object_new(owner, (git_object *)tree) : Qnil;
}
Exemplo n.º 6
0
static VALUE rb_git_tree_entry_2object(VALUE self)
{
	rugged_tree_entry *tree_entry;
	rugged_object *owner_tree;
	git_object *object;
	int error;

	Data_Get_Struct(self, rugged_tree_entry, tree_entry);
	Data_Get_Struct(tree_entry->tree, rugged_object, owner_tree);

	error = git_tree_entry_2object(&object, tree_entry->entry);
	rugged_exception_check(error);

	return rugged_object_new(owner_tree->owner, object);
}
Exemplo n.º 7
0
/*
 *  call-seq:
 *    commit.tree -> tree
 *
 *  Return the tree pointed at by this +commit+. The tree is
 *  returned as a +Rugged::Tree+ object.
 *
 *    commit.tree #=> #<Rugged::Tree:0x10882c680>
 */
static VALUE rb_git_commit_tree_GET(VALUE self)
{
	git_commit *commit;
	git_tree *tree;
	VALUE owner;
	int error;

	Data_Get_Struct(self, git_commit, commit);
	owner = rugged_owner(self);

	error = git_commit_tree(&tree, commit);
	rugged_exception_check(error);

	return rugged_object_new(owner, (git_object *)tree);
}
Exemplo n.º 8
0
/*
 *  call-seq:
 *    annotation.target -> object
 *
 *  Return the +object+ pointed at by this tag annotation, as a <tt>Rugged::Object</tt>
 *  instance.
 *
 *    annotation.target #=> #<Rugged::Commit:0x108828918>
 */
static VALUE rb_git_tag_annotation_target(VALUE self)
{
	git_tag *tag;
	git_object *target;
	int error;
	VALUE owner;

	Data_Get_Struct(self, git_tag, tag);
	owner = rugged_owner(self);

	error = git_tag_target(&target, tag);
	rugged_exception_check(error);

	return rugged_object_new(owner, target);
}
Exemplo n.º 9
0
static VALUE rb_git_tag_target_GET(VALUE self)
{
	git_tag *tag;
	git_object *target;
	int error;
	VALUE owner;

	RUGGED_OBJ_UNWRAP(self, git_tag, tag);
	RUGGED_OBJ_OWNER(self, owner);

	error = git_tag_target(&target, tag);
	rugged_exception_check(error);

	return rugged_object_new(owner, target);
}
Exemplo n.º 10
0
static VALUE rb_git_commit_parents_GET(VALUE self)
{
	git_commit *commit;
	git_commit *parent;
	unsigned int n;
	VALUE ret_arr, owner;

	RUGGED_OBJ_UNWRAP(self, git_commit, commit);
	RUGGED_OBJ_OWNER(self, owner);

	ret_arr = rb_ary_new();
	for (n = 0; (parent = git_commit_parent(commit, n)) != NULL; n++) {
		rb_ary_store(ret_arr, n, rugged_object_new(owner, (git_object *)parent));
	}

	return ret_arr;
}
Exemplo n.º 11
0
/*
 *  call-seq:
 *    tags.create_annotation(name, target, annotation) -> annotation
 *
 *  Create a new annotated tag object with the specified +name+ on +target+ in
 *  +repo+.
 *
 *  Unlike the +create+ method, +create_annotation+ simply creates a tag
 *  object. It does not write a tag ref.
 *
 *  +annotation+ must have the following keys:
 *
 *  :tagger ::
 *    An optional Hash containing a git signature. Defaults to the signature
 *    from the configuration if only `:message` is given. Will cause the
 *    creation of an annotated tag object if present.
 *
 *  :message ::
 *    An optional string containing the message for the new tag.
 *
 *  Returns an instance of Rugged::Tag::Annotation representing the newly
 *  created annotation.
 */
static VALUE rb_git_tag_collection_create_annotation(VALUE self, VALUE rb_name, VALUE rb_target, VALUE rb_annotation)
{
	git_oid tag_oid;
	git_repository *repo = NULL;
	git_object *target = NULL, *tag = NULL;
	git_signature *tagger = NULL;
	VALUE rb_message;
	int error;

	VALUE rb_repo = rugged_owner(self);
	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	Check_Type(rb_name, T_STRING);

	target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);

	rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message"));
	Check_Type(rb_message, T_STRING);

	tagger = rugged_signature_get(
		rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo
	);

	error = git_tag_annotation_create(
		&tag_oid,
		repo,
		StringValueCStr(rb_name),
		target,
		tagger,
		StringValueCStr(rb_message)
	);

	git_object_free(target);
	git_signature_free(tagger);

	rugged_exception_check(error);

	error = git_object_lookup(&tag, repo, &tag_oid, GIT_OBJ_TAG);
	rugged_exception_check(error);

	return rugged_object_new(rb_repo, tag);
}
Exemplo n.º 12
0
/*
 *  call-seq:
 *    commit.parents -> [commit, ...]
 *
 *  Return the parent(s) of this commit as an array of +Rugged::Commit+
 *  objects. An array is always returned even when the commit has only
 *  one or zero parents.
 *
 *    commit.parents #=> => [#<Rugged::Commit:0x108828918>]
 *    root.parents #=> []
 */
static VALUE rb_git_commit_parents_GET(VALUE self)
{
	git_commit *commit;
	git_commit *parent;
	unsigned int n, parent_count;
	VALUE ret_arr, owner;
	int error;

	Data_Get_Struct(self, git_commit, commit);
	owner = rugged_owner(self);

	parent_count = git_commit_parentcount(commit);
	ret_arr = rb_ary_new2((long)parent_count);

	for (n = 0; n < parent_count; n++) {
		error = git_commit_parent(&parent, commit, n);
		rugged_exception_check(error);
		rb_ary_push(ret_arr, rugged_object_new(owner, (git_object *)parent));
	}

	return ret_arr;
}
Exemplo n.º 13
0
/*
 *  call-seq:
 *    tag.annotation -> annotation or nil
 */
static VALUE rb_git_tag_annotation(VALUE self)
{
	git_reference *ref, *resolved_ref;
	git_repository *repo;
	git_object *target;
	int error;
	VALUE rb_repo = rugged_owner(self);

	rugged_check_repo(rb_repo);
	Data_Get_Struct(self, git_reference, ref);
	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_reference_resolve(&resolved_ref, ref);
	rugged_exception_check(error);

	error = git_object_lookup(&target, repo, git_reference_target(resolved_ref), GIT_OBJ_TAG);
	git_reference_free(resolved_ref);

	if (error == GIT_ENOTFOUND)
		return Qnil;

	return rugged_object_new(rb_repo, target);
}
Exemplo n.º 14
0
/*
 *  call-seq:
 *    reference.target_id -> id
 *    reference.target_id -> ref_name
 *
 *  Return the target of +reference+.
 *
 *  If +reference+ is a symbolic reference, it returns the target
 *  reference object.
 *
 *  If +reference+ is a direct reference, it returns the target object.
 *
 *    ref1.type #=> :symbolic
 *    ref1.target #=> #<Rugged::Reference ...>
 *
 *    ref2.type #=> :direct
 *    ref2.target #=> #<Rugged::Commit ...>
 */
static VALUE rb_git_ref_target(VALUE self)
{
	git_reference *ref;

	Data_Get_Struct(self, git_reference, ref);

	if (git_reference_type(ref) == GIT_REF_OID) {
		git_object *target;

		rugged_exception_check(
			git_object_lookup(&target, git_reference_owner(ref), git_reference_target(ref), GIT_OBJ_ANY)
		);
		return rugged_object_new(rugged_owner(self), target);
	} else {
		git_reference *target;

		rugged_exception_check(
			git_reference_lookup(&target, git_reference_owner(ref), git_reference_symbolic_target(ref))
		);

		return rugged_ref_new(rb_cRuggedReference, rugged_owner(self), target);
	}
}