Skip to content

Commit 5bed5e0

Browse files
Fix Rugged::Patch#bytesize to actually support the documented options.
1 parent 3282d79 commit 5bed5e0

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

ext/rugged/rugged_patch.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,19 @@ static VALUE rb_git_diff_patch_bytesize(int argc, VALUE *argv, VALUE self)
304304
int include_context, include_hunk_headers, include_file_headers;
305305
Data_Get_Struct(self, git_patch, patch);
306306

307-
include_context = 1;
308-
include_hunk_headers = 1;
309-
include_file_headers = 1;
307+
include_context = include_hunk_headers = include_file_headers = 1;
310308

311309
rb_scan_args(argc, argv, "0:", &rb_options);
312310
if (!NIL_P(rb_options)) {
313-
if (rb_hash_aref(rb_options, CSTR2SYM("include_context")) == Qfalse) {
311+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_context")))) {
314312
include_context = 0;
315313
}
316314

317-
if (rb_hash_aref(rb_options, CSTR2SYM("include_hunk_headers")) == Qfalse) {
315+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_hunk_headers")))) {
318316
include_hunk_headers = 0;
319317
}
320318

321-
if (rb_hash_aref(rb_options, CSTR2SYM("include_file_headers")) == Qfalse) {
319+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_file_headers")))) {
322320
include_file_headers = 0;
323321
}
324322
}

test/diff_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_with_oid_string
7373
patches = diff.patches
7474
hunks = patches.map(&:hunks).flatten
7575
lines = hunks.map(&:lines).flatten
76-
bytesize = patches.inject(0) {|n, p| n += p.bytesize(include_context: false)}
76+
bytesize = patches.inject(0) {|n, p| n += p.bytesize(exclude_context: true)}
7777

7878
assert_equal 5, diff.size
7979
assert_equal 5, deltas.size

0 commit comments

Comments
 (0)