Skip to content

Commit 697f67a

Browse files
committed
Merge branch 'mh/fsck-reflog-entries' into maint
"git fsck" used to ignore missing or invalid objects recorded in reflog. * mh/fsck-reflog-entries: fsck: report errors if reflog entries point at invalid objects fsck_handle_reflog_sha1(): new function
2 parents ada9ecd + 19bf6c9 commit 697f67a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

builtin/fsck.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,34 +451,40 @@ static void fsck_dir(int i, char *path)
451451

452452
static int default_refs;
453453

454+
static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
455+
{
456+
struct object *obj;
457+
458+
if (!is_null_sha1(sha1)) {
459+
obj = lookup_object(sha1);
460+
if (obj) {
461+
obj->used = 1;
462+
mark_object_reachable(obj);
463+
} else {
464+
error("%s: invalid reflog entry %s", refname, sha1_to_hex(sha1));
465+
errors_found |= ERROR_REACHABLE;
466+
}
467+
}
468+
}
469+
454470
static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
455471
const char *email, unsigned long timestamp, int tz,
456472
const char *message, void *cb_data)
457473
{
458-
struct object *obj;
474+
const char *refname = cb_data;
459475

460476
if (verbose)
461477
fprintf(stderr, "Checking reflog %s->%s\n",
462478
sha1_to_hex(osha1), sha1_to_hex(nsha1));
463479

464-
if (!is_null_sha1(osha1)) {
465-
obj = lookup_object(osha1);
466-
if (obj) {
467-
obj->used = 1;
468-
mark_object_reachable(obj);
469-
}
470-
}
471-
obj = lookup_object(nsha1);
472-
if (obj) {
473-
obj->used = 1;
474-
mark_object_reachable(obj);
475-
}
480+
fsck_handle_reflog_sha1(refname, osha1);
481+
fsck_handle_reflog_sha1(refname, nsha1);
476482
return 0;
477483
}
478484

479485
static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)
480486
{
481-
for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
487+
for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname);
482488
return 0;
483489
}
484490

0 commit comments

Comments
 (0)