git-fsck: learn about --verbose
With --verbose, it gets really chatty now. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 5, 2007 at 03:44 UTC
20f1eb6b46645115695329a371d412eb3e714865
2 files changed
+45
-2
Documentation/git-fsck.txt
+4
-1
@@ -10,7 +10,7 @@ SYNOPSIS
10
--------
11
[verse]
12
'git-fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
13
- [--full] [--strict] [<object>*]
13
+ [--full] [--strict] [--verbose] [<object>*]
14
15
DESCRIPTION
16
-----------
@@ -61,6 +61,9 @@ index file and all SHA1 references in .git/refs/* as heads.
61
objects that triggers this check, but it is recommended
62
to check new projects with this flag.
63
64
+--verbose::
65
+ Be chatty.
66
+
67
It tests SHA1 and general object sanity, and it does full tracking of
68
the resulting reachability and everything else. It prints out any
69
corruption it finds (missing or bad objects), and if you use the
builtin-fsck.c
+41
-1
@@ -20,6 +20,7 @@ static int check_strict;
20
static int keep_cache_objects;
21
static unsigned char head_sha1[20];
22
static int errors_found;
23
+static int verbose;
24
#define ERROR_OBJECT 01
25
#define ERROR_REACHABLE 02
26
@@ -149,6 +150,9 @@ static void check_unreachable_object(struct object *obj)
150
151
static void check_object(struct object *obj)
152
{
153
+ if (verbose)
154
+ fprintf(stderr, "Checking %s\n", sha1_to_hex(obj->sha1));
155
+
156
if (obj->flags & REACHABLE)
157
check_reachable_object(obj);
158
else
@@ -161,6 +165,9 @@ static void check_connectivity(void)
165
166
/* Look up all the requirements, warn about missing objects.. */
167
max = get_max_object_index();
168
+ if (verbose)
169
+ fprintf(stderr, "Checking connectivity (%d objects)\n", max);
170
+
171
for (i = 0; i < max; i++) {
172
struct object *obj = get_indexed_object(i);
173
@@ -229,6 +236,10 @@ static int fsck_tree(struct tree *item)
236
const char *o_name;
237
const unsigned char *o_sha1;
238
239
+ if (verbose)
240
+ fprintf(stderr, "Checking tree %s\n",
241
+ sha1_to_hex(item->object.sha1));
242
+
243
init_tree_desc(&desc, item->buffer, item->size);
244
245
o_mode = 0;
@@ -317,6 +328,10 @@ static int fsck_commit(struct commit *commit)
328
char *buffer = commit->buffer;
329
unsigned char tree_sha1[20], sha1[20];
330
331
+ if (verbose)
332
+ fprintf(stderr, "Checking commit %s\n",
333
+ sha1_to_hex(commit->object.sha1));
334
+
335
if (memcmp(buffer, "tree ", 5))
336
return objerror(&commit->object, "invalid format - expected 'tree' line");
337
if (get_sha1_hex(buffer+5, tree_sha1) || buffer[45] != '\n')
@@ -345,6 +360,10 @@ static int fsck_tag(struct tag *tag)
360
{
361
struct object *tagged = tag->tagged;
362
363
+ if (verbose)
364
+ fprintf(stderr, "Checking tag %s\n",
365
+ sha1_to_hex(tag->object.sha1));
366
+
367
if (!tagged) {
368
return objerror(&tag->object, "could not load tagged object");
369
}
@@ -446,6 +465,9 @@ static void fsck_dir(int i, char *path)
465
if (!dir)
466
return;
467
468
+ if (verbose)
469
+ fprintf(stderr, "Checking directory %s\n", path);
470
+
471
while ((de = readdir(dir)) != NULL) {
472
char name[100];
473
unsigned char sha1[20];
@@ -480,6 +502,10 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
502
{
503
struct object *obj;
504
505
+ if (verbose)
506
+ fprintf(stderr, "Checking reflog %s->%s\n",
507
+ sha1_to_hex(osha1), sha1_to_hex(nsha1));
508
+
509
if (!is_null_sha1(osha1)) {
510
obj = lookup_object(osha1);
511
if (obj) {
@@ -549,6 +575,10 @@ static void get_default_heads(void)
575
static void fsck_object_dir(const char *path)
576
{
577
int i;
578
+
579
+ if (verbose)
580
+ fprintf(stderr, "Checking object directory\n");
581
+
582
for (i = 0; i < 256; i++) {
583
static char dir[4096];
584
sprintf(dir, "%s/%02x", path, i);
@@ -564,6 +594,9 @@ static int fsck_head_link(void)
594
int null_is_error = 0;
595
const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag);
596
597
+ if (verbose)
598
+ fprintf(stderr, "Checking HEAD link\n");
599
+
600
if (!head_points_at)
601
return error("Invalid HEAD");
602
if (!strcmp(head_points_at, "HEAD"))
@@ -586,6 +619,9 @@ static int fsck_cache_tree(struct cache_tree *it)
619
int i;
620
int err = 0;
621
622
+ if (verbose)
623
+ fprintf(stderr, "Checking cache tree\n");
624
+
625
if (0 <= it->entry_count) {
626
struct object *obj = parse_object(it->sha1);
627
if (!obj) {
@@ -605,7 +641,7 @@ static int fsck_cache_tree(struct cache_tree *it)
641
642
static const char fsck_usage[] =
643
"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
608
-"[--strict] <head-sha1>*]";
644
+"[--strict] [--verbose] <head-sha1>*]";
645
646
int cmd_fsck(int argc, char **argv, const char *prefix)
647
{
@@ -645,6 +681,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
681
check_strict = 1;
682
continue;
683
}
684
+ if (!strcmp(arg, "--verbose")) {
685
+ verbose = 1;
686
+ continue;
687
+ }
688
if (*arg == '-')
689
usage(fsck_usage);
690
}