Skip to content

Commit 3b069b1

Browse files
committed
diff-index.c: unify handling of command line paths
Regardless of where in the directory hierarchy you are, "-" on the command line means the standard input. The old code knew too much about how the low level machinery uses paths to read from the working tree and did not bother to have the same check for "-" when the command is run from the top-level. Unify the codepaths for subdirectory case and toplevel case into one and make it clearer. Signed-off-by: Junio C Hamano <[email protected]>
1 parent c20f592 commit 3b069b1

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

diff-no-index.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void diff_no_index(struct rev_info *revs,
170170
int argc, const char **argv,
171171
int nongit, const char *prefix)
172172
{
173-
int i;
173+
int i, prefixlen;
174174
int no_index = 0;
175175
unsigned options = 0;
176176
const char *paths[2];
@@ -230,23 +230,18 @@ void diff_no_index(struct rev_info *revs,
230230
if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))
231231
setup_pager();
232232

233-
if (prefix) {
234-
int len = strlen(prefix);
235-
236-
for (i = 0; i < 2; i++) {
237-
const char *p = argv[argc - 2 + i];
233+
prefixlen = prefix ? strlen(prefix) : 0;
234+
for (i = 0; i < 2; i++) {
235+
const char *p = argv[argc - 2 + i];
236+
if (!strcmp(p, "-"))
238237
/*
239-
* stdin should be spelled as '-'; if you have
240-
* path that is '-', spell it as ./-.
238+
* stdin should be spelled as "-"; if you have
239+
* path that is "-", spell it as "./-".
241240
*/
242-
p = (strcmp(p, "-")
243-
? xstrdup(prefix_filename(prefix, len, p))
244-
: p);
245-
paths[i] = p;
246-
}
247-
} else {
248-
for (i = 0; i < 2; i++)
249-
paths[i] = argv[argc - 2 + i];
241+
p = p;
242+
else if (prefixlen)
243+
p = xstrdup(prefix_filename(prefix, prefixlen, p));
244+
paths[i] = p;
250245
}
251246
revs->diffopt.skip_stat_unmatch = 1;
252247
if (!revs->diffopt.output_format)

0 commit comments

Comments
 (0)