Class: Rugged::Tree
- Inherits:
-
RuggedObject
- Object
- RuggedObject
- Rugged::Tree
- Includes:
- Enumerable
- Defined in:
- lib/rugged/tree.rb,
lib/rugged/objects.rb,
ext/rugged/rugged_tree.c
Defined Under Namespace
Classes: Builder
Instance Method Summary collapse
- #[](entry_id) ⇒ Object
-
#count ⇒ Object
Rugged Tree.
- #each ⇒ Object
-
#each_blob ⇒ Object
Iterate over the blobs in this tree.
-
#each_tree ⇒ Object
Iterat over the subtrees in this tree.
- #get_entry(entry_id) ⇒ Object
- #get_subtree(rb_path) ⇒ Object
-
#length ⇒ Object
Rugged Tree.
- #walk(rb_mode) ⇒ Object
-
#walk_blobs(mode = :postorder) ⇒ Object
Walks the tree but only yields blobs.
-
#walk_trees(mode = :postorder) ⇒ Object
Walks the tree but only yields subtrees.
Instance Method Details
#[](entry_id) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/rugged/rugged_tree.c', line 78
static VALUE rb_git_tree_get_entry(VALUE self, VALUE entry_id)
{
git_tree *tree;
Data_Get_Struct(self, git_tree, tree);
if (TYPE(entry_id) == T_FIXNUM)
return rb_git_treeentry_fromC(git_tree_entry_byindex(tree, FIX2INT(entry_id)));
else if (TYPE(entry_id) == T_STRING)
return rb_git_treeentry_fromC(git_tree_entry_byname(tree, StringValueCStr(entry_id)));
else
rb_raise(rb_eTypeError, "entry_id must be either an index or a filename");
}
|
#count ⇒ Object
Rugged Tree
70 71 72 73 74 75 76 |
# File 'ext/rugged/rugged_tree.c', line 70
static VALUE rb_git_tree_entrycount(VALUE self)
{
git_tree *tree;
Data_Get_Struct(self, git_tree, tree);
return INT2FIX(git_tree_entrycount(tree));
}
|
#each ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/rugged/rugged_tree.c', line 93
static VALUE rb_git_tree_each(VALUE self)
{
git_tree *tree;
unsigned int i, count;
Data_Get_Struct(self, git_tree, tree);
if (!rb_block_given_p())
return rb_funcall(self, rb_intern("to_enum"), 0);
count = git_tree_entrycount(tree);
for (i = 0; i < count; ++i) {
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
rb_yield(rb_git_treeentry_fromC(entry));
}
return Qnil;
}
|
#each_blob ⇒ Object
Iterate over the blobs in this tree
14 15 16 |
# File 'lib/rugged/tree.rb', line 14 def each_blob self.each { |e| yield e if e[:type] == :blob } end |
#each_tree ⇒ Object
Iterat over the subtrees in this tree
19 20 21 |
# File 'lib/rugged/tree.rb', line 19 def each_tree self.each { |e| yield e if e[:type] == :tree } end |
#get_entry(entry_id) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/rugged/rugged_tree.c', line 78
static VALUE rb_git_tree_get_entry(VALUE self, VALUE entry_id)
{
git_tree *tree;
Data_Get_Struct(self, git_tree, tree);
if (TYPE(entry_id) == T_FIXNUM)
return rb_git_treeentry_fromC(git_tree_entry_byindex(tree, FIX2INT(entry_id)));
else if (TYPE(entry_id) == T_STRING)
return rb_git_treeentry_fromC(git_tree_entry_byname(tree, StringValueCStr(entry_id)));
else
rb_raise(rb_eTypeError, "entry_id must be either an index or a filename");
}
|
#get_subtree(rb_path) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/rugged/rugged_tree.c', line 149
static VALUE rb_git_tree_subtree(VALUE self, VALUE rb_path)
{
int error;
git_tree *tree, *subtree;
VALUE owner;
Data_Get_Struct(self, git_tree, tree);
owner = rugged_owner(self);
Check_Type(rb_path, T_STRING);
error = git_tree_get_subtree(&subtree, tree, StringValueCStr(rb_path));
rugged_exception_check(error);
return rugged_object_new(owner, (git_object *)subtree);
}
|
#length ⇒ Object
Rugged Tree
70 71 72 73 74 75 76 |
# File 'ext/rugged/rugged_tree.c', line 70
static VALUE rb_git_tree_entrycount(VALUE self)
{
git_tree *tree;
Data_Get_Struct(self, git_tree, tree);
return INT2FIX(git_tree_entrycount(tree));
}
|
#walk(rb_mode) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'ext/rugged/rugged_tree.c', line 121
static VALUE rb_git_tree_walk(VALUE self, VALUE rb_mode)
{
git_tree *tree;
int error, mode = 0;
ID id_mode;
Data_Get_Struct(self, git_tree, tree);
if (!rb_block_given_p())
return rb_funcall(self, rb_intern("to_enum"), 2, CSTR2SYM("walk"), rb_mode);
Check_Type(rb_mode, T_SYMBOL);
id_mode = SYM2ID(rb_mode);
if (id_mode == rb_intern("preorder"))
mode = GIT_TREEWALK_PRE;
else if (id_mode == rb_intern("postorder"))
mode = GIT_TREEWALK_POST;
else
rb_raise(rb_eTypeError,
"Invalid iteration mode. Expected `:preorder` or `:postorder`");
error = git_tree_walk(tree, &rugged__treewalk_cb, mode, (void *)rb_block_proc());
rugged_exception_check(error);
return Qnil;
}
|