Skip to content

Commit 16a7fcf

Browse files
dschogitster
authored andcommitted
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>
1 parent c4640fe commit 16a7fcf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Documentation/git-fsck.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ index file and all SHA1 references in .git/refs/* as heads.
6565
Be chatty.
6666

6767
--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.
7072

7173
It tests SHA1 and general object sanity, and it does full tracking of
7274
the resulting reachability and everything else. It prints out any

builtin-fsck.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ static void check_unreachable_object(struct object *obj)
152152
}
153153
if (!(f = fopen(filename, "w")))
154154
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));
156166
fclose(f);
157167
}
158168
return;

0 commit comments

Comments
 (0)