Skip to content

Commit 19bf6c9

Browse files
mhaggergitster
authored andcommitted
fsck: report errors if reflog entries point at invalid objects
Previously, if a reflog entry's old or new SHA-1 was not resolvable to an object, that SHA-1 was silently ignored. Instead, report such cases as errors. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d66ae59 commit 19bf6c9

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

builtin/fsck.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static void fsck_dir(int i, char *path)
451451

452452
static int default_refs;
453453

454-
static void fsck_handle_reflog_sha1(unsigned char *sha1)
454+
static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
455455
{
456456
struct object *obj;
457457

@@ -460,6 +460,9 @@ static void fsck_handle_reflog_sha1(unsigned char *sha1)
460460
if (obj) {
461461
obj->used = 1;
462462
mark_object_reachable(obj);
463+
} else {
464+
error("%s: invalid reflog entry %s", refname, sha1_to_hex(sha1));
465+
errors_found |= ERROR_REACHABLE;
463466
}
464467
}
465468
}
@@ -468,18 +471,20 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
468471
const char *email, unsigned long timestamp, int tz,
469472
const char *message, void *cb_data)
470473
{
474+
const char *refname = cb_data;
475+
471476
if (verbose)
472477
fprintf(stderr, "Checking reflog %s->%s\n",
473478
sha1_to_hex(osha1), sha1_to_hex(nsha1));
474479

475-
fsck_handle_reflog_sha1(osha1);
476-
fsck_handle_reflog_sha1(nsha1);
480+
fsck_handle_reflog_sha1(refname, osha1);
481+
fsck_handle_reflog_sha1(refname, nsha1);
477482
return 0;
478483
}
479484

480485
static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)
481486
{
482-
for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
487+
for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname);
483488
return 0;
484489
}
485490

0 commit comments

Comments
 (0)