Merge branch 'jk/fsck-exit-code-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:42 +0000 (11:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:42 +0000 (11:38 -0700)
"git fsck" failed to report that it found corrupt objects via its
exit status in some cases.

* jk/fsck-exit-code-fix:
fsck: return non-zero status on missing ref tips
fsck: exit with non-zero status upon error from fsck_obj()

1  2 
builtin/fsck.c
diff --combined builtin/fsck.c
index d42a27da89d8d5693c6335cf4e2123d41c030580,ca3018c6c5b65c1cfd644d0557a39b6cb2a73759..0928a98a71ca2b764d4fbb59976f1c4bdc421dde
@@@ -144,7 -144,7 +144,7 @@@ static int traverse_reachable(void
        unsigned int nr = 0;
        int result = 0;
        if (show_progress)
 -              progress = start_progress_delay("Checking connectivity", 0, 0, 2);
 +              progress = start_progress_delay(_("Checking connectivity"), 0, 0, 2);
        while (pending.nr) {
                struct object_array_entry *entry;
                struct object *obj;
@@@ -310,7 -310,8 +310,7 @@@ static int fsck_obj(struct object *obj
        if (obj->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *) obj;
  
 -              free(commit->buffer);
 -              commit->buffer = NULL;
 +              free_commit_buffer(commit);
  
                if (!commit->parents && show_root)
                        printf("root %s\n", sha1_to_hex(commit->object.sha1));
@@@ -388,7 -389,8 +388,8 @@@ static void fsck_sha1_list(void
                unsigned char *sha1 = entry->sha1;
  
                sha1_list.entry[i] = NULL;
-               fsck_sha1(sha1);
+               if (fsck_sha1(sha1))
+                       errors_found |= ERROR_OBJECT;
                free(entry);
        }
        sha1_list.nr = 0;
@@@ -481,6 -483,11 +482,6 @@@ static int fsck_handle_reflog(const cha
        return 0;
  }
  
 -static int is_branch(const char *refname)
 -{
 -      return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
 -}
 -
  static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
  {
        struct object *obj;
        obj = parse_object(sha1);
        if (!obj) {
                error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
+               errors_found |= ERROR_REACHABLE;
                /* We'll continue with the rest despite the error.. */
                return 0;
        }
@@@ -504,7 -512,7 +506,7 @@@ static void get_default_heads(void
  {
        if (head_points_at && !is_null_sha1(head_sha1))
                fsck_handle_ref("HEAD", head_sha1, 0, NULL);
-       for_each_ref(fsck_handle_ref, NULL);
+       for_each_rawref(fsck_handle_ref, NULL);
        if (include_reflogs)
                for_each_reflog(fsck_handle_reflog, NULL);
  
@@@ -535,7 -543,7 +537,7 @@@ static void fsck_object_dir(const char 
                fprintf(stderr, "Checking object directory\n");
  
        if (show_progress)
 -              progress = start_progress("Checking object directories", 256);
 +              progress = start_progress(_("Checking object directories"), 256);
        for (i = 0; i < 256; i++) {
                static char dir[4096];
                sprintf(dir, "%s/%02x", path, i);
@@@ -624,7 -632,7 +626,7 @@@ int cmd_fsck(int argc, const char **arg
        struct alternate_object_database *alt;
  
        errors_found = 0;
 -      read_replace_refs = 0;
 +      check_replace_refs = 0;
  
        argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
  
                                total += p->num_objects;
                        }
  
 -                      progress = start_progress("Checking objects", total);
 +                      progress = start_progress(_("Checking objects"), total);
                }
                for (p = packed_git; p; p = p->next) {
                        /* verify gives error messages itself */