Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 1 | #include <sys/types.h> |
| 2 | #include <dirent.h> |
| 3 | |
Linus Torvalds | 4b18242 | 2005-04-30 09:59:31 -0700 | [diff] [blame] | 4 | #include "cache.h" |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 5 | #include "commit.h" |
| 6 | #include "tree.h" |
| 7 | #include "blob.h" |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 8 | #include "tag.h" |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 9 | |
| 10 | #define REACHABLE 0x0001 |
Linus Torvalds | d9839e0 | 2005-04-13 09:57:30 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | ab7df18 | 2005-04-25 16:34:13 -0700 | [diff] [blame] | 12 | static int show_root = 0; |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 13 | static int show_tags = 0; |
Linus Torvalds | d9839e0 | 2005-04-13 09:57:30 -0700 | [diff] [blame] | 14 | static int show_unreachable = 0; |
Junio C Hamano | ae7c0c9 | 2005-05-04 01:33:33 -0700 | [diff] [blame] | 15 | static int keep_cache_objects = 0; |
Linus Torvalds | d9839e0 | 2005-04-13 09:57:30 -0700 | [diff] [blame] | 16 | static unsigned char head_sha1[20]; |
| 17 | |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 18 | static void check_connectivity(void) |
| 19 | { |
| 20 | int i; |
| 21 | |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 22 | /* Look up all the requirements, warn about missing objects.. */ |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 23 | for (i = 0; i < nr_objs; i++) { |
| 24 | struct object *obj = objs[i]; |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 25 | struct object_list *refs; |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 3a6a23e | 2005-04-30 11:22:26 -0700 | [diff] [blame] | 27 | if (!obj->parsed) { |
| 28 | printf("missing %s %s\n", obj->type, sha1_to_hex(obj->sha1)); |
| 29 | continue; |
| 30 | } |
| 31 | |
| 32 | for (refs = obj->refs; refs; refs = refs->next) { |
| 33 | if (refs->item->parsed) |
| 34 | continue; |
| 35 | printf("broken link from %7s %s\n", |
| 36 | obj->type, sha1_to_hex(obj->sha1)); |
| 37 | printf(" to %7s %s\n", |
Linus Torvalds | aa03413 | 2005-05-02 21:10:54 -0700 | [diff] [blame] | 38 | refs->item->type, sha1_to_hex(refs->item->sha1)); |
Linus Torvalds | 3a6a23e | 2005-04-30 11:22:26 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* Don't bother with tag reachability. */ |
| 42 | if (obj->type == tag_type) |
| 43 | continue; |
| 44 | |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 45 | if (show_unreachable && !(obj->flags & REACHABLE)) { |
Linus Torvalds | f43b8ab | 2005-04-18 17:35:31 -0700 | [diff] [blame] | 46 | printf("unreachable %s %s\n", obj->type, sha1_to_hex(obj->sha1)); |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 47 | continue; |
Linus Torvalds | d9839e0 | 2005-04-13 09:57:30 -0700 | [diff] [blame] | 48 | } |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 49 | |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 50 | if (!obj->used) { |
| 51 | printf("dangling %s %s\n", obj->type, |
| 52 | sha1_to_hex(obj->sha1)); |
Linus Torvalds | d9839e0 | 2005-04-13 09:57:30 -0700 | [diff] [blame] | 53 | } |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 57 | /* |
| 58 | * The entries in a tree are ordered in the _path_ order, |
| 59 | * which means that a directory entry is ordered by adding |
| 60 | * a slash to the end of it. |
| 61 | * |
| 62 | * So a directory called "a" is ordered _after_ a file |
| 63 | * called "a.c", because "a/" sorts after "a.c". |
| 64 | */ |
Junio C Hamano | a4f35a2 | 2005-05-07 14:43:32 -0700 | [diff] [blame^] | 65 | #define TREE_UNORDERED (-1) |
| 66 | #define TREE_HAS_DUPS (-2) |
| 67 | |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 68 | static int verify_ordered(struct tree_entry_list *a, struct tree_entry_list *b) |
| 69 | { |
| 70 | int len1 = strlen(a->name); |
| 71 | int len2 = strlen(b->name); |
| 72 | int len = len1 < len2 ? len1 : len2; |
| 73 | unsigned char c1, c2; |
| 74 | int cmp; |
| 75 | |
| 76 | cmp = memcmp(a->name, b->name, len); |
| 77 | if (cmp < 0) |
| 78 | return 0; |
| 79 | if (cmp > 0) |
Junio C Hamano | a4f35a2 | 2005-05-07 14:43:32 -0700 | [diff] [blame^] | 80 | return TREE_UNORDERED; |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Ok, the first <len> characters are the same. |
| 84 | * Now we need to order the next one, but turn |
| 85 | * a '\0' into a '/' for a directory entry. |
| 86 | */ |
| 87 | c1 = a->name[len]; |
| 88 | c2 = b->name[len]; |
Junio C Hamano | a4f35a2 | 2005-05-07 14:43:32 -0700 | [diff] [blame^] | 89 | if (!c1 && !c2) |
| 90 | /* |
| 91 | * git-write-tree used to write out a nonsense tree that has |
| 92 | * entries with the same name, one blob and one tree. Make |
| 93 | * sure we do not have duplicate entries. |
| 94 | */ |
| 95 | return TREE_HAS_DUPS; |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 96 | if (!c1 && a->directory) |
| 97 | c1 = '/'; |
| 98 | if (!c2 && b->directory) |
| 99 | c2 = '/'; |
Junio C Hamano | a4f35a2 | 2005-05-07 14:43:32 -0700 | [diff] [blame^] | 100 | return c1 < c2 ? 0 : TREE_UNORDERED; |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 103 | static int fsck_tree(struct tree *item) |
Linus Torvalds | 1ea34e3 | 2005-04-08 17:11:14 -0700 | [diff] [blame] | 104 | { |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 105 | int has_full_path = 0; |
| 106 | struct tree_entry_list *entry, *last; |
| 107 | |
| 108 | last = NULL; |
| 109 | for (entry = item->entries; entry; entry = entry->next) { |
| 110 | if (strchr(entry->name, '/')) |
| 111 | has_full_path = 1; |
| 112 | |
Linus Torvalds | 42ea9cb | 2005-05-05 16:18:48 -0700 | [diff] [blame] | 113 | switch (entry->mode) { |
| 114 | /* |
| 115 | * Standard modes.. |
| 116 | */ |
| 117 | case S_IFREG | 0755: |
| 118 | case S_IFREG | 0644: |
| 119 | case S_IFLNK: |
| 120 | case S_IFDIR: |
| 121 | break; |
| 122 | /* |
| 123 | * This is nonstandard, but we had a few of these |
| 124 | * early on when we honored the full set of mode |
| 125 | * bits.. |
| 126 | */ |
| 127 | case S_IFREG | 0664: |
| 128 | break; |
| 129 | default: |
| 130 | printf("tree %s has entry %o %s\n", |
| 131 | sha1_to_hex(item->object.sha1), |
| 132 | entry->mode, entry->name); |
| 133 | } |
| 134 | |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 135 | if (last) { |
Junio C Hamano | a4f35a2 | 2005-05-07 14:43:32 -0700 | [diff] [blame^] | 136 | switch (verify_ordered(last, entry)) { |
| 137 | case TREE_UNORDERED: |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 138 | fprintf(stderr, "tree %s not ordered\n", |
| 139 | sha1_to_hex(item->object.sha1)); |
| 140 | return -1; |
Junio C Hamano | a4f35a2 | 2005-05-07 14:43:32 -0700 | [diff] [blame^] | 141 | case TREE_HAS_DUPS: |
| 142 | fprintf(stderr, "tree %s has duplicate entries for '%s'\n", |
| 143 | sha1_to_hex(item->object.sha1), |
| 144 | entry->name); |
| 145 | return -1; |
| 146 | default: |
| 147 | break; |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| 151 | last = entry; |
| 152 | } |
| 153 | |
| 154 | if (has_full_path) { |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 155 | fprintf(stderr, "warning: fsck-cache: tree %s " |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 156 | "has full pathnames in it\n", |
| 157 | sha1_to_hex(item->object.sha1)); |
Linus Torvalds | 1ea34e3 | 2005-04-08 17:11:14 -0700 | [diff] [blame] | 158 | } |
Linus Torvalds | 8500349 | 2005-05-02 16:13:18 -0700 | [diff] [blame] | 159 | |
Linus Torvalds | 59c1e24 | 2005-04-09 00:25:22 -0700 | [diff] [blame] | 160 | return 0; |
Linus Torvalds | 1ea34e3 | 2005-04-08 17:11:14 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 163 | static int fsck_commit(struct commit *commit) |
Linus Torvalds | 1ea34e3 | 2005-04-08 17:11:14 -0700 | [diff] [blame] | 164 | { |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 165 | if (!commit->tree) |
Linus Torvalds | 1ea34e3 | 2005-04-08 17:11:14 -0700 | [diff] [blame] | 166 | return -1; |
Linus Torvalds | ab7df18 | 2005-04-25 16:34:13 -0700 | [diff] [blame] | 167 | if (!commit->parents && show_root) |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 168 | printf("root %s\n", sha1_to_hex(commit->object.sha1)); |
Linus Torvalds | e6948b6 | 2005-04-24 16:20:53 -0700 | [diff] [blame] | 169 | if (!commit->date) |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 170 | printf("bad commit date in %s\n", |
| 171 | sha1_to_hex(commit->object.sha1)); |
Linus Torvalds | 59c1e24 | 2005-04-09 00:25:22 -0700 | [diff] [blame] | 172 | return 0; |
Linus Torvalds | 1ea34e3 | 2005-04-08 17:11:14 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Daniel Barkalow | c418eda | 2005-04-28 07:46:33 -0700 | [diff] [blame] | 175 | static int fsck_tag(struct tag *tag) |
Linus Torvalds | 4728b86 | 2005-04-24 14:10:55 -0700 | [diff] [blame] | 176 | { |
Linus Torvalds | 92d4c85 | 2005-05-03 07:57:56 -0700 | [diff] [blame] | 177 | struct object *tagged = tag->tagged; |
| 178 | |
| 179 | if (!tagged) { |
| 180 | printf("bad object in tag %s\n", sha1_to_hex(tag->object.sha1)); |
| 181 | return -1; |
| 182 | } |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 183 | if (!show_tags) |
| 184 | return 0; |
| 185 | |
Linus Torvalds | 92d4c85 | 2005-05-03 07:57:56 -0700 | [diff] [blame] | 186 | printf("tagged %s %s", tagged->type, sha1_to_hex(tagged->sha1)); |
| 187 | printf(" (%s) in %s\n", tag->tag, sha1_to_hex(tag->object.sha1)); |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 188 | return 0; |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Linus Torvalds | 7e8c174 | 2005-05-02 09:06:33 -0700 | [diff] [blame] | 191 | static int fsck_sha1(unsigned char *sha1) |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 192 | { |
Linus Torvalds | 7e8c174 | 2005-05-02 09:06:33 -0700 | [diff] [blame] | 193 | struct object *obj = parse_object(sha1); |
| 194 | if (!obj) |
| 195 | return -1; |
| 196 | if (obj->type == blob_type) |
| 197 | return 0; |
| 198 | if (obj->type == tree_type) |
| 199 | return fsck_tree((struct tree *) obj); |
| 200 | if (obj->type == commit_type) |
| 201 | return fsck_commit((struct commit *) obj); |
| 202 | if (obj->type == tag_type) |
| 203 | return fsck_tag((struct tag *) obj); |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 204 | return -1; |
| 205 | } |
| 206 | |
Linus Torvalds | 7e8c174 | 2005-05-02 09:06:33 -0700 | [diff] [blame] | 207 | /* |
| 208 | * This is the sorting chunk size: make it reasonably |
| 209 | * big so that we can sort well.. |
| 210 | */ |
| 211 | #define MAX_SHA1_ENTRIES (1024) |
| 212 | |
| 213 | struct sha1_entry { |
| 214 | unsigned long ino; |
| 215 | unsigned char sha1[20]; |
| 216 | }; |
| 217 | |
| 218 | static struct { |
| 219 | unsigned long nr; |
| 220 | struct sha1_entry *entry[MAX_SHA1_ENTRIES]; |
| 221 | } sha1_list; |
| 222 | |
| 223 | static int ino_compare(const void *_a, const void *_b) |
| 224 | { |
| 225 | const struct sha1_entry *a = _a, *b = _b; |
| 226 | unsigned long ino1 = a->ino, ino2 = b->ino; |
| 227 | return ino1 < ino2 ? -1 : ino1 > ino2 ? 1 : 0; |
| 228 | } |
| 229 | |
| 230 | static void fsck_sha1_list(void) |
| 231 | { |
| 232 | int i, nr = sha1_list.nr; |
| 233 | |
| 234 | qsort(sha1_list.entry, nr, sizeof(struct sha1_entry *), ino_compare); |
| 235 | for (i = 0; i < nr; i++) { |
| 236 | struct sha1_entry *entry = sha1_list.entry[i]; |
| 237 | unsigned char *sha1 = entry->sha1; |
| 238 | |
| 239 | sha1_list.entry[i] = NULL; |
| 240 | if (fsck_sha1(sha1) < 0) |
| 241 | fprintf(stderr, "bad sha1 entry '%s'\n", sha1_to_hex(sha1)); |
| 242 | free(entry); |
| 243 | } |
| 244 | sha1_list.nr = 0; |
| 245 | } |
| 246 | |
| 247 | static void add_sha1_list(unsigned char *sha1, unsigned long ino) |
| 248 | { |
| 249 | struct sha1_entry *entry = xmalloc(sizeof(*entry)); |
| 250 | int nr; |
| 251 | |
| 252 | entry->ino = ino; |
| 253 | memcpy(entry->sha1, sha1, 20); |
| 254 | nr = sha1_list.nr; |
| 255 | if (nr == MAX_SHA1_ENTRIES) { |
| 256 | fsck_sha1_list(); |
| 257 | nr = 0; |
| 258 | } |
| 259 | sha1_list.entry[nr] = entry; |
| 260 | sha1_list.nr = ++nr; |
| 261 | } |
| 262 | |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 263 | static int fsck_dir(int i, char *path) |
| 264 | { |
| 265 | DIR *dir = opendir(path); |
| 266 | struct dirent *de; |
| 267 | |
| 268 | if (!dir) { |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 269 | return error("missing sha1 directory '%s'", path); |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | while ((de = readdir(dir)) != NULL) { |
| 273 | char name[100]; |
Linus Torvalds | 7e8c174 | 2005-05-02 09:06:33 -0700 | [diff] [blame] | 274 | unsigned char sha1[20]; |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 275 | int len = strlen(de->d_name); |
| 276 | |
| 277 | switch (len) { |
| 278 | case 2: |
| 279 | if (de->d_name[1] != '.') |
| 280 | break; |
| 281 | case 1: |
| 282 | if (de->d_name[0] != '.') |
| 283 | break; |
| 284 | continue; |
| 285 | case 38: |
| 286 | sprintf(name, "%02x", i); |
| 287 | memcpy(name+2, de->d_name, len+1); |
Linus Torvalds | 7e8c174 | 2005-05-02 09:06:33 -0700 | [diff] [blame] | 288 | if (get_sha1_hex(name, sha1) < 0) |
| 289 | break; |
| 290 | add_sha1_list(sha1, de->d_ino); |
| 291 | continue; |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 292 | } |
| 293 | fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name); |
| 294 | } |
| 295 | closedir(dir); |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | int main(int argc, char **argv) |
| 300 | { |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 301 | int i, heads; |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 302 | char *sha1_dir; |
| 303 | |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 304 | for (i = 1; i < argc; i++) { |
| 305 | const char *arg = argv[i]; |
| 306 | |
| 307 | if (!strcmp(arg, "--unreachable")) { |
| 308 | show_unreachable = 1; |
| 309 | continue; |
| 310 | } |
| 311 | if (!strcmp(arg, "--tags")) { |
| 312 | show_tags = 1; |
| 313 | continue; |
| 314 | } |
Linus Torvalds | ab7df18 | 2005-04-25 16:34:13 -0700 | [diff] [blame] | 315 | if (!strcmp(arg, "--root")) { |
| 316 | show_root = 1; |
| 317 | continue; |
| 318 | } |
Junio C Hamano | ae7c0c9 | 2005-05-04 01:33:33 -0700 | [diff] [blame] | 319 | if (!strcmp(arg, "--cache")) { |
| 320 | keep_cache_objects = 1; |
| 321 | continue; |
| 322 | } |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 323 | if (*arg == '-') |
Junio C Hamano | ae7c0c9 | 2005-05-04 01:33:33 -0700 | [diff] [blame] | 324 | usage("fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]"); |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Junio C Hamano | ace1534 | 2005-05-07 00:38:04 -0700 | [diff] [blame] | 327 | sha1_dir = get_object_directory(); |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 328 | for (i = 0; i < 256; i++) { |
| 329 | static char dir[4096]; |
| 330 | sprintf(dir, "%s/%02x", sha1_dir, i); |
| 331 | fsck_dir(i, dir); |
| 332 | } |
Linus Torvalds | 7e8c174 | 2005-05-02 09:06:33 -0700 | [diff] [blame] | 333 | fsck_sha1_list(); |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 334 | |
| 335 | heads = 0; |
| 336 | for (i = 1; i < argc; i++) { |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 337 | const char *arg = argv[i]; |
| 338 | |
| 339 | if (*arg == '-') |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 340 | continue; |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 341 | |
Linus Torvalds | 3c249c9 | 2005-05-01 16:36:56 -0700 | [diff] [blame] | 342 | if (!get_sha1(arg, head_sha1)) { |
Linus Torvalds | 770896e | 2005-05-04 17:03:09 -0700 | [diff] [blame] | 343 | struct object *obj = lookup_object(head_sha1); |
Jonas Fonseca | e1a1388 | 2005-04-29 20:00:40 -0700 | [diff] [blame] | 344 | |
Linus Torvalds | 770896e | 2005-05-04 17:03:09 -0700 | [diff] [blame] | 345 | /* Error is printed by lookup_object(). */ |
| 346 | if (!obj) |
Jonas Fonseca | e1a1388 | 2005-04-29 20:00:40 -0700 | [diff] [blame] | 347 | continue; |
| 348 | |
Daniel Barkalow | ff5ebe3 | 2005-04-18 11:39:48 -0700 | [diff] [blame] | 349 | obj->used = 1; |
| 350 | mark_reachable(obj, REACHABLE); |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 351 | heads++; |
| 352 | continue; |
| 353 | } |
Linus Torvalds | 889262e | 2005-04-25 16:31:13 -0700 | [diff] [blame] | 354 | error("expected sha1, got %s", arg); |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Junio C Hamano | ae7c0c9 | 2005-05-04 01:33:33 -0700 | [diff] [blame] | 357 | if (keep_cache_objects) { |
| 358 | int i; |
| 359 | read_cache(); |
| 360 | for (i = 0; i < active_nr; i++) { |
| 361 | struct blob *blob = lookup_blob(active_cache[i]->sha1); |
| 362 | struct object *obj; |
| 363 | if (!blob) |
| 364 | continue; |
| 365 | obj = &blob->object; |
| 366 | obj->used = 1; |
| 367 | mark_reachable(obj, REACHABLE); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (!heads && !keep_cache_objects) { |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 372 | if (show_unreachable) { |
Junio C Hamano | ae7c0c9 | 2005-05-04 01:33:33 -0700 | [diff] [blame] | 373 | fprintf(stderr, "unable to do reachability without a head nor --cache\n"); |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 374 | show_unreachable = 0; |
| 375 | } |
Junio C Hamano | ae7c0c9 | 2005-05-04 01:33:33 -0700 | [diff] [blame] | 376 | if (!heads) |
| 377 | fprintf(stderr, "expect dangling commits - potential heads - due to lack of head information\n"); |
Linus Torvalds | bcee6fd | 2005-04-13 16:42:09 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Linus Torvalds | 8ba0bbb | 2005-04-10 23:13:09 -0700 | [diff] [blame] | 380 | check_connectivity(); |
Linus Torvalds | 2022211 | 2005-04-08 15:02:42 -0700 | [diff] [blame] | 381 | return 0; |
| 382 | } |