Code

Merge branch 'maint'
[git.git] / builtin-fsck.c
index 7c3b0a535f81a350d11df112a6a5b5a49b139afb..fcb8ed5af1bc50df19a2f533989aa9673ea166e8 100644 (file)
@@ -14,6 +14,7 @@
 static int show_root;
 static int show_tags;
 static int show_unreachable;
+static int include_reflogs = 1;
 static int check_full;
 static int check_strict;
 static int keep_cache_objects;
@@ -252,6 +253,7 @@ static int fsck_tree(struct tree *item)
                case S_IFREG | 0644:
                case S_IFLNK:
                case S_IFDIR:
+               case S_IFDIRLNK:
                        break;
                /*
                 * This is nonstandard, but we had a few of these
@@ -348,7 +350,7 @@ static int fsck_tag(struct tag *tag)
        return 0;
 }
 
-static int fsck_sha1(unsigned char *sha1)
+static int fsck_sha1(const unsigned char *sha1)
 {
        struct object *obj = parse_object(sha1);
        if (!obj) {
@@ -517,7 +519,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
 static void get_default_heads(void)
 {
        for_each_ref(fsck_handle_ref, NULL);
-       for_each_reflog(fsck_handle_reflog, NULL);
+       if (include_reflogs)
+               for_each_reflog(fsck_handle_reflog, NULL);
 
        /*
         * Not having any default heads isn't really fatal, but
@@ -624,6 +627,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
                        keep_cache_objects = 1;
                        continue;
                }
+               if (!strcmp(arg, "--no-reflogs")) {
+                       include_reflogs = 0;
+                       continue;
+               }
                if (!strcmp(arg, "--full")) {
                        check_full = 1;
                        continue;
@@ -655,12 +662,9 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
                        verify_pack(p, 0);
 
                for (p = packed_git; p; p = p->next) {
-                       uint32_t i, num = num_packed_objects(p);
-                       for (i = 0; i < num; i++) {
-                               unsigned char sha1[20];
-                               nth_packed_object_sha1(p, i, sha1);
-                               fsck_sha1(sha1);
-                       }
+                       uint32_t i, num = p->num_objects;
+                       for (i = 0; i < num; i++)
+                               fsck_sha1(nth_packed_object_sha1(p, i));
                }
        }
 
@@ -700,8 +704,14 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
                int i;
                read_cache();
                for (i = 0; i < active_nr; i++) {
-                       struct blob *blob = lookup_blob(active_cache[i]->sha1);
+                       unsigned int mode;
+                       struct blob *blob;
                        struct object *obj;
+
+                       mode = ntohl(active_cache[i]->ce_mode);
+                       if (S_ISDIRLNK(mode))
+                               continue;
+                       blob = lookup_blob(active_cache[i]->sha1);
                        if (!blob)
                                continue;
                        obj = &blob->object;