Skip to content

Commit 1d71200

Browse files
Stop iteration once we've generated the patch header.
1 parent 516da48 commit 1d71200

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ext/rugged/rugged_patch.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,10 @@ static int patch_print_header_cb(
357357

358358
if (line->origin == GIT_DIFF_LINE_FILE_HDR) {
359359
rb_ary_push(rb_buffer, rb_str_new(line->content, line->content_len));
360+
return GIT_OK;
361+
} else {
362+
return GIT_ITEROVER;
360363
}
361-
362-
return GIT_OK;
363364
}
364365

365366
/*
@@ -388,10 +389,13 @@ static VALUE rb_git_diff_patch_to_s(VALUE self)
388389
static VALUE rb_git_diff_patch_header(VALUE self)
389390
{
390391
git_patch *patch;
392+
int error = 0;
391393
VALUE rb_buffer = rb_ary_new();
392394
Data_Get_Struct(self, git_patch, patch);
393395

394-
rugged_exception_check(git_patch_print(patch, patch_print_header_cb, (void*)rb_buffer));
396+
error = git_patch_print(patch, patch_print_header_cb, (void*)rb_buffer);
397+
if (error && error != GIT_ITEROVER)
398+
rugged_exception_check(error);
395399

396400
return rb_ary_join(rb_buffer, Qnil);
397401
}

0 commit comments

Comments
 (0)