fsck --lost-found: write blob's contents, not their SHA-1
When looking for a lost blob, it is much nicer to be able to grep through .git/lost-found/other/* than to write an inefficient loop over the file names. So write the contents of the dangling blobs, not their object names. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 22, 2007 at 21:20 UTC
16a7fcfe5e568b50ddebe2369600e71da67d1405
2 files changed
+15
-3
Documentation/git-fsck.txt
+4
-2
@@ -65,8 +65,10 @@ index file and all SHA1 references in .git/refs/* as heads.
65
Be chatty.
66
67
--lost-found::
68
- Write dangling refs into .git/lost-found/commit/ or
69
- .git/lost-found/other/, depending on type.
68
+ Write dangling objects into .git/lost-found/commit/ or
69
+ .git/lost-found/other/, depending on type. If the object is
70
+ a blob, the contents are written into the file, rather than
71
+ its object name.
72
73
It tests SHA1 and general object sanity, and it does full tracking of
74
the resulting reachability and everything else. It prints out any
builtin-fsck.c
+11
-1
@@ -152,7 +152,17 @@ static void check_unreachable_object(struct object *obj)
152
}
153
if (!(f = fopen(filename, "w")))
154
die("Could not open %s", filename);
155
- fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
155
+ if (obj->type == OBJ_BLOB) {
156
+ enum object_type type;
157
+ unsigned long size;
158
+ char *buf = read_sha1_file(obj->sha1,
159
+ &type, &size);
160
+ if (buf) {
161
+ fwrite(buf, size, 1, f);
162
+ free(buf);
163
+ }
164
+ } else
165
+ fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
166
fclose(f);
167
}
168
return;