Class: Rugged::Tree::Builder
- Inherits:
-
Object
- Object
- Rugged::Tree::Builder
- Defined in:
- ext/rugged/rugged_tree.c
Class Method Summary collapse
-
.Tree::Builder.new(repository, [tree]) ⇒ Object
Create a new Rugged::Tree::Builder instance to write a tree to the given
repository.
Instance Method Summary collapse
-
#<<(rb_entry) ⇒ Object
Inser a new entry into
builder. -
#[](path) ⇒ Object
Return an entry from
builderbased on its relative path. -
#clear ⇒ nil
Clear all entries in
builder. -
#insert(rb_entry) ⇒ Object
Inser a new entry into
builder. -
#reject! {|entry| ... } ⇒ nil
Deletes every tree
entryfrombuilderfor which the givenblockevaluates to true. -
#remove(path) ⇒ Boolean
Remove an entry from
builderby its relativepath. -
#write ⇒ Object
Write +builder+'s content as a tree to the repository that owns the builder and return the
oidfor the newly created tree.
Class Method Details
.Tree::Builder.new(repository, [tree]) ⇒ Object
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.
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'ext/rugged/rugged_tree.c', line 739
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");
TypedData_Get_Struct(rb_object, git_tree, &rugged_object_type, tree);
}
rugged_check_repo(rb_repo);
TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
error = git_treebuilder_new(&builder, repo, tree);
rugged_exception_check(error);
rb_builder = TypedData_Wrap_Struct(klass, &rugged_treebuilder_type, builder);
rugged_set_owner(rb_builder, rb_repo);
return rb_builder;
}
|
Instance Method Details
#<<(entry) ⇒ nil #insert(entry) ⇒ nil
Inser a new entry into builder.
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
# File 'ext/rugged/rugged_tree.c', line 803
static VALUE rb_git_treebuilder_insert(VALUE self, VALUE rb_entry)
{
git_treebuilder *builder;
VALUE rb_path, rb_oid, rb_attr;
git_oid oid;
int error;
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
Check_Type(rb_entry, T_HASH);
rb_path = rb_hash_aref(rb_entry, CSTR2SYM("name"));
Check_Type(rb_path, T_STRING);
rb_oid = rb_hash_aref(rb_entry, CSTR2SYM("oid"));
Check_Type(rb_oid, T_STRING);
rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(rb_oid)));
rb_attr = rb_hash_aref(rb_entry, CSTR2SYM("filemode"));
Check_Type(rb_attr, T_FIXNUM);
error = git_treebuilder_insert(NULL,
builder,
StringValueCStr(rb_path),
&oid,
FIX2INT(rb_attr));
rugged_exception_check(error);
return Qnil;
}
|
#[](path) ⇒ Object
Return an entry from builder based on its relative path.
786 787 788 789 790 791 792 793 794 |
# File 'ext/rugged/rugged_tree.c', line 786
static VALUE rb_git_treebuilder_get(VALUE self, VALUE path)
{
git_treebuilder *builder;
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
Check_Type(path, T_STRING);
return rb_git_treeentry_fromC(git_treebuilder_get(builder, StringValueCStr(path)));
}
|
#clear ⇒ nil
Clear all entries in builder.
772 773 774 775 776 777 778 |
# File 'ext/rugged/rugged_tree.c', line 772
static VALUE rb_git_treebuilder_clear(VALUE self)
{
git_treebuilder *builder;
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
git_treebuilder_clear(builder);
return Qnil;
}
|
#<<(entry) ⇒ nil #insert(entry) ⇒ nil
Inser a new entry into builder.
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
# File 'ext/rugged/rugged_tree.c', line 803
static VALUE rb_git_treebuilder_insert(VALUE self, VALUE rb_entry)
{
git_treebuilder *builder;
VALUE rb_path, rb_oid, rb_attr;
git_oid oid;
int error;
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
Check_Type(rb_entry, T_HASH);
rb_path = rb_hash_aref(rb_entry, CSTR2SYM("name"));
Check_Type(rb_path, T_STRING);
rb_oid = rb_hash_aref(rb_entry, CSTR2SYM("oid"));
Check_Type(rb_oid, T_STRING);
rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(rb_oid)));
rb_attr = rb_hash_aref(rb_entry, CSTR2SYM("filemode"));
Check_Type(rb_attr, T_FIXNUM);
error = git_treebuilder_insert(NULL,
builder,
StringValueCStr(rb_path),
&oid,
FIX2INT(rb_attr));
rugged_exception_check(error);
return Qnil;
}
|
#reject! {|entry| ... } ⇒ nil
Deletes every tree entry from builder for which
the given block evaluates to true.
897 898 899 900 901 902 903 904 905 906 |
# File 'ext/rugged/rugged_tree.c', line 897
static VALUE rb_git_treebuilder_filter(VALUE self)
{
git_treebuilder *builder;
rb_need_block();
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
git_treebuilder_filter(builder, &treebuilder_cb, (void *)rb_block_proc());
return Qnil;
}
|
#remove(path) ⇒ Boolean
Remove an entry from builder by its relative path.
Returns true if the entry was successfully removed,
or false if the entry was not found.
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
# File 'ext/rugged/rugged_tree.c', line 842
static VALUE rb_git_treebuilder_remove(VALUE self, VALUE path)
{
git_treebuilder *builder;
int error;
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
Check_Type(path, T_STRING);
error = git_treebuilder_remove(builder, StringValueCStr(path));
if (error == GIT_ENOTFOUND) {
return Qfalse;
} else if (error == GIT_ERROR && giterr_last()->klass == GITERR_TREE) {
return Qfalse;
}
rugged_exception_check(error);
return Qtrue;
}
|
#write ⇒ Object
Write +builder+'s content as a tree to the repository
that owns the builder and return the oid for the
newly created tree.
869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'ext/rugged/rugged_tree.c', line 869
static VALUE rb_git_treebuilder_write(VALUE self)
{
git_treebuilder *builder;
git_oid written_id;
int error;
TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
error = git_treebuilder_write(&written_id, builder);
rugged_exception_check(error);
return rugged_create_oid(&written_id);
}
|