Skip to content

Commit 69c07df

Browse files
committed
move Rugged::Commit handling to Ruby
1 parent 7571340 commit 69c07df

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

ext/rugged/rugged_tree.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,18 +489,7 @@ static VALUE rb_git_tree_diff_(VALUE self, VALUE rb_repo, VALUE rb_self, VALUE r
489489
Data_Get_Struct(rb_self, git_tree, tree);
490490
}
491491

492-
if (rb_obj_is_kind_of(rb_other, rb_cRuggedCommit)) {
493-
git_tree *other_tree;
494-
git_commit *commit;
495-
496-
Data_Get_Struct(rb_other, git_commit, commit);
497-
error = git_commit_tree(&other_tree, commit);
498-
499-
if (!error) {
500-
error = git_diff_tree_to_tree(&diff, repo, tree, other_tree, &opts);
501-
git_tree_free(other_tree);
502-
}
503-
} else if (rb_obj_is_kind_of(rb_other, rb_cRuggedTree)) {
492+
if (rb_obj_is_kind_of(rb_other, rb_cRuggedTree)) {
504493
git_tree *other_tree;
505494

506495
Data_Get_Struct(rb_other, git_tree, other_tree);
@@ -520,8 +509,9 @@ static VALUE rb_git_tree_diff_(VALUE self, VALUE rb_repo, VALUE rb_self, VALUE r
520509
return rugged_diff_new(rb_cRuggedDiff, rb_repo, diff);
521510
}
522511

523-
static VALUE rb_git_diff_tree_to_tree(VALUE self, VALUE rb_repo, VALUE rb_tree, VALUE rb_options) {
512+
static VALUE rb_git_diff_tree_to_tree(VALUE self, VALUE rb_repo, VALUE rb_tree, VALUE rb_other_tree, VALUE rb_options) {
524513
git_tree *tree = NULL;
514+
git_tree *other_tree = NULL;
525515
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
526516
git_repository *repo = NULL;
527517
git_diff *diff = NULL;
@@ -530,9 +520,12 @@ static VALUE rb_git_diff_tree_to_tree(VALUE self, VALUE rb_repo, VALUE rb_tree,
530520
Data_Get_Struct(rb_repo, git_repository, repo);
531521
Data_Get_Struct(rb_tree, git_tree, tree);
532522

523+
if(RTEST(rb_other_tree))
524+
Data_Get_Struct(rb_other_tree, git_tree, other_tree);
525+
533526
rugged_parse_diff_options(&opts, rb_options);
534527

535-
error = git_diff_tree_to_tree(&diff, repo, tree, NULL, &opts);
528+
error = git_diff_tree_to_tree(&diff, repo, tree, other_tree, &opts);
536529

537530
xfree(opts.pathspec.strings);
538531
rugged_exception_check(error);
@@ -1039,7 +1032,7 @@ void Init_rugged_tree(void)
10391032
rb_define_singleton_method(rb_cRuggedTree, "empty", rb_git_tree_empty, 1);
10401033

10411034
rb_define_private_method(rb_singleton_class(rb_cRuggedTree), "_diff", rb_git_tree_diff_, 4);
1042-
rb_define_private_method(rb_singleton_class(rb_cRuggedTree), "diff_tree_to_tree", rb_git_diff_tree_to_tree, 3);
1035+
rb_define_private_method(rb_singleton_class(rb_cRuggedTree), "diff_tree_to_tree", rb_git_diff_tree_to_tree, 4);
10431036

10441037
rb_cRuggedTreeBuilder = rb_define_class_under(rb_cRuggedTree, "Builder", rb_cObject);
10451038
rb_define_singleton_method(rb_cRuggedTreeBuilder, "new", rb_git_treebuilder_new, -1);

lib/rugged/tree.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ def self.diff(repo, _self, other = nil, options = {})
99
if _self.nil?
1010
raise TypeError, "Need 'old' or 'new' for diffing"
1111
else
12-
diff_tree_to_tree repo, _self, options
12+
diff_tree_to_tree repo, _self, nil, options
1313
end
1414
else
1515
if other.is_a?(::String)
1616
other = Rugged::Object.rev_parse repo, other
1717
end
1818

19-
_diff(repo, _self, other, options)
19+
case other
20+
when Rugged::Commit
21+
diff_tree_to_tree repo, _self, other.tree, options
22+
else
23+
_diff(repo, _self, other, options)
24+
end
2025
end
2126
end
2227

0 commit comments

Comments
 (0)