Merge branch 'ld/maint-diff-quiet-w'
authorJunio C Hamano <gitster@pobox.com>
Tue, 2 Mar 2010 20:44:10 +0000 (12:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Mar 2010 20:44:10 +0000 (12:44 -0800)
* ld/maint-diff-quiet-w:
git-diff: add a test for git diff --quiet -w
git diff --quiet -w: check and report the status

1  2 
diff.c
diff --combined diff.c
index ed3e7c5aaf9cdbc76aba0b357cb001e9aba55a9b,7216b1e8db75fb28916be85139b816e9c6be93f8..dfdfa1a813c345b7653b1743afa75ff15d8c379f
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -2826,15 -2826,6 +2826,15 @@@ int diff_opt_parse(struct diff_options 
                DIFF_OPT_SET(options, FOLLOW_RENAMES);
        else if (!strcmp(arg, "--color"))
                DIFF_OPT_SET(options, COLOR_DIFF);
 +      else if (!prefixcmp(arg, "--color=")) {
 +              int value = git_config_colorbool(NULL, arg+8, -1);
 +              if (value == 0)
 +                      DIFF_OPT_CLR(options, COLOR_DIFF);
 +              else if (value > 0)
 +                      DIFF_OPT_SET(options, COLOR_DIFF);
 +              else
 +                      return error("option `color' expects \"always\", \"auto\", or \"never\"");
 +      }
        else if (!strcmp(arg, "--no-color"))
                DIFF_OPT_CLR(options, COLOR_DIFF);
        else if (!strcmp(arg, "--color-words")) {
                ;
        else if (!prefixcmp(arg, "--output=")) {
                options->file = fopen(arg + strlen("--output="), "w");
 +              if (!options->file)
 +                      die_errno("Could not open '%s'", arg + strlen("--output="));
                options->close_file = 1;
        } else
                return 0;
@@@ -3531,6 -3520,29 +3531,29 @@@ void diff_flush(struct diff_options *op
                separator++;
        }
  
+       if (output_format & DIFF_FORMAT_NO_OUTPUT &&
+           DIFF_OPT_TST(options, EXIT_WITH_STATUS) &&
+           DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) {
+               /*
+                * run diff_flush_patch for the exit status. setting
+                * options->file to /dev/null should be safe, becaue we
+                * aren't supposed to produce any output anyway.
+                */
+               if (options->close_file)
+                       fclose(options->file);
+               options->file = fopen("/dev/null", "w");
+               if (!options->file)
+                       die_errno("Could not open /dev/null");
+               options->close_file = 1;
+               for (i = 0; i < q->nr; i++) {
+                       struct diff_filepair *p = q->queue[i];
+                       if (check_pair_status(p))
+                               diff_flush_patch(p, options);
+                       if (options->found_changes)
+                               break;
+               }
+       }
        if (output_format & DIFF_FORMAT_PATCH) {
                if (separator) {
                        putc(options->line_termination, options->file);
@@@ -3653,7 -3665,7 +3676,7 @@@ static void diffcore_skip_stat_unmatch(
                struct diff_filepair *p = q->queue[i];
  
                /*
 -               * 1. Entries that come from stat info dirtyness
 +               * 1. Entries that come from stat info dirtiness
                 *    always have both sides (iow, not create/delete),
                 *    one side of the object name is unknown, with
                 *    the same mode and size.  Keep the ones that