From e423ffd8a6f46a14ecbb637d909290bd3579cebd Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Tue, 6 Jan 2009 19:53:32 +0100 Subject: [PATCH 1/3] diff: accept -- when using --no-index Accept -- as an "end of options" marker even when using --no-index. Previously, the -- triggered a "normal" index/tree diff and subsequently failed because of the unrecognized (in that mode) --no-index. Note that the second loop can treat '--' as a normal option, because the preceding checks ensure it is the third-to-last argument. While at it, fix the parsing of "-q" option in --no-index mode as well. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- diff-no-index.c | 10 +++++++--- t/t4013-diff-various.sh | 1 + t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir diff --git a/diff-no-index.c b/diff-no-index.c index b60d3455da..39868e2a8f 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -173,8 +173,10 @@ void diff_no_index(struct rev_info *revs, /* Were we asked to do --no-index explicitly? */ for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "--")) - return; + if (!strcmp(argv[i], "--")) { + i++; + break; + } if (!strcmp(argv[i], "--no-index")) no_index = 1; if (argv[i][0] != '-') @@ -212,8 +214,10 @@ void diff_no_index(struct rev_info *revs, int j; if (!strcmp(argv[i], "--no-index")) i++; - else if (!strcmp(argv[1], "-q")) + else if (!strcmp(argv[i], "-q")) options |= DIFF_SILENT_ON_REMOVED; + else if (!strcmp(argv[i], "--")) + i++; else { j = diff_opt_parse(&revs->diffopt, argv + i, argc - i); if (!j) diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index aeb5405cfe..aba53202f8 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -261,6 +261,7 @@ diff --patch-with-stat -r initial..side diff --patch-with-raw -r initial..side diff --name-status dir2 dir diff --no-index --name-status dir2 dir +diff --no-index --name-status -- dir2 dir diff master master^ side EOF diff --git a/t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir b/t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir new file mode 100644 index 0000000000..6756f8de67 --- /dev/null +++ b/t/t4013/diff.diff_--no-index_--name-status_--_dir2_dir @@ -0,0 +1,3 @@ +$ git diff --no-index --name-status -- dir2 dir +A dir/sub +$ From c6dbca08ca39d9cd511a36cdd18847b8720f1653 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Wed, 7 Jan 2009 00:56:03 +0100 Subject: [PATCH 2/3] diff --no-index: test for pager after option parsing We need to parse options before we can see if --exit-code was provided. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- diff-no-index.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/diff-no-index.c b/diff-no-index.c index 39868e2a8f..12ff1f1eef 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -200,13 +200,6 @@ void diff_no_index(struct rev_info *revs, die("git diff %s takes two paths", no_index ? "--no-index" : "[--no-index]"); - /* - * If the user asked for our exit code then don't start a - * pager or we would end up reporting its exit code instead. - */ - if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS)) - setup_pager(); - diff_setup(&revs->diffopt); if (!revs->diffopt.output_format) revs->diffopt.output_format = DIFF_FORMAT_PATCH; @@ -226,6 +219,13 @@ void diff_no_index(struct rev_info *revs, } } + /* + * If the user asked for our exit code then don't start a + * pager or we would end up reporting its exit code instead. + */ + if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS)) + setup_pager(); + if (prefix) { int len = strlen(prefix); From a324fc45e4d04e3b879cd2d9a603d73ca696b775 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Wed, 7 Jan 2009 12:15:30 +0100 Subject: [PATCH 3/3] diff --no-index -q: fix endless loop We forgot to move to the next argument when parsing -q, getting stuck in an endless loop. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- diff-no-index.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diff-no-index.c b/diff-no-index.c index 12ff1f1eef..60ed17470a 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -207,8 +207,10 @@ void diff_no_index(struct rev_info *revs, int j; if (!strcmp(argv[i], "--no-index")) i++; - else if (!strcmp(argv[i], "-q")) + else if (!strcmp(argv[i], "-q")) { options |= DIFF_SILENT_ON_REMOVED; + i++; + } else if (!strcmp(argv[i], "--")) i++; else {