summaryrefslogtreecommitdiff
path: root/fsck.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-07-17 13:00:02 +0200
committerJunio C Hamano <gitster@pobox.com>2016-07-18 15:15:59 -0700
commit90cf590f53f2939a47ca7b397e270e8228699829 (patch)
tree54a32ad0aa0098c039f7a5a12ac9ca8e3a4febde /fsck.c
parent1cd772cc4124e43b14231dcaeae8a5dddf4ffdb9 (diff)
downloadgit-90cf590f53f2939a47ca7b397e270e8228699829.tar.gz
fsck: optionally show more helpful info for broken links
When reporting broken links between commits/trees/blobs, it would be quite helpful at times if the user would be told how the object is supposed to be reachable. With the new --name-objects option, git-fsck will try to do exactly that: name the objects in a way that shows how they are reachable. For example, when some reflog got corrupted and a blob is missing that should not be, the user might want to remove the corresponding reflog entry. This option helps them find that entry: `git fsck` will now report something like this: broken link from tree b5eb6ff... (refs/stash@{<date>}~37:) to blob ec5cf80... Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fsck.c')
-rw-r--r--fsck.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/fsck.c b/fsck.c
index 828c5c6484..c9cf3de8d3 100644
--- a/fsck.c
+++ b/fsck.c
@@ -323,6 +323,19 @@ static void put_object_name(struct fsck_options *options, struct object *obj,
va_end(ap);
}
+static const char *describe_object(struct fsck_options *o, struct object *obj)
+{
+ static struct strbuf buf = STRBUF_INIT;
+ char *name;
+
+ strbuf_reset(&buf);
+ strbuf_addstr(&buf, oid_to_hex(&obj->oid));
+ if (o->object_names && (name = lookup_decoration(o->object_names, obj)))
+ strbuf_addf(&buf, " (%s)", name);
+
+ return buf.buf;
+}
+
static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
{
struct tree_desc desc;
@@ -358,7 +371,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
}
else {
result = error("in tree %s: entry %s has bad mode %.6o",
- oid_to_hex(&tree->object.oid), entry.path, entry.mode);
+ describe_object(options, &tree->object), entry.path, entry.mode);
}
if (result < 0)
return result;
@@ -454,7 +467,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
case OBJ_TAG:
return fsck_walk_tag((struct tag *)obj, data, options);
default:
- error("Unknown object type for %s", oid_to_hex(&obj->oid));
+ error("Unknown object type for %s", describe_object(options, obj));
return -1;
}
}
@@ -901,9 +914,9 @@ int fsck_error_function(struct fsck_options *o,
struct object *obj, int msg_type, const char *message)
{
if (msg_type == FSCK_WARN) {
- warning("object %s: %s", oid_to_hex(&obj->oid), message);
+ warning("object %s: %s", describe_object(o, obj), message);
return 0;
}
- error("object %s: %s", oid_to_hex(&obj->oid), message);
+ error("object %s: %s", describe_object(o, obj), message);
return 1;
}