Skip to content

Commit 4a07e38

Browse files
committed
inverse options for Rugged::Patch#bytesize to match that of lines
1 parent 2c80cbc commit 4a07e38

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

ext/rugged/rugged_patch.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,16 @@ static VALUE rb_git_diff_patch_lines(int argc, VALUE *argv, VALUE self)
233233
*
234234
* The following options can be passed in the +options+ Hash:
235235
*
236-
* :include_context ::
237-
* Boolean value specifying that context lines should be included when
236+
* :exclude_context ::
237+
* Boolean value specifying that context lines should be excluded when
238238
* counting the number of bytes in the patch.
239239
*
240-
* :include_hunk_headers ::
241-
* Boolean value specifying that hunk headers should be included when
240+
* :exclude_hunk_headers ::
241+
* Boolean value specifying that hunk headers should be excluded when
242242
* counting the number of bytes in the patch.
243243
*
244-
* :include_file_headers ::
245-
* Boolean value specifying that file headers should be included when
244+
* :exclude_file_headers ::
245+
* Boolean value specifying that file headers should be excluded when
246246
* counting the number of bytes in the patch.
247247
*
248248
* Returns the number of bytes in the patch, depending on which options are
@@ -253,27 +253,29 @@ static VALUE rb_git_diff_patch_bytesize(int argc, VALUE *argv, VALUE self)
253253
git_patch *patch;
254254
size_t bytesize;
255255
VALUE rb_options;
256-
int options[3];
256+
int include_context, include_hunk_headers, include_file_headers;
257257
Data_Get_Struct(self, git_patch, patch);
258258

259-
memset(options, 0, sizeof(options));
259+
include_context = 1;
260+
include_hunk_headers = 1;
261+
include_file_headers = 1;
260262

261263
rb_scan_args(argc, argv, "0:", &rb_options);
262264
if (!NIL_P(rb_options)) {
263-
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("include_context")))) {
264-
options[0] = 1;
265+
if (rb_hash_aref(rb_options, CSTR2SYM("include_context")) == Qfalse) {
266+
include_context = 0;
265267
}
266268

267-
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("include_hunk_headers")))) {
268-
options[1] = 1;
269+
if (rb_hash_aref(rb_options, CSTR2SYM("include_hunk_headers")) == Qfalse) {
270+
include_hunk_headers = 0;
269271
}
270272

271-
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("include_file_headers")))) {
272-
options[2] = 1;
273+
if (rb_hash_aref(rb_options, CSTR2SYM("include_file_headers")) == Qfalse) {
274+
include_file_headers = 0;
273275
}
274276
}
275277

276-
bytesize = git_patch_size(patch, options[0], options[1], options[2]);
278+
bytesize = git_patch_size(patch, include_context, include_hunk_headers, include_file_headers);
277279

278280
return INT2FIX(bytesize);
279281
}

test/diff_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ 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: true)}
76+
bytesize = patches.inject(0) {|n, p| n += p.bytesize(include_context: false)}
7777

7878
assert_equal 5, diff.size
7979
assert_equal 5, deltas.size
8080
assert_equal 5, patches.size
81-
assert_equal 975, bytesize
81+
assert_equal 1589, bytesize
8282

8383
assert_equal 2, deltas.select(&:added?).size
8484
assert_equal 1, deltas.select(&:deleted?).size

0 commit comments

Comments
 (0)