Skip to content

Commit 1d487e8

Browse files
committed
Start moving diff implementation to Ruby
Move C implementation to a private method, move scan args to Ruby
1 parent 98cd180 commit 1d487e8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

ext/rugged/rugged_index.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,16 +791,15 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
791791
* marked with a single entry in the diff. If this flag is set to true,
792792
* all files under ignored directories will be included in the diff, too.
793793
*/
794-
static VALUE rb_git_index_diff(int argc, VALUE *argv, VALUE self)
794+
static VALUE rb_git_index_diff(VALUE self, VALUE rb_other, VALUE rb_options)
795795
{
796796
git_index *index;
797797
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
798798
git_repository *repo;
799799
git_diff *diff = NULL;
800-
VALUE owner, rb_other, rb_options;
800+
VALUE owner;
801801
int error;
802802

803-
rb_scan_args(argc, argv, "01:", &rb_other, &rb_options);
804803
rugged_parse_diff_options(&opts, rb_options);
805804

806805
Data_Get_Struct(self, git_index, index);
@@ -1224,7 +1223,7 @@ void Init_rugged_index(void)
12241223
rb_define_method(rb_cRuggedIndex, "get", rb_git_index_get, -1);
12251224
rb_define_method(rb_cRuggedIndex, "[]", rb_git_index_get, -1);
12261225
rb_define_method(rb_cRuggedIndex, "each", rb_git_index_each, 0);
1227-
rb_define_method(rb_cRuggedIndex, "diff", rb_git_index_diff, -1);
1226+
rb_define_private_method(rb_cRuggedIndex, "_diff", rb_git_index_diff, 2);
12281227

12291228
rb_define_method(rb_cRuggedIndex, "conflicts?", rb_git_index_conflicts_p, 0);
12301229
rb_define_method(rb_cRuggedIndex, "conflicts", rb_git_index_conflicts, 0);

lib/rugged/index.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ module Rugged
22
class Index
33
include Enumerable
44

5+
def diff(*args)
6+
options = args.pop if args.last.is_a?(Hash)
7+
other = args.shift
8+
_diff other, options
9+
end
10+
511
def to_s
612
s = "#<Rugged::Index\n"
713
self.each do |entry|

0 commit comments

Comments
 (0)