Class: Rugged::Walker
- Inherits:
-
Object
- Object
- Rugged::Walker
- Includes:
- Enumerable
- Defined in:
- lib/rugged/walker.rb,
ext/rugged/rugged_revwalk.c
Class Method Summary collapse
-
.new(repository) ⇒ Object
Create a new
Walkerinstance able to walk commits found inrepository, which is a Rugged::Repository instance. -
.Rugged::Walker.walk(repo, options) { ... } ⇒ Object
Create a Walker object, initialize it with the given options and perform a walk on the repository; the lifetime of the walker is bound to the call and it is immediately cleaned up after the walk is over.
Instance Method Summary collapse
-
#count ⇒ Fixnum
Returns the amount of objects a walker iterated over.
-
#each(*args) ⇒ Object
Perform the walk through the repository, yielding each one of the commits found as a Rugged::Commit instance to
block. -
#each_oid(*args) ⇒ Object
Perform the walk through the repository, yielding each one of the commit oids found as a String to
block. -
#hide(commit) ⇒ nil
Hide the given
commit(and all its parents) from the output in the revision walk. -
#push(commit) ⇒ nil
Push one new
committo start the walk from. - #push_range(range) ⇒ Object
-
#reset ⇒ nil
Remove all pushed and hidden commits and reset the
walkerback into a blank state. -
#simplify_first_parent ⇒ nil
Simplify the walk to the first parent of each commit.
-
#sorting(sort_mode) ⇒ nil
Change the sorting mode for the revision walk.
-
#walk(*args) ⇒ Object
Perform the walk through the repository, yielding each one of the commits found as a Rugged::Commit instance to
block.
Class Method Details
.new(repository) ⇒ Object
Create a new Walker instance able to walk commits found
in repository, which is a Rugged::Repository instance.
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/rugged/rugged_revwalk.c', line 97
static VALUE rb_git_walker_new(VALUE klass, VALUE rb_repo)
{
git_repository *repo;
git_revwalk *walk;
int error;
TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
error = git_revwalk_new(&walk, repo);
rugged_exception_check(error);
return rugged_walker_new(klass, rb_repo, walk);;
}
|
.Rugged::Walker.walk(repo, options) { ... } ⇒ Object
Create a Walker object, initialize it with the given options and perform a walk on the repository; the lifetime of the walker is bound to the call and it is immediately cleaned up after the walk is over.
The following options are available:
-
sort: Sorting mode for the walk (or an OR combination of several sorting modes). -
show: Tips of the repository that will be walked; this is necessary for the walk to yield any results. A tip can be a 40-char object ID, an existingRugged::Commitobject, a reference, or anArrayof several of these (if you'd like to walk several tips in parallel). -
hide: Same asshow, but hides the given tips instead so they don't appear on the walk. -
oid_only: iftrue, the walker will yield 40-char OIDs for each commit, instead of realRugged::Commitobjects. Defaults tofalse. -
simplify: iftrue, the walk will be simplified to the first parent of each commit.
Example:
Rugged::Walker.walk(repo,
show: "92b22bbcb37caf4f6f53d30292169e84f5e4283b",
sort: Rugged::SORT_DATE|Rugged::SORT_TOPO,
oid_only: true) do |commit_oid|
puts commit_oid
end
generates:
92b22bbcb37caf4f6f53d30292169e84f5e4283b
6b750d5800439b502de669465b385e5f469c78b6
ef9207141549f4ffcd3c4597e270d32e10d0a6bc
cb75e05f0f8ac3407fb3bd0ebd5ff07573b16c9f
...
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'ext/rugged/rugged_revwalk.c', line 374
static VALUE rb_git_walk(int argc, VALUE *argv, VALUE self)
{
VALUE rb_repo, rb_options;
struct walk_options w;
int exception = 0;
RETURN_ENUMERATOR(self, argc, argv);
rb_scan_args(argc, argv, "10:", &rb_repo, &rb_options);
TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, w.repo);
rugged_exception_check(git_revwalk_new(&w.walk, w.repo));
w.rb_owner = rb_repo;
w.rb_options = rb_options;
w.oid_only = 0;
w.offset = 0;
w.limit = UINT64_MAX;
if (!NIL_P(w.rb_options))
rb_protect(load_all_options, (VALUE)&w, &exception);
if (!exception)
rb_protect(do_walk, (VALUE)&w, &exception);
git_revwalk_free(w.walk);
if (exception)
rb_jump_tag(exception);
return Qnil;
}
|
Instance Method Details
#count ⇒ Fixnum
Returns the amount of objects a walker iterated over. If an argument or
block is given this method delegates to Enumerable#count.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'ext/rugged/rugged_revwalk.c', line 195
static VALUE rb_git_walker_count(int argc, VALUE *argv, VALUE self)
{
git_revwalk *walk;
git_oid commit_oid;
int error = 0;
uint64_t count = 0;
if (argc > 0 || rb_block_given_p())
return rb_call_super(argc, argv);
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
while (((error = git_revwalk_next(&commit_oid, walk)) == 0) && ++count != UINT64_MAX);
if (error != GIT_ITEROVER)
rugged_exception_check(error);
return ULONG2NUM(count);
}
|
#each {|commit| ... } ⇒ Object #each ⇒ Enumerator
Perform the walk through the repository, yielding each
one of the commits found as a Rugged::Commit instance
to block.
If no block is given, an Enumerator 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
...
456 457 458 459 |
# File 'ext/rugged/rugged_revwalk.c', line 456
static VALUE rb_git_walker_each(int argc, VALUE *argv, VALUE self)
{
return rb_git_walk_with_opts(argc, argv, self, 0);
}
|
#each_oid {|commit| ... } ⇒ Object #each_oid ⇒ Enumerator
Perform the walk through the repository, yielding each
one of the commit oids found as a String
to block.
If no block is given, an Enumerator 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_oid| puts commit_oid }
generates:
92b22bbcb37caf4f6f53d30292169e84f5e4283b
6b750d5800439b502de669465b385e5f469c78b6
ef9207141549f4ffcd3c4597e270d32e10d0a6bc
cb75e05f0f8ac3407fb3bd0ebd5ff07573b16c9f
...
486 487 488 489 |
# File 'ext/rugged/rugged_revwalk.c', line 486
static VALUE rb_git_walker_each_oid(int argc, VALUE *argv, VALUE self)
{
return rb_git_walk_with_opts(argc, argv, self, 1);
}
|
#hide(commit) ⇒ nil
Hide the given commit (and all its parents) from the
output in the revision walk.
150 151 152 153 154 155 156 |
# File 'ext/rugged/rugged_revwalk.c', line 150
static VALUE rb_git_walker_hide(VALUE self, VALUE rb_commit)
{
git_revwalk *walk;
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
push_commit(walk, rb_commit, 1);
return Qnil;
}
|
#push(commit) ⇒ nil
Push one new commit to start the walk from. commit must be a
String with the OID of a commit in the repository, or a Rugged::Commit
instance.
More than one commit may be pushed to the walker (to walk several branches simulataneously).
Duplicate pushed commits will be ignored; at least one commit must have been pushed as a starting point before the walk can begin.
walker.push("92b22bbcb37caf4f6f53d30292169e84f5e4283b")
127 128 129 130 131 132 133 |
# File 'ext/rugged/rugged_revwalk.c', line 127
static VALUE rb_git_walker_push(VALUE self, VALUE rb_commit)
{
git_revwalk *walk;
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
push_commit(walk, rb_commit, 0);
return Qnil;
}
|
#push_range(range) ⇒ Object
135 136 137 138 139 140 141 |
# File 'ext/rugged/rugged_revwalk.c', line 135
static VALUE rb_git_walker_push_range(VALUE self, VALUE range)
{
git_revwalk *walk;
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
rugged_exception_check(git_revwalk_push_range(walk, StringValueCStr(range)));
return Qnil;
}
|
#reset ⇒ nil
Remove all pushed and hidden commits and reset the walker
back into a blank state.
222 223 224 225 226 227 228 |
# File 'ext/rugged/rugged_revwalk.c', line 222
static VALUE rb_git_walker_reset(VALUE self)
{
git_revwalk *walk;
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
git_revwalk_reset(walk);
return Qnil;
}
|
#simplify_first_parent ⇒ nil
Simplify the walk to the first parent of each commit.
180 181 182 183 184 185 186 |
# File 'ext/rugged/rugged_revwalk.c', line 180
static VALUE rb_git_walker_simplify_first_parent(VALUE self)
{
git_revwalk *walk;
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
git_revwalk_simplify_first_parent(walk);
return Qnil;
}
|
#sorting(sort_mode) ⇒ nil
Change the sorting mode for the revision walk.
This will cause walker to be reset.
166 167 168 169 170 171 172 |
# File 'ext/rugged/rugged_revwalk.c', line 166
static VALUE rb_git_walker_sorting(VALUE self, VALUE ruby_sort_mode)
{
git_revwalk *walk;
TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
git_revwalk_sorting(walk, FIX2INT(ruby_sort_mode));
return Qnil;
}
|
#each {|commit| ... } ⇒ Object #each ⇒ Enumerator
Perform the walk through the repository, yielding each
one of the commits found as a Rugged::Commit instance
to block.
If no block is given, an Enumerator 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
...
456 457 458 459 |
# File 'ext/rugged/rugged_revwalk.c', line 456
static VALUE rb_git_walker_each(int argc, VALUE *argv, VALUE self)
{
return rb_git_walk_with_opts(argc, argv, self, 0);
}
|