mirror of
https://github.com/git/git
synced 2024-10-06 00:29:28 +00:00
fsck: don't require object structs for display functions
Our printable_type() and describe_object() functions take whole object structs, but they really only care about the oid and type. Let's take those individually in order to give our callers more flexibility. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
733902905d
commit
82ef89b318
|
@ -50,23 +50,20 @@ static int name_objects;
|
||||||
#define ERROR_REFS 010
|
#define ERROR_REFS 010
|
||||||
#define ERROR_COMMIT_GRAPH 020
|
#define ERROR_COMMIT_GRAPH 020
|
||||||
|
|
||||||
static const char *describe_object(struct object *obj)
|
static const char *describe_object(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
return fsck_describe_object(&fsck_walk_options, &obj->oid);
|
return fsck_describe_object(&fsck_walk_options, oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *printable_type(struct object *obj)
|
static const char *printable_type(const struct object_id *oid,
|
||||||
|
enum object_type type)
|
||||||
{
|
{
|
||||||
const char *ret;
|
const char *ret;
|
||||||
|
|
||||||
if (obj->type == OBJ_NONE) {
|
if (type == OBJ_NONE)
|
||||||
enum object_type type = oid_object_info(the_repository,
|
type = oid_object_info(the_repository, oid, NULL);
|
||||||
&obj->oid, NULL);
|
|
||||||
if (type > 0)
|
|
||||||
object_as_type(the_repository, obj, type, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = type_name(obj->type);
|
ret = type_name(type);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = _("unknown");
|
ret = _("unknown");
|
||||||
|
|
||||||
|
@ -101,7 +98,8 @@ static int objerror(struct object *obj, const char *err)
|
||||||
errors_found |= ERROR_OBJECT;
|
errors_found |= ERROR_OBJECT;
|
||||||
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
|
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
|
||||||
fprintf_ln(stderr, _("error in %s %s: %s"),
|
fprintf_ln(stderr, _("error in %s %s: %s"),
|
||||||
printable_type(obj), describe_object(obj), err);
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid), err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,12 +110,14 @@ static int fsck_error_func(struct fsck_options *o,
|
||||||
case FSCK_WARN:
|
case FSCK_WARN:
|
||||||
/* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
|
/* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
|
||||||
fprintf_ln(stderr, _("warning in %s %s: %s"),
|
fprintf_ln(stderr, _("warning in %s %s: %s"),
|
||||||
printable_type(obj), describe_object(obj), message);
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid), message);
|
||||||
return 0;
|
return 0;
|
||||||
case FSCK_ERROR:
|
case FSCK_ERROR:
|
||||||
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
|
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
|
||||||
fprintf_ln(stderr, _("error in %s %s: %s"),
|
fprintf_ln(stderr, _("error in %s %s: %s"),
|
||||||
printable_type(obj), describe_object(obj), message);
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid), message);
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
BUG("%d (FSCK_IGNORE?) should never trigger this callback", type);
|
BUG("%d (FSCK_IGNORE?) should never trigger this callback", type);
|
||||||
|
@ -138,7 +138,8 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
/* ... these references to parent->fld are safe here */
|
/* ... these references to parent->fld are safe here */
|
||||||
printf_ln(_("broken link from %7s %s"),
|
printf_ln(_("broken link from %7s %s"),
|
||||||
printable_type(parent), describe_object(parent));
|
printable_type(&parent->oid, parent->type),
|
||||||
|
describe_object(&parent->oid));
|
||||||
printf_ln(_("broken link from %7s %s"),
|
printf_ln(_("broken link from %7s %s"),
|
||||||
(type == OBJ_ANY ? _("unknown") : type_name(type)),
|
(type == OBJ_ANY ? _("unknown") : type_name(type)),
|
||||||
_("unknown"));
|
_("unknown"));
|
||||||
|
@ -166,10 +167,10 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
|
||||||
if (parent && !has_object_file(&obj->oid)) {
|
if (parent && !has_object_file(&obj->oid)) {
|
||||||
printf_ln(_("broken link from %7s %s\n"
|
printf_ln(_("broken link from %7s %s\n"
|
||||||
" to %7s %s"),
|
" to %7s %s"),
|
||||||
printable_type(parent),
|
printable_type(&parent->oid, parent->type),
|
||||||
describe_object(parent),
|
describe_object(&parent->oid),
|
||||||
printable_type(obj),
|
printable_type(&obj->oid, obj->type),
|
||||||
describe_object(obj));
|
describe_object(&obj->oid));
|
||||||
errors_found |= ERROR_REACHABLE;
|
errors_found |= ERROR_REACHABLE;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -275,8 +276,9 @@ static void check_reachable_object(struct object *obj)
|
||||||
return;
|
return;
|
||||||
if (has_object_pack(&obj->oid))
|
if (has_object_pack(&obj->oid))
|
||||||
return; /* it is in pack - forget about it */
|
return; /* it is in pack - forget about it */
|
||||||
printf_ln(_("missing %s %s"), printable_type(obj),
|
printf_ln(_("missing %s %s"),
|
||||||
describe_object(obj));
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid));
|
||||||
errors_found |= ERROR_REACHABLE;
|
errors_found |= ERROR_REACHABLE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -301,8 +303,9 @@ static void check_unreachable_object(struct object *obj)
|
||||||
* since this is something that is prunable.
|
* since this is something that is prunable.
|
||||||
*/
|
*/
|
||||||
if (show_unreachable) {
|
if (show_unreachable) {
|
||||||
printf_ln(_("unreachable %s %s"), printable_type(obj),
|
printf_ln(_("unreachable %s %s"),
|
||||||
describe_object(obj));
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,12 +323,13 @@ static void check_unreachable_object(struct object *obj)
|
||||||
*/
|
*/
|
||||||
if (!(obj->flags & USED)) {
|
if (!(obj->flags & USED)) {
|
||||||
if (show_dangling)
|
if (show_dangling)
|
||||||
printf_ln(_("dangling %s %s"), printable_type(obj),
|
printf_ln(_("dangling %s %s"),
|
||||||
describe_object(obj));
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid));
|
||||||
if (write_lost_and_found) {
|
if (write_lost_and_found) {
|
||||||
char *filename = git_pathdup("lost-found/%s/%s",
|
char *filename = git_pathdup("lost-found/%s/%s",
|
||||||
obj->type == OBJ_COMMIT ? "commit" : "other",
|
obj->type == OBJ_COMMIT ? "commit" : "other",
|
||||||
describe_object(obj));
|
describe_object(&obj->oid));
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (safe_create_leading_directories_const(filename)) {
|
if (safe_create_leading_directories_const(filename)) {
|
||||||
|
@ -338,7 +342,7 @@ static void check_unreachable_object(struct object *obj)
|
||||||
if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))
|
if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))
|
||||||
die_errno(_("could not write '%s'"), filename);
|
die_errno(_("could not write '%s'"), filename);
|
||||||
} else
|
} else
|
||||||
fprintf(f, "%s\n", describe_object(obj));
|
fprintf(f, "%s\n", describe_object(&obj->oid));
|
||||||
if (fclose(f))
|
if (fclose(f))
|
||||||
die_errno(_("could not finish '%s'"),
|
die_errno(_("could not finish '%s'"),
|
||||||
filename);
|
filename);
|
||||||
|
@ -357,7 +361,7 @@ static void check_unreachable_object(struct object *obj)
|
||||||
static void check_object(struct object *obj)
|
static void check_object(struct object *obj)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf_ln(stderr, _("Checking %s"), describe_object(obj));
|
fprintf_ln(stderr, _("Checking %s"), describe_object(&obj->oid));
|
||||||
|
|
||||||
if (obj->flags & REACHABLE)
|
if (obj->flags & REACHABLE)
|
||||||
check_reachable_object(obj);
|
check_reachable_object(obj);
|
||||||
|
@ -415,7 +419,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf_ln(stderr, _("Checking %s %s"),
|
fprintf_ln(stderr, _("Checking %s %s"),
|
||||||
printable_type(obj), describe_object(obj));
|
printable_type(&obj->oid, obj->type),
|
||||||
|
describe_object(&obj->oid));
|
||||||
|
|
||||||
if (fsck_walk(obj, NULL, &fsck_obj_options))
|
if (fsck_walk(obj, NULL, &fsck_obj_options))
|
||||||
objerror(obj, _("broken links"));
|
objerror(obj, _("broken links"));
|
||||||
|
@ -428,7 +433,7 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
|
||||||
|
|
||||||
if (!commit->parents && show_root)
|
if (!commit->parents && show_root)
|
||||||
printf_ln(_("root %s"),
|
printf_ln(_("root %s"),
|
||||||
describe_object(&commit->object));
|
describe_object(&commit->object.oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj->type == OBJ_TAG) {
|
if (obj->type == OBJ_TAG) {
|
||||||
|
@ -436,10 +441,10 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
|
||||||
|
|
||||||
if (show_tags && tag->tagged) {
|
if (show_tags && tag->tagged) {
|
||||||
printf_ln(_("tagged %s %s (%s) in %s"),
|
printf_ln(_("tagged %s %s (%s) in %s"),
|
||||||
printable_type(tag->tagged),
|
printable_type(&tag->tagged->oid, tag->tagged->type),
|
||||||
describe_object(tag->tagged),
|
describe_object(&tag->tagged->oid),
|
||||||
tag->tag,
|
tag->tag,
|
||||||
describe_object(&tag->object));
|
describe_object(&tag->object.oid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue