7 * These three functions should build up a graph in memory about
8 * what objects we've referenced, and found, and types..
10 * Right now we don't do that kind of reachability checking. Yet.
12 static void fsck_tree(void *data, unsigned long size)
16 static void fsck_commit(void *data, unsigned long size)
20 static int mark_sha1_seen(unsigned char *sha1, char *tag)
25 static int fsck_entry(unsigned char *sha1, char *tag, void *data, unsigned long size)
27 if (!strcmp(tag, "blob"))
28 /* Nothing to check */;
29 else if (!strcmp(tag, "tree"))
30 fsck_tree(data, size);
31 else if (!strcmp(tag, "commit"))
32 fsck_commit(data, size);
35 return mark_sha1_seen(sha1, tag);
38 static int fsck_name(char *hex)
40 unsigned char sha1[20];
41 if (!get_sha1_hex(hex, sha1)) {
42 unsigned long mapsize;
43 void *map = map_sha1_file(sha1, &mapsize);
48 if (!check_sha1_signature(sha1, map, mapsize))
49 buffer = unpack_sha1_file(map, mapsize, type, &size);
51 if (buffer && !fsck_entry(sha1, type, buffer, size))
58 static int fsck_dir(int i, char *path)
60 DIR *dir = opendir(path);
64 fprintf(stderr, "missing sha1 directory '%s'", path);
68 while ((de = readdir(dir)) != NULL) {
70 int len = strlen(de->d_name);
74 if (de->d_name[1] != '.')
77 if (de->d_name[0] != '.')
81 sprintf(name, "%02x", i);
82 memcpy(name+2, de->d_name, len+1);
86 fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
92 int main(int argc, char **argv)
99 sha1_dir = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;
100 for (i = 0; i < 256; i++) {
101 static char dir[4096];
102 sprintf(dir, "%s/%02x", sha1_dir, i);