Skip to content

Commit 57e765b

Browse files
committed
Merge pull request nodegit#1175 from carlosmn/diff-0-ctx
Can't perform diff with no context lines
2 parents 0887b58 + 1aa5318 commit 57e765b

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

include/git2/diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ typedef struct {
289289
} git_diff_options;
290290

291291
#define GIT_DIFF_OPTIONS_VERSION 1
292-
#define GIT_DIFF_OPTIONS_INIT {GIT_DIFF_OPTIONS_VERSION}
292+
#define GIT_DIFF_OPTIONS_INIT {GIT_DIFF_OPTIONS_VERSION, GIT_DIFF_NORMAL, 3}
293293

294294
/**
295295
* When iterating over a diff, callback that will be made per file.

src/diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ static git_diff_list *git_diff_list_alloc(
291291
* - diff.noprefix
292292
*/
293293

294-
if (opts == NULL)
294+
if (opts == NULL) {
295+
/* Make sure we default to 3 lines */
296+
diff->opts.context_lines = 3;
295297
return diff;
298+
}
296299

297300
memcpy(&diff->opts, opts, sizeof(git_diff_options));
298301

src/diff_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static void setup_xdiff_options(
202202
memset(param, 0, sizeof(xpparam_t));
203203

204204
cfg->ctxlen =
205-
(!opts || !opts->context_lines) ? 3 : opts->context_lines;
205+
(!opts) ? 3 : opts->context_lines;
206206
cfg->interhunkctxlen =
207207
(!opts) ? 0 : opts->interhunk_lines;
208208

tests-clar/diff/tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ static diff_expects expect;
1010
void test_diff_tree__initialize(void)
1111
{
1212
GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION);
13+
/* The default context lines is set by _INIT which we can't use here */
14+
opts.context_lines = 3;
1315

1416
memset(&expect, 0, sizeof(expect));
1517

0 commit comments

Comments
 (0)