summaryrefslogtreecommitdiff
path: root/diff-no-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-06-27 19:05:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-06-28 23:09:40 (GMT)
commit3b069b1beba6d851401032260a8030448637ece5 (patch)
tree86ac99cf74a29adf277db833ebec1a9c13028ab2 /diff-no-index.c
parentc20f592611c2760a14d37fa1780afd2093159aeb (diff)
downloadgit-3b069b1beba6d851401032260a8030448637ece5.zip
git-3b069b1beba6d851401032260a8030448637ece5.tar.gz
git-3b069b1beba6d851401032260a8030448637ece5.tar.bz2
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>
Diffstat (limited to 'diff-no-index.c')
-rw-r--r--diff-no-index.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/diff-no-index.c b/diff-no-index.c
index 31cc5b1..ac41b68 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -170,7 +170,7 @@ void diff_no_index(struct rev_info *revs,
int argc, const char **argv,
int nongit, const char *prefix)
{
- int i;
+ int i, prefixlen;
int no_index = 0;
unsigned options = 0;
const char *paths[2];
@@ -230,23 +230,18 @@ void diff_no_index(struct rev_info *revs,
if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))
setup_pager();
- if (prefix) {
- int len = strlen(prefix);
-
- for (i = 0; i < 2; i++) {
- const char *p = argv[argc - 2 + i];
+ prefixlen = prefix ? strlen(prefix) : 0;
+ for (i = 0; i < 2; i++) {
+ const char *p = argv[argc - 2 + i];
+ if (!strcmp(p, "-"))
/*
- * stdin should be spelled as '-'; if you have
- * path that is '-', spell it as ./-.
+ * stdin should be spelled as "-"; if you have
+ * path that is "-", spell it as "./-".
*/
- p = (strcmp(p, "-")
- ? xstrdup(prefix_filename(prefix, len, p))
- : p);
- paths[i] = p;
- }
- } else {
- for (i = 0; i < 2; i++)
- paths[i] = argv[argc - 2 + i];
+ p = p;
+ else if (prefixlen)
+ p = xstrdup(prefix_filename(prefix, prefixlen, p));
+ paths[i] = p;
}
revs->diffopt.skip_stat_unmatch = 1;
if (!revs->diffopt.output_format)