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 <gitster@pobox.com>
Junio C Hamano committed
Jun 27, 2012 at 12:05 UTC
3b069b1beba6d851401032260a8030448637ece5
1 file changed
+11
-16
diff-no-index.c
+11
-16
@@ -170,7 +170,7 @@ void diff_no_index(struct rev_info *revs,
170
int argc, const char **argv,
171
int nongit, const char *prefix)
172
{
173
- int i;
173
+ int i, prefixlen;
174
int no_index = 0;
175
unsigned options = 0;
176
const char *paths[2];
@@ -230,23 +230,18 @@ void diff_no_index(struct rev_info *revs,
230
if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))
231
setup_pager();
232
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, "-"))
237
/*
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 "./-".
240
*/
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;
245
}
246
revs->diffopt.skip_stat_unmatch = 1;
247
if (!revs->diffopt.output_format)