summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a1cdc25)
raw | patch | inline | side by side (parent: a1cdc25)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 26 Jan 2011 21:01:54 +0000 (13:01 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Jan 2011 20:58:15 +0000 (12:58 -0800) |
When there is a random garbage file whose name happens to be 38-byte
long in a .git/objects/??/ directory, the loop terminated prematurely
without marking all the other files that it hasn't checked in the
readdir() loop.
Treat such a file just like any other garbage file, and do not break out
of the readdir() loop.
While at it, replace repeated sprintf() calls to a single one outside the
loop.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
long in a .git/objects/??/ directory, the loop terminated prematurely
without marking all the other files that it hasn't checked in the
readdir() loop.
Treat such a file just like any other garbage file, and do not break out
of the readdir() loop.
While at it, replace repeated sprintf() calls to a single one outside the
loop.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsck.c | patch | blob | history |
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 91409a0069ece772070a9778190456a1c62a9d60..795aba087fe9c6ce0e644526d662a561b7f13f31 100644 (file)
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
sha1_list.nr = ++nr;
}
+static inline int is_loose_object_file(struct dirent *de,
+ char *name, unsigned char *sha1)
+{
+ if (strlen(de->d_name) != 38)
+ return 0;
+ memcpy(name + 2, de->d_name, 39);
+ return !get_sha1_hex(name, sha1);
+}
+
static void fsck_dir(int i, char *path)
{
DIR *dir = opendir(path);
struct dirent *de;
+ char name[100];
if (!dir)
return;
if (verbose)
fprintf(stderr, "Checking directory %s\n", path);
+ sprintf(name, "%02x", i);
while ((de = readdir(dir)) != NULL) {
- char name[100];
unsigned char sha1[20];
if (is_dot_or_dotdot(de->d_name))
continue;
- if (strlen(de->d_name) == 38) {
- sprintf(name, "%02x", i);
- memcpy(name+2, de->d_name, 39);
- if (get_sha1_hex(name, sha1) < 0)
- break;
+ if (is_loose_object_file(de, name, sha1)) {
add_sha1_list(sha1, DIRENT_SORT_HINT(de));
continue;
}