Class: Rugged::Walker

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rugged/walker.rb,
ext/rugged/rugged_revwalk.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(repository) ⇒ Object

Create a new Walker instance able to walk commits found in repository, which is a Rugged::Repository instance.


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/rugged/rugged_revwalk.c', line 49

static VALUE rb_git_walker_new(VALUE klass, VALUE rb_repo)
{
	git_repository *repo;
	git_revwalk *walk;
	int error;

	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_revwalk_new(&walk, repo);
	rugged_exception_check(error);

	return rugged_walker_new(klass, rb_repo, walk);;
}

Instance Method Details

#each {|commit| ... } ⇒ Object #eachIterator

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 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
...

Overloads:

  • #each {|commit| ... } ⇒ Object

    Yields:

    • (commit)

156
157
158
159
# File 'ext/rugged/rugged_revwalk.c', line 156

static VALUE rb_git_walker_each(int argc, VALUE *argv, VALUE self)
{
	return rb_git_walker_each_with_opts(argc, argv, self, 0);
}

#each_oid {|commit| ... } ⇒ Object #each_oidIterator

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 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_oid| puts commit_oid }

generates:

92b22bbcb37caf4f6f53d30292169e84f5e4283b
6b750d5800439b502de669465b385e5f469c78b6
ef9207141549f4ffcd3c4597e270d32e10d0a6bc
cb75e05f0f8ac3407fb3bd0ebd5ff07573b16c9f
...

Overloads:

  • #each_oid {|commit| ... } ⇒ Object

    Yields:

    • (commit)

186
187
188
189
# File 'ext/rugged/rugged_revwalk.c', line 186

static VALUE rb_git_walker_each_oid(int argc, VALUE *argv, VALUE self)
{
	return rb_git_walker_each_with_opts(argc, argv, self, 1);
}

#hide(commit) ⇒ nil

Hide the given commit (and all its parents) from the output in the revision walk.


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'ext/rugged/rugged_revwalk.c', line 233

static VALUE rb_git_walker_hide(VALUE self, VALUE rb_commit)
{
	git_revwalk *walk;
	git_commit *commit;
	int error;

	Data_Get_Struct(self, git_revwalk, walk);

	commit = (git_commit *)rugged_object_get(
		git_revwalk_repository(walk), rb_commit, GIT_OBJ_COMMIT);

	error = git_revwalk_hide(walk, git_object_id((git_object *)commit));

	git_commit_free(commit);
	rugged_exception_check(error);

	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")

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'ext/rugged/rugged_revwalk.c', line 207

static VALUE rb_git_walker_push(VALUE self, VALUE rb_commit)
{
	git_revwalk *walk;
	git_commit *commit;
	int error;

	Data_Get_Struct(self, git_revwalk, walk);

	commit = (git_commit *)rugged_object_get(
		git_revwalk_repository(walk), rb_commit, GIT_OBJ_COMMIT);

	error = git_revwalk_push(walk, git_object_id((git_object *)commit));

	git_commit_free(commit);
	rugged_exception_check(error);

	return Qnil;
}

#resetnil

Remove all pushed and hidden commits and reset the walker back into a blank state.


289
290
291
292
293
294
295
# File 'ext/rugged/rugged_revwalk.c', line 289

static VALUE rb_git_walker_reset(VALUE self)
{
	git_revwalk *walk;
	Data_Get_Struct(self, git_revwalk, walk);
	git_revwalk_reset(walk);
	return Qnil;
}

#simplify_first_parentnil

Simplify the walk to the first parent of each commit.


274
275
276
277
278
279
280
# File 'ext/rugged/rugged_revwalk.c', line 274

static VALUE rb_git_walker_simplify_first_parent(VALUE self)
{
	git_revwalk *walk;
	Data_Get_Struct(self, git_revwalk, 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.


260
261
262
263
264
265
266
# File 'ext/rugged/rugged_revwalk.c', line 260

static VALUE rb_git_walker_sorting(VALUE self, VALUE ruby_sort_mode)
{
	git_revwalk *walk;
	Data_Get_Struct(self, git_revwalk, walk);
	git_revwalk_sorting(walk, FIX2INT(ruby_sort_mode));
	return Qnil;
}

#each {|commit| ... } ⇒ Object #eachIterator

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 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
...

Overloads:

  • #each {|commit| ... } ⇒ Object

    Yields:

    • (commit)

156
157
158
159
# File 'ext/rugged/rugged_revwalk.c', line 156

static VALUE rb_git_walker_each(int argc, VALUE *argv, VALUE self)
{
	return rb_git_walker_each_with_opts(argc, argv, self, 0);
}