Skip to content

Commit 20f1eb6

Browse files
dschogitster
authored andcommitted
git-fsck: learn about --verbose
With --verbose, it gets really chatty now. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 00f429a commit 20f1eb6

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

Documentation/git-fsck.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git-fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
13-
[--full] [--strict] [<object>*]
13+
[--full] [--strict] [--verbose] [<object>*]
1414

1515
DESCRIPTION
1616
-----------
@@ -61,6 +61,9 @@ index file and all SHA1 references in .git/refs/* as heads.
6161
objects that triggers this check, but it is recommended
6262
to check new projects with this flag.
6363

64+
--verbose::
65+
Be chatty.
66+
6467
It tests SHA1 and general object sanity, and it does full tracking of
6568
the resulting reachability and everything else. It prints out any
6669
corruption it finds (missing or bad objects), and if you use the

builtin-fsck.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static int check_strict;
2020
static int keep_cache_objects;
2121
static unsigned char head_sha1[20];
2222
static int errors_found;
23+
static int verbose;
2324
#define ERROR_OBJECT 01
2425
#define ERROR_REACHABLE 02
2526

@@ -149,6 +150,9 @@ static void check_unreachable_object(struct object *obj)
149150

150151
static void check_object(struct object *obj)
151152
{
153+
if (verbose)
154+
fprintf(stderr, "Checking %s\n", sha1_to_hex(obj->sha1));
155+
152156
if (obj->flags & REACHABLE)
153157
check_reachable_object(obj);
154158
else
@@ -161,6 +165,9 @@ static void check_connectivity(void)
161165

162166
/* Look up all the requirements, warn about missing objects.. */
163167
max = get_max_object_index();
168+
if (verbose)
169+
fprintf(stderr, "Checking connectivity (%d objects)\n", max);
170+
164171
for (i = 0; i < max; i++) {
165172
struct object *obj = get_indexed_object(i);
166173

@@ -229,6 +236,10 @@ static int fsck_tree(struct tree *item)
229236
const char *o_name;
230237
const unsigned char *o_sha1;
231238

239+
if (verbose)
240+
fprintf(stderr, "Checking tree %s\n",
241+
sha1_to_hex(item->object.sha1));
242+
232243
init_tree_desc(&desc, item->buffer, item->size);
233244

234245
o_mode = 0;
@@ -317,6 +328,10 @@ static int fsck_commit(struct commit *commit)
317328
char *buffer = commit->buffer;
318329
unsigned char tree_sha1[20], sha1[20];
319330

331+
if (verbose)
332+
fprintf(stderr, "Checking commit %s\n",
333+
sha1_to_hex(commit->object.sha1));
334+
320335
if (memcmp(buffer, "tree ", 5))
321336
return objerror(&commit->object, "invalid format - expected 'tree' line");
322337
if (get_sha1_hex(buffer+5, tree_sha1) || buffer[45] != '\n')
@@ -345,6 +360,10 @@ static int fsck_tag(struct tag *tag)
345360
{
346361
struct object *tagged = tag->tagged;
347362

363+
if (verbose)
364+
fprintf(stderr, "Checking tag %s\n",
365+
sha1_to_hex(tag->object.sha1));
366+
348367
if (!tagged) {
349368
return objerror(&tag->object, "could not load tagged object");
350369
}
@@ -446,6 +465,9 @@ static void fsck_dir(int i, char *path)
446465
if (!dir)
447466
return;
448467

468+
if (verbose)
469+
fprintf(stderr, "Checking directory %s\n", path);
470+
449471
while ((de = readdir(dir)) != NULL) {
450472
char name[100];
451473
unsigned char sha1[20];
@@ -480,6 +502,10 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
480502
{
481503
struct object *obj;
482504

505+
if (verbose)
506+
fprintf(stderr, "Checking reflog %s->%s\n",
507+
sha1_to_hex(osha1), sha1_to_hex(nsha1));
508+
483509
if (!is_null_sha1(osha1)) {
484510
obj = lookup_object(osha1);
485511
if (obj) {
@@ -549,6 +575,10 @@ static void get_default_heads(void)
549575
static void fsck_object_dir(const char *path)
550576
{
551577
int i;
578+
579+
if (verbose)
580+
fprintf(stderr, "Checking object directory\n");
581+
552582
for (i = 0; i < 256; i++) {
553583
static char dir[4096];
554584
sprintf(dir, "%s/%02x", path, i);
@@ -564,6 +594,9 @@ static int fsck_head_link(void)
564594
int null_is_error = 0;
565595
const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag);
566596

597+
if (verbose)
598+
fprintf(stderr, "Checking HEAD link\n");
599+
567600
if (!head_points_at)
568601
return error("Invalid HEAD");
569602
if (!strcmp(head_points_at, "HEAD"))
@@ -586,6 +619,9 @@ static int fsck_cache_tree(struct cache_tree *it)
586619
int i;
587620
int err = 0;
588621

622+
if (verbose)
623+
fprintf(stderr, "Checking cache tree\n");
624+
589625
if (0 <= it->entry_count) {
590626
struct object *obj = parse_object(it->sha1);
591627
if (!obj) {
@@ -605,7 +641,7 @@ static int fsck_cache_tree(struct cache_tree *it)
605641

606642
static const char fsck_usage[] =
607643
"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
608-
"[--strict] <head-sha1>*]";
644+
"[--strict] [--verbose] <head-sha1>*]";
609645

610646
int cmd_fsck(int argc, char **argv, const char *prefix)
611647
{
@@ -645,6 +681,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
645681
check_strict = 1;
646682
continue;
647683
}
684+
if (!strcmp(arg, "--verbose")) {
685+
verbose = 1;
686+
continue;
687+
}
648688
if (*arg == '-')
649689
usage(fsck_usage);
650690
}

0 commit comments

Comments
 (0)