Merge branch 'pm/log-exit-code'
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Aug 2008 06:42:29 +0000 (23:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Aug 2008 06:42:29 +0000 (23:42 -0700)
* pm/log-exit-code:
Teach git log --exit-code to return an appropriate exit code
Teach git log --check to return an appropriate exit code

1  2 
builtin-log.c
diff --combined builtin-log.c
index 911fd659906ebe87bf0adcd17519dd97777fb948,3a7957483031758af5c05afc55a499e617557f1c..9204ffd7607dd6b72a2ef45e7b18921e822070af
@@@ -217,6 -217,11 +217,11 @@@ static int cmd_log_walk(struct rev_inf
        if (rev->early_output)
                finish_early_output(rev);
  
+       /*
+        * For --check and --exit-code, the exit code is based on CHECK_FAILED
+        * and HAS_CHANGES being accumulated in rev->diffopt, so be careful to
+        * retain that state information if replacing rev->diffopt in this loop
+        */
        while ((commit = get_revision(rev)) != NULL) {
                log_tree_commit(rev, commit);
                if (!rev->reflog_info) {
                free_commit_list(commit->parents);
                commit->parents = NULL;
        }
-       return 0;
+       if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
+           DIFF_OPT_TST(&rev->diffopt, CHECK_FAILED)) {
+               return 02;
+       }
+       return diff_result_code(&rev->diffopt, 0);
  }
  
  static int git_log_config(const char *var, const char *value, void *cb)
@@@ -461,7 -470,7 +470,7 @@@ static int extra_cc_alloc
  static void add_header(const char *value)
  {
        int len = strlen(value);
 -      while (value[len - 1] == '\n')
 +      while (len && value[len - 1] == '\n')
                len--;
        if (!strncasecmp(value, "to: ", 4)) {
                ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);