Skip to content

Commit 12e5bdd

Browse files
committed
Merge branch 'jk/diff-no-index-initialize'
"git diff --no-index" may still want to access Git goodies like --ext-diff and --textconv, but so far these have been ignored, which has been corrected. * jk/diff-no-index-initialize: diff: reuse diff setup for --no-index case
2 parents 68731c7 + 287ab28 commit 12e5bdd

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

builtin/diff.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,21 +338,23 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
338338
"--no-index" : "[--no-index]");
339339

340340
}
341-
if (no_index)
342-
/* If this is a no-index diff, just run it and exit there. */
343-
diff_no_index(the_repository, &rev, argc, argv);
344-
345-
/* Otherwise, we are doing the usual "git" diff */
346-
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
347341

348-
/* Scale to real terminal size and respect statGraphWidth config */
342+
/* Set up defaults that will apply to both no-index and regular diffs. */
349343
rev.diffopt.stat_width = -1;
350344
rev.diffopt.stat_graph_width = -1;
351-
352-
/* Default to let external and textconv be used */
353345
rev.diffopt.flags.allow_external = 1;
354346
rev.diffopt.flags.allow_textconv = 1;
355347

348+
/* If this is a no-index diff, just run it and exit there. */
349+
if (no_index)
350+
diff_no_index(&rev, argc, argv);
351+
352+
/*
353+
* Otherwise, we are doing the usual "git" diff; set up any
354+
* further defaults that apply to regular diffs.
355+
*/
356+
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
357+
356358
/*
357359
* Default to intent-to-add entries invisible in the
358360
* index. This makes them show up as new files in diff-files

diff-no-index.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,14 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
233233
}
234234
}
235235

236-
void diff_no_index(struct repository *r,
237-
struct rev_info *revs,
236+
void diff_no_index(struct rev_info *revs,
238237
int argc, const char **argv)
239238
{
240239
int i;
241240
const char *paths[2];
242241
struct strbuf replacement = STRBUF_INIT;
243242
const char *prefix = revs->prefix;
244243

245-
/*
246-
* FIXME: --no-index should not look at index and we should be
247-
* able to pass NULL repo. Maybe later.
248-
*/
249-
repo_diff_setup(r, &revs->diffopt);
250244
for (i = 1; i < argc - 2; ) {
251245
int j;
252246
if (!strcmp(argv[i], "--no-index"))

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
438438

439439
int diff_result_code(struct diff_options *, int);
440440

441-
void diff_no_index(struct repository *, struct rev_info *, int, const char **);
441+
void diff_no_index(struct rev_info *, int, const char **);
442442

443443
int index_differs_from(struct repository *r, const char *def,
444444
const struct diff_flags *flags,

t/t4053-diff-no-index.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,12 @@ test_expect_success 'diff --no-index from repo subdir with absolute paths' '
137137
test_cmp expect actual
138138
'
139139

140+
test_expect_success 'diff --no-index allows external diff' '
141+
test_expect_code 1 \
142+
env GIT_EXTERNAL_DIFF="echo external ;:" \
143+
git diff --no-index non/git/a non/git/b >actual &&
144+
echo external >expect &&
145+
test_cmp expect actual
146+
'
147+
140148
test_done

0 commit comments

Comments
 (0)