Skip to content

Commit bcee6fd

Browse files
author
Linus Torvalds
committed
Make 'fsck' able to take an arbitrary number of parents on the
command line. "arbitrary" is a bit wrong, since it is limited by the argument size limit (128kB or so), but let's see if anybody ever cares. Arguably you should prune your tree before you have a few thousand dangling heads in your archive. We can fix it by passing in a file listing if we ever care.
1 parent 2845dbe commit bcee6fd

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

fsck-cache.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define REACHABLE 0x40000
2020

2121
static int show_unreachable = 0;
22-
static int head_supplied = 0;
2322
static unsigned char head_sha1[20];
2423

2524
struct parent {
@@ -122,9 +121,6 @@ static void check_connectivity(void)
122121
{
123122
int i;
124123

125-
if (head_supplied)
126-
mark_reachable(lookup_rev(head_sha1));
127-
128124
/* Look up all the requirements, warn about missing objects.. */
129125
for (i = 0; i < nr_revs; i++) {
130126
struct revision *rev = revs[i];
@@ -282,29 +278,38 @@ static int fsck_dir(int i, char *path)
282278

283279
int main(int argc, char **argv)
284280
{
285-
int i;
281+
int i, heads;
286282
char *sha1_dir;
287283

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;
288292
for (i = 1; i < argc; i++) {
289293
if (!strcmp(argv[i], "--unreachable")) {
290294
show_unreachable = 1;
291295
continue;
292296
}
293297
if (!get_sha1_hex(argv[i], head_sha1)) {
294-
head_supplied = 1;
298+
mark_reachable(lookup_rev(head_sha1));
299+
heads++;
295300
continue;
296301
}
297-
usage("fsck-cache [[--unreachable] <head-sha1>]");
302+
error("fsck-cache [[--unreachable] <head-sha1>*]");
298303
}
299-
if (show_unreachable && !head_supplied)
300-
usage("unable to do reachability checks without a head");
301304

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");
307311
}
312+
308313
check_connectivity();
309314
return 0;
310315
}

0 commit comments

Comments
 (0)