13
#include "dir.h"
14
#include "progress.h"
15
#include "streaming.h"
16
+#include "decorate.h"
17
18
#define REACHABLE 0x0001
19
#define SEEN 0x0002
36
static int verbose;
37
static int show_progress = -1;
38
static int show_dangling = 1;
39
+static int name_objects;
40
#define ERROR_OBJECT 01
41
#define ERROR_REACHABLE 02
42
#define ERROR_PACK 04
44
45
static const char *describe_object(struct object *obj)
46
{
45
- return oid_to_hex(&obj->oid);
47
+ static struct strbuf buf = STRBUF_INIT;
48
+ char *name = name_objects ?
49
+ lookup_decoration(fsck_walk_options.object_names, obj) : NULL;
50
+
51
+ strbuf_reset(&buf);
52
+ strbuf_addstr(&buf, oid_to_hex(&obj->oid));
53
+ if (name)
54
+ strbuf_addf(&buf, " (%s)", name);
55
+
56
+ return buf.buf;
57
}
58
59
static int fsck_config(const char *var, const char *value, void *cb)
389
390
static int default_refs;
391
381
-static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
392
+static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,
393
+ unsigned long timestamp)
394
{
395
struct object *obj;
396
397
if (!is_null_sha1(sha1)) {
398
obj = lookup_object(sha1);
399
if (obj) {
400
+ if (timestamp && name_objects)
401
+ add_decoration(fsck_walk_options.object_names,
402
+ obj,
403
+ xstrfmt("%s@{%ld}", refname, timestamp));
404
obj->used = 1;
405
mark_object_reachable(obj);
406
} else {
420
fprintf(stderr, "Checking reflog %s->%s\n",
421
sha1_to_hex(osha1), sha1_to_hex(nsha1));
422
407
- fsck_handle_reflog_sha1(refname, osha1);
408
- fsck_handle_reflog_sha1(refname, nsha1);
423
+ fsck_handle_reflog_sha1(refname, osha1, 0);
424
+ fsck_handle_reflog_sha1(refname, nsha1, timestamp);
425
return 0;
426
}
427
450
}
451
default_refs++;
452
obj->used = 1;
453
+ if (name_objects)
454
+ add_decoration(fsck_walk_options.object_names,
455
+ obj, xstrdup(refname));
456
mark_object_reachable(obj);
457
458
return 0;
568
return 1;
569
}
570
obj->used = 1;
571
+ if (name_objects)
572
+ add_decoration(fsck_walk_options.object_names,
573
+ obj, xstrdup(":"));
574
mark_object_reachable(obj);
575
if (obj->type != OBJ_TREE)
576
err |= objerror(obj, "non-tree in cache-tree");
599
OPT_BOOL(0, "lost-found", &write_lost_and_found,
600
N_("write dangling objects in .git/lost-found")),
601
OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
602
+ OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")),
603
OPT_END(),
604
};
605
629
include_reflogs = 0;
630
}
631
632
+ if (name_objects)
633
+ fsck_walk_options.object_names =
634
+ xcalloc(1, sizeof(struct decoration));
635
+
636
git_config(fsck_config, NULL);
637
638
fsck_head_link();
688
continue;
689
690
obj->used = 1;
691
+ if (name_objects)
692
+ add_decoration(fsck_walk_options.object_names,
693
+ obj, xstrdup(arg));
694
mark_object_reachable(obj);
695
heads++;
696
continue;
723
continue;
724
obj = &blob->object;
725
obj->used = 1;
726
+ if (name_objects)
727
+ add_decoration(fsck_walk_options.object_names,
728
+ obj,
729
+ xstrfmt(":%s", active_cache[i]->name));
730
mark_object_reachable(obj);
731
}
732
if (active_cache_tree)