summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-06-24 12:21:48 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-06-24 12:21:48 -0700
commit8f61ccf15d7699bf8ce13d08337573a5baecfe47 (patch)
treec2d7bf9af5487e432b9ddc2c963e60f56b752e71 /builtin
parentMerge branch 'js/sleep-without-select' (diff)
parentfsck: report errors if reflog entries point at invalid objects (diff)
downloadtgif-8f61ccf15d7699bf8ce13d08337573a5baecfe47.tar.xz
Merge branch 'mh/fsck-reflog-entries'
"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
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fsck.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 4e8e2ee5b7..2679793049 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -451,35 +451,41 @@ static void fsck_dir(int i, char *path)
static int default_refs;
+static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
+{
+ struct object *obj;
+
+ if (!is_null_sha1(sha1)) {
+ obj = lookup_object(sha1);
+ if (obj) {
+ obj->used = 1;
+ mark_object_reachable(obj);
+ } else {
+ error("%s: invalid reflog entry %s", refname, sha1_to_hex(sha1));
+ errors_found |= ERROR_REACHABLE;
+ }
+ }
+}
+
static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data)
{
- struct object *obj;
+ const char *refname = cb_data;
if (verbose)
fprintf(stderr, "Checking reflog %s->%s\n",
sha1_to_hex(osha1), sha1_to_hex(nsha1));
- if (!is_null_sha1(osha1)) {
- obj = lookup_object(osha1);
- if (obj) {
- obj->used = 1;
- mark_object_reachable(obj);
- }
- }
- obj = lookup_object(nsha1);
- if (obj) {
- obj->used = 1;
- mark_object_reachable(obj);
- }
+ fsck_handle_reflog_sha1(refname, osha1);
+ fsck_handle_reflog_sha1(refname, nsha1);
return 0;
}
static int fsck_handle_reflog(const char *logname, const struct object_id *oid,
int flag, void *cb_data)
{
- for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
+ for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname);
return 0;
}