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>
This commit is contained in:

committed by
Junio C Hamano

parent
1cd772cc41
commit
90cf590f53
21
fsck.c
21
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user