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>

Michael Haggerty committed Jun 8, 2015 at 15:40 UTC 19bf6c9b345d18150805bde328284692d9fb3a91
1 file changed +9 -4
builtin/fsck.c
+9 -4
@@ -451,7 +451,7 @@ static void fsck_dir(int i, char *path)
451
452 static int default_refs;
453
454 -static void fsck_handle_reflog_sha1(unsigned char *sha1)
454 +static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
455 {
456 struct object *obj;
457
@@ -460,6 +460,9 @@ static void fsck_handle_reflog_sha1(unsigned char *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 }
@@ -468,18 +471,20 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
471 const char *email, unsigned long timestamp, int tz,
472 const char *message, void *cb_data)
473 {
474 + const char *refname = cb_data;
475 +
476 if (verbose)
477 fprintf(stderr, "Checking reflog %s->%s\n",
478 sha1_to_hex(osha1), sha1_to_hex(nsha1));
479
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);
482 return 0;
483 }
484
485 static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)
486 {
482 - for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
487 + for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname);
488 return 0;
489 }
490