Ejemplo n.º 1
0
/*
 *  call-seq:
 *    Tree::Builder.new(repository, [tree])
 *
 *  Create a new Rugged::Tree::Builder instance to write a tree to
 *  the given +repository+.
 *
 *  If an optional +tree+ is given, the returned Tree::Builder will be
 *  initialized with the entry of +tree+. Otherwise, the Tree::Builder
 *  will be empty and has to be filled manually.
 */
static VALUE rb_git_treebuilder_new(int argc, VALUE *argv, VALUE klass)
{
	git_treebuilder *builder;
	git_repository *repo;
	git_tree *tree = NULL;
	VALUE rb_object, rb_builder, rb_repo;
	int error;

	if (rb_scan_args(argc, argv, "11", &rb_repo, &rb_object) == 2) {
		if (!rb_obj_is_kind_of(rb_object, rb_cRuggedTree))
			rb_raise(rb_eTypeError, "A Rugged::Tree instance is required");

		Data_Get_Struct(rb_object, git_tree, tree);
	}

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_treebuilder_new(&builder, repo, tree);
	rugged_exception_check(error);

	rb_builder = Data_Wrap_Struct(klass, NULL, &rb_git_treebuilder_free, builder);
	rugged_set_owner(rb_builder, rb_repo);

	return rb_builder;
}
Ejemplo n.º 2
0
VALUE rugged_remote_new(VALUE klass, VALUE owner, git_remote *remote)
{
	VALUE rb_remote;

	rb_remote = Data_Wrap_Struct(klass, NULL, &rb_git_remote__free, remote);
	rugged_set_owner(rb_remote, owner);
	return rb_remote;
}
VALUE rugged_submodule_new(VALUE owner, git_submodule *submodule)
{
	VALUE rb_submodule;

	rb_submodule = Data_Wrap_Struct(
			rb_cRuggedSubmodule,
			NULL,
			&rb_git_submodule__free,
			submodule);
	rugged_set_owner(rb_submodule, owner);

	return rb_submodule;
}
VALUE rugged_diff_delta_new(VALUE owner, const git_diff_delta *delta)
{
	VALUE rb_delta = rb_class_new_instance(0, NULL, rb_cRuggedDiffDelta);

	rugged_set_owner(rb_delta, owner);
	rb_iv_set(rb_delta, "@old_file", rb_git_delta_file_fromC(&delta->old_file));
	rb_iv_set(rb_delta, "@new_file", rb_git_delta_file_fromC(&delta->new_file));
	rb_iv_set(rb_delta, "@similarity", INT2FIX(delta->similarity));
	rb_iv_set(rb_delta, "@status", rb_git_delta_status_fromC(delta->status));
	rb_iv_set(rb_delta, "@binary",
		(!(delta->flags & GIT_DIFF_FLAG_NOT_BINARY) &&
		 (delta->flags & GIT_DIFF_FLAG_BINARY)) ? Qtrue : Qfalse
	);

	return rb_delta;
}
Ejemplo n.º 5
0
VALUE rugged_diff_hunk_new(VALUE owner, size_t hunk_idx, const git_diff_hunk *hunk, size_t lines_in_hunk)
{
	VALUE rb_hunk = rb_class_new_instance(0, NULL, rb_cRuggedDiffHunk);
	rugged_set_owner(rb_hunk, owner);

	rb_iv_set(rb_hunk, "@header", rb_str_new(hunk->header, hunk->header_len));
	rb_iv_set(rb_hunk, "@line_count", INT2FIX(lines_in_hunk));
	rb_iv_set(rb_hunk, "@hunk_index", INT2FIX(hunk_idx));

	rb_iv_set(rb_hunk, "@old_start", INT2FIX(hunk->old_start));
	rb_iv_set(rb_hunk, "@old_lines", INT2FIX(hunk->old_lines));
	rb_iv_set(rb_hunk, "@new_start", INT2FIX(hunk->new_start));
	rb_iv_set(rb_hunk, "@new_lines", INT2FIX(hunk->new_lines));

	return rb_hunk;
}
Ejemplo n.º 6
0
VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index)
{
	VALUE rb_index = Data_Wrap_Struct(klass, NULL, &rb_git_index__free, index);
	rugged_set_owner(rb_index, owner);
	return rb_index;
}
/*
 *  call-seq:
 *    SubmoduleCollection.new(repo) -> submodules
 *
 *  Creates and returns a new collection of submodules for the given +repo+.
 */
static VALUE rb_git_submodule_collection_initialize(VALUE self, VALUE rb_repo)
{
	rugged_check_repo(rb_repo);
	rugged_set_owner(self, rb_repo);
	return self;
}
Ejemplo n.º 8
0
VALUE rugged_walker_new(VALUE klass, VALUE owner, git_revwalk *walk)
{
	VALUE rb_walk = Data_Wrap_Struct(klass, NULL, &rb_git_walk__free, walk);
	rugged_set_owner(rb_walk, owner);
	return rb_walk;
}
/*
 *  call-seq:
 *    RemoteCollection.new(repo) -> remotes
 *
 *  Creates and returns a new collection of remotes for the given +repo+.
 */
static VALUE rb_git_remote_collection_initialize(VALUE self, VALUE repo)
{
	rugged_set_owner(self, repo);
	return self;
}
Ejemplo n.º 10
0
VALUE rugged_patch_new(VALUE owner, git_patch *patch)
{
    VALUE rb_patch = Data_Wrap_Struct(rb_cRuggedPatch, NULL, &git_patch_free, patch);
    rugged_set_owner(rb_patch, owner);
    return rb_patch;
}
Ejemplo n.º 11
0
VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref)
{
	VALUE rb_ref = Data_Wrap_Struct(klass, NULL, &rb_git_ref__free, ref);
	rugged_set_owner(rb_ref, owner);
	return rb_ref;
}