Skip to content

Commit 0eee042

Browse files
committed
rebase: update to libgit2 with a single in-memory index
This lets us make the index one with the usual lifetime, attached to a larger object.
1 parent f01fd3f commit 0eee042

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

ext/rugged/rugged_rebase.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ static VALUE rb_git_rebase_new(int argc, VALUE* argv, VALUE klass)
156156
* The id of the commit being cherry-picked. Exists for all but
157157
* +:exec+ operations.
158158
*
159-
* :index ::
160-
* If the rebase is +:inmemory+ this is in the resulting merge
161-
* index. It can be used to resolve merge conflicts during the
162-
* rebase.
163-
*
164159
* :exec ::
165160
* If the operatin is +:exec+ this is what the user asked to be
166161
* executed.
@@ -190,19 +185,36 @@ static VALUE rb_git_rebase_next(VALUE self)
190185
rb_hash_aset(hash, CSTR2SYM("id"), val);
191186
}
192187

193-
if (operation->index) {
194-
val = Data_Wrap_Struct(rb_cRuggedIndex, NULL, NULL, operation->index);
195-
rugged_set_owner(val, self);
196-
rb_hash_aset(hash, CSTR2SYM("index"), val);
197-
}
198-
199188
if (operation->exec) {
200189
val = rb_str_new_utf8(operation->exec);
201190
rb_hash_aset(hash, CSTR2SYM("exec"), val);
202191
}
203192

204193
return hash;
205194
}
195+
/*
196+
* call-seq:
197+
* Rebase.inmemory_index -> Index
198+
*
199+
* Gets the index produced by the last operation, which is the result
200+
* of +next+ and which will be committed by the next invocation of
201+
* +commit+. This is useful for resolving conflicts in an in-memory
202+
* rebase before committing them.
203+
*
204+
* This is only applicable for in-memory rebases; for rebases within
205+
* a working directory, the changes were applied to the repository's
206+
* index.
207+
*/
208+
static VALUE rb_git_rebase_inmemory_index(VALUE self)
209+
{
210+
git_rebase *rebase;
211+
git_index *index;
212+
213+
Data_Get_Struct(self, git_rebase, rebase);
214+
rugged_exception_check(git_rebase_inmemory_index(&index, rebase));
215+
216+
return rugged_index_new(rb_cRuggedIndex, self, index);
217+
}
206218

207219
/*
208220
* call-seq:
@@ -328,6 +340,7 @@ void Init_rugged_rebase(void)
328340

329341
rb_define_singleton_method(rb_cRuggedRebase, "new", rb_git_rebase_new, -1);
330342
rb_define_method(rb_cRuggedRebase, "next", rb_git_rebase_next, 0);
343+
rb_define_method(rb_cRuggedRebase, "inmemory_index", rb_git_rebase_inmemory_index, 0);
331344
rb_define_method(rb_cRuggedRebase, "commit", rb_git_rebase_commit, -1);
332345
rb_define_method(rb_cRuggedRebase, "abort", rb_git_rebase_abort, 0);
333346
rb_define_method(rb_cRuggedRebase, "finish", rb_git_rebase_finish, 1);

test/rebase_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_inmemory_resolve_conflicts
5050
rebase = Rugged::Rebase.new(@repo, "refs/heads/asparagus", "refs/heads/master", inmemory: true)
5151

5252
op = rebase.next()
53-
idx = op[:index]
53+
idx = rebase.inmemory_index
5454

5555
assert idx
5656
assert_equal :pick, op[:type]

0 commit comments

Comments
 (0)