fsck: --no-dangling omits "dangling object" information
The default output from "fsck" is often overwhelmed by informational message on dangling objects, especially if you do not repack often, and a real error can easily be buried. Add "--no-dangling" option to omit them, and update the user manual to demonstrate its use. Based on a patch by Clemens Buchacher, but reverted the part to change the default to --no-dangling, which is unsuitable for the first patch. The usual three-step procedure to break the backward compatibility over time needs to happen on top of this, if we were to go in that direction. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Feb 28, 2012 at 14:55 UTC
c6a13b2c86b71cb25011094ff2dee3d7769991a2
5 files changed
+20
-17
Documentation/git-fsck.txt
+6
-1
@@ -11,7 +11,7 @@ SYNOPSIS
11
[verse]
12
'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
13
[--[no-]full] [--strict] [--verbose] [--lost-found]
14
- [--[no-]progress] [<object>*]
14
+ [--[no-]dangling] [--[no-]progress] [<object>*]
15
16
DESCRIPTION
17
-----------
@@ -30,6 +30,11 @@ index file, all SHA1 references in .git/refs/*, and all reflogs (unless
30
Print out objects that exist but that aren't reachable from any
31
of the reference nodes.
32
33
+--dangling::
34
+--no-dangling::
35
+ Print objects that exist but that are never 'directly' used (default).
36
+ `--no-dangling` can be used to squech this information from the output.
37
+
38
--root::
39
Report root nodes.
40
Documentation/git-repack.txt
+1
-1
@@ -34,7 +34,7 @@ OPTIONS
34
Especially useful when packing a repository that is used
35
for private development. Use
36
with '-d'. This will clean up the objects that `git prune`
37
- leaves behind, but `git fsck --full` shows as
37
+ leaves behind, but `git fsck --full --dangling` shows as
38
dangling.
39
+
40
Note that users fetching over dumb protocols will have to fetch the
Documentation/user-manual.txt
+7
-8
@@ -1582,7 +1582,7 @@ Checking the repository for corruption
1582
1583
The linkgit:git-fsck[1] command runs a number of self-consistency checks
1584
on the repository, and reports on any problems. This may take some
1585
-time. The most common warning by far is about "dangling" objects:
1585
+time.
1586
1587
-------------------------------------------------
1588
$ git fsck
@@ -1597,9 +1597,11 @@ dangling tree b24c2473f1fd3d91352a624795be026d64c8841f
1597
...
1598
-------------------------------------------------
1599
1600
-Dangling objects are not a problem. At worst they may take up a little
1601
-extra disk space. They can sometimes provide a last-resort method for
1602
-recovering lost work--see <<dangling-objects>> for details.
1600
+You will see informational messages on dangling objects. They are objects
1601
+that still exist in the repository but are no longer referenced by any of
1602
+your branches, and can (and will) be removed after a while with "gc".
1603
+You can run `git fsck --no-dangling` to supress these messages, and still
1604
+view real errors.
1605
1606
[[recovering-lost-changes]]
1607
Recovering lost changes
@@ -3295,15 +3297,12 @@ it is with linkgit:git-fsck[1]; this may be time-consuming.
3297
Assume the output looks like this:
3298
3299
------------------------------------------------
3298
-$ git fsck --full
3300
+$ git fsck --full --no-dangling
3301
broken link from tree 2d9263c6d23595e7cb2a21e5ebbb53655278dff8
3302
to blob 4b9458b3786228369c63936db65827de3cc06200
3303
missing blob 4b9458b3786228369c63936db65827de3cc06200
3304
------------------------------------------------
3305
3304
-(Typically there will be some "dangling object" messages too, but they
3305
-aren't interesting.)
3306
-
3306
Now you know that blob 4b9458b3 is missing, and that the tree 2d9263c6
3307
points to it. If you could find just one copy of that missing blob
3308
object, possibly in some other repository, you could move it into
builtin/fsck.c
+5
-2
@@ -29,6 +29,7 @@ static int errors_found;
29
static int write_lost_and_found;
30
static int verbose;
31
static int show_progress = -1;
32
+static int show_dangling = 1;
33
#define ERROR_OBJECT 01
34
#define ERROR_REACHABLE 02
35
#define ERROR_PACK 04
@@ -221,8 +222,9 @@ static void check_unreachable_object(struct object *obj)
222
* start looking at, for example.
223
*/
224
if (!obj->used) {
224
- printf("dangling %s %s\n", typename(obj->type),
225
- sha1_to_hex(obj->sha1));
225
+ if (show_dangling)
226
+ printf("dangling %s %s\n", typename(obj->type),
227
+ sha1_to_hex(obj->sha1));
228
if (write_lost_and_found) {
229
char *filename = git_path("lost-found/%s/%s",
230
obj->type == OBJ_COMMIT ? "commit" : "other",
@@ -614,6 +616,7 @@ static char const * const fsck_usage[] = {
616
static struct option fsck_opts[] = {
617
OPT__VERBOSE(&verbose, "be verbose"),
618
OPT_BOOLEAN(0, "unreachable", &show_unreachable, "show unreachable objects"),
619
+ OPT_BOOL(0, "dangling", &show_dangling, "show dangling objects"),
620
OPT_BOOLEAN(0, "tags", &show_tags, "report tags"),
621
OPT_BOOLEAN(0, "root", &show_root, "report root nodes"),
622
OPT_BOOLEAN(0, "cache", &keep_cache_objects, "make index objects head nodes"),
t/t1450-fsck.sh
+1
-5
@@ -27,12 +27,8 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
27
git init &&
28
echo ../../../.git/objects >.git/objects/info/alternates &&
29
test_commit C fileC one &&
30
- git fsck >../out 2>&1
30
+ git fsck --no-dangling >../actual 2>&1
31
) &&
32
- {
33
- grep -v dangling out >actual ||
34
- :
35
- } &&
32
test_cmp empty actual
33
'
34