|
19 | 19 | #define REACHABLE 0x40000
|
20 | 20 |
|
21 | 21 | static int show_unreachable = 0;
|
22 |
| -static int head_supplied = 0; |
23 | 22 | static unsigned char head_sha1[20];
|
24 | 23 |
|
25 | 24 | struct parent {
|
@@ -122,9 +121,6 @@ static void check_connectivity(void)
|
122 | 121 | {
|
123 | 122 | int i;
|
124 | 123 |
|
125 |
| - if (head_supplied) |
126 |
| - mark_reachable(lookup_rev(head_sha1)); |
127 |
| - |
128 | 124 | /* Look up all the requirements, warn about missing objects.. */
|
129 | 125 | for (i = 0; i < nr_revs; i++) {
|
130 | 126 | struct revision *rev = revs[i];
|
@@ -282,29 +278,38 @@ static int fsck_dir(int i, char *path)
|
282 | 278 |
|
283 | 279 | int main(int argc, char **argv)
|
284 | 280 | {
|
285 |
| - int i; |
| 281 | + int i, heads; |
286 | 282 | char *sha1_dir;
|
287 | 283 |
|
| 284 | + sha1_dir = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT; |
| 285 | + for (i = 0; i < 256; i++) { |
| 286 | + static char dir[4096]; |
| 287 | + sprintf(dir, "%s/%02x", sha1_dir, i); |
| 288 | + fsck_dir(i, dir); |
| 289 | + } |
| 290 | + |
| 291 | + heads = 0; |
288 | 292 | for (i = 1; i < argc; i++) {
|
289 | 293 | if (!strcmp(argv[i], "--unreachable")) {
|
290 | 294 | show_unreachable = 1;
|
291 | 295 | continue;
|
292 | 296 | }
|
293 | 297 | if (!get_sha1_hex(argv[i], head_sha1)) {
|
294 |
| - head_supplied = 1; |
| 298 | + mark_reachable(lookup_rev(head_sha1)); |
| 299 | + heads++; |
295 | 300 | continue;
|
296 | 301 | }
|
297 |
| - usage("fsck-cache [[--unreachable] <head-sha1>]"); |
| 302 | + error("fsck-cache [[--unreachable] <head-sha1>*]"); |
298 | 303 | }
|
299 |
| - if (show_unreachable && !head_supplied) |
300 |
| - usage("unable to do reachability checks without a head"); |
301 | 304 |
|
302 |
| - sha1_dir = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT; |
303 |
| - for (i = 0; i < 256; i++) { |
304 |
| - static char dir[4096]; |
305 |
| - sprintf(dir, "%s/%02x", sha1_dir, i); |
306 |
| - fsck_dir(i, dir); |
| 305 | + if (!heads) { |
| 306 | + if (show_unreachable) { |
| 307 | + fprintf(stderr, "unable to do reachability without a head\n"); |
| 308 | + show_unreachable = 0; |
| 309 | + } |
| 310 | + fprintf(stderr, "expect dangling commits - potential heads - due to lack of head information\n"); |
307 | 311 | }
|
| 312 | + |
308 | 313 | check_connectivity();
|
309 | 314 | return 0;
|
310 | 315 | }
|
0 commit comments