Skip to content

Commit 1c92d0e

Browse files
committed
Move diff_index_to_workdir do it's own method
This lets us pull the "other" nil check up in to Ruby
1 parent 1d487e8 commit 1c92d0e

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

ext/rugged/rugged_index.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,6 @@ static VALUE rb_git_index_diff(VALUE self, VALUE rb_other, VALUE rb_options)
806806
owner = rugged_owner(self);
807807
Data_Get_Struct(owner, git_repository, repo);
808808

809-
if (NIL_P(rb_other)) {
810-
error = git_diff_index_to_workdir(&diff, repo, index, &opts);
811-
} else {
812809
// Need to flip the reverse option, so that the index is by default
813810
// the "old file" side of the diff.
814811
opts.flags ^= GIT_DIFF_REVERSE;
@@ -829,7 +826,29 @@ static VALUE rb_git_index_diff(VALUE self, VALUE rb_other, VALUE rb_options)
829826
xfree(opts.pathspec.strings);
830827
rb_raise(rb_eTypeError, "A Rugged::Commit or Rugged::Tree instance is required");
831828
}
832-
}
829+
830+
xfree(opts.pathspec.strings);
831+
rugged_exception_check(error);
832+
833+
return rugged_diff_new(rb_cRuggedDiff, owner, diff);
834+
}
835+
836+
static VALUE rb_git_diff_index_to_workdir(VALUE self, VALUE rb_options)
837+
{
838+
git_index *index;
839+
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
840+
git_repository *repo;
841+
git_diff *diff = NULL;
842+
VALUE owner;
843+
int error;
844+
845+
rugged_parse_diff_options(&opts, rb_options);
846+
847+
Data_Get_Struct(self, git_index, index);
848+
owner = rugged_owner(self);
849+
Data_Get_Struct(owner, git_repository, repo);
850+
851+
error = git_diff_index_to_workdir(&diff, repo, index, &opts);
833852

834853
xfree(opts.pathspec.strings);
835854
rugged_exception_check(error);
@@ -1224,6 +1243,7 @@ void Init_rugged_index(void)
12241243
rb_define_method(rb_cRuggedIndex, "[]", rb_git_index_get, -1);
12251244
rb_define_method(rb_cRuggedIndex, "each", rb_git_index_each, 0);
12261245
rb_define_private_method(rb_cRuggedIndex, "_diff", rb_git_index_diff, 2);
1246+
rb_define_private_method(rb_cRuggedIndex, "diff_index_to_workdir", rb_git_diff_index_to_workdir, 1);
12271247

12281248
rb_define_method(rb_cRuggedIndex, "conflicts?", rb_git_index_conflicts_p, 0);
12291249
rb_define_method(rb_cRuggedIndex, "conflicts", rb_git_index_conflicts, 0);

lib/rugged/index.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class Index
55
def diff(*args)
66
options = args.pop if args.last.is_a?(Hash)
77
other = args.shift
8-
_diff other, options
8+
if other.nil?
9+
diff_index_to_workdir options
10+
else
11+
_diff other, options
12+
end
913
end
1014

1115
def to_s

0 commit comments

Comments
 (0)