Skip to content
Browse files

add Rugged::Diff::Hunk#line_count

  • Loading branch information...
1 parent 45bfdb3 commit 335824af3c5244680cbb6ca5f61ef1bb70779185 @brianmario brianmario committed Sep 13, 2012
Showing with 22 additions and 0 deletions.
  1. +19 −0 ext/rugged/rugged_diff_hunk.c
  2. +3 −0 lib/rugged/diff/hunk.rb
View
19 ext/rugged/rugged_diff_hunk.c
@@ -76,9 +76,28 @@ static VALUE rb_git_diff_hunk_each_line(VALUE self)
return Qnil;
}
+static VALUE rb_git_diff_hunk_line_count(VALUE self)
+{
+ git_diff_delta *delta;
+ rugged_diff *diff;
+ int num_lines = 0;
+ VALUE rb_diff;
+ VALUE rb_hunk;
+
+ rb_hunk = rugged_owner(self);
+ rb_diff = rugged_owner(rb_hunk);
+ Data_Get_Struct(rb_diff, rugged_diff, diff);
+
+ num_lines = git_diff_iterator_num_lines_in_hunk(diff->iter);
+ rugged_exception_check(num_lines);
+
+ return INT2FIX(num_lines);
+}
+
void Init_rugged_diff_hunk()
{
rb_cRuggedDiffHunk = rb_define_class_under(rb_cRuggedDiff, "Hunk", rb_cObject);
rb_define_method(rb_cRuggedDiffHunk, "each_line", rb_git_diff_hunk_each_line, 0);
+ rb_define_method(rb_cRuggedDiffHunk, "line_count", rb_git_diff_hunk_line_count, 0);
}
View
3 lib/rugged/diff/hunk.rb
@@ -4,6 +4,9 @@ class Hunk
include Enumerable
alias each each_line
+ alias size line_count
+ alias count line_count
+
attr_accessor :header
attr_accessor :range

0 comments on commit 335824a

Please sign in to comment.
Something went wrong with that request. Please try again.