Skip to content

Commit 7bb3bea

Browse files
committed
Merge branch 'cb/fsck-squelch-dangling'
* cb/fsck-squelch-dangling: fsck: --no-dangling omits "dangling object" information
2 parents 66b8800 + c6a13b2 commit 7bb3bea

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

Documentation/git-fsck.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SYNOPSIS
1111
[verse]
1212
'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
1313
[--[no-]full] [--strict] [--verbose] [--lost-found]
14-
[--[no-]progress] [<object>*]
14+
[--[no-]dangling] [--[no-]progress] [<object>*]
1515

1616
DESCRIPTION
1717
-----------
@@ -30,6 +30,11 @@ index file, all SHA1 references in .git/refs/*, and all reflogs (unless
3030
Print out objects that exist but that aren't reachable from any
3131
of the reference nodes.
3232

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+
3338
--root::
3439
Report root nodes.
3540

Documentation/git-repack.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ OPTIONS
3434
Especially useful when packing a repository that is used
3535
for private development. Use
3636
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
3838
dangling.
3939
+
4040
Note that users fetching over dumb protocols will have to fetch the

Documentation/user-manual.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ Checking the repository for corruption
15821582

15831583
The linkgit:git-fsck[1] command runs a number of self-consistency checks
15841584
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.
15861586

15871587
-------------------------------------------------
15881588
$ git fsck
@@ -1597,9 +1597,11 @@ dangling tree b24c2473f1fd3d91352a624795be026d64c8841f
15971597
...
15981598
-------------------------------------------------
15991599

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.
16031605

16041606
[[recovering-lost-changes]]
16051607
Recovering lost changes
@@ -3295,15 +3297,12 @@ it is with linkgit:git-fsck[1]; this may be time-consuming.
32953297
Assume the output looks like this:
32963298

32973299
------------------------------------------------
3298-
$ git fsck --full
3300+
$ git fsck --full --no-dangling
32993301
broken link from tree 2d9263c6d23595e7cb2a21e5ebbb53655278dff8
33003302
to blob 4b9458b3786228369c63936db65827de3cc06200
33013303
missing blob 4b9458b3786228369c63936db65827de3cc06200
33023304
------------------------------------------------
33033305

3304-
(Typically there will be some "dangling object" messages too, but they
3305-
aren't interesting.)
3306-
33073306
Now you know that blob 4b9458b3 is missing, and that the tree 2d9263c6
33083307
points to it. If you could find just one copy of that missing blob
33093308
object, possibly in some other repository, you could move it into

builtin/fsck.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static int errors_found;
2929
static int write_lost_and_found;
3030
static int verbose;
3131
static int show_progress = -1;
32+
static int show_dangling = 1;
3233
#define ERROR_OBJECT 01
3334
#define ERROR_REACHABLE 02
3435
#define ERROR_PACK 04
@@ -221,8 +222,9 @@ static void check_unreachable_object(struct object *obj)
221222
* start looking at, for example.
222223
*/
223224
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));
226228
if (write_lost_and_found) {
227229
char *filename = git_path("lost-found/%s/%s",
228230
obj->type == OBJ_COMMIT ? "commit" : "other",
@@ -614,6 +616,7 @@ static char const * const fsck_usage[] = {
614616
static struct option fsck_opts[] = {
615617
OPT__VERBOSE(&verbose, "be verbose"),
616618
OPT_BOOLEAN(0, "unreachable", &show_unreachable, "show unreachable objects"),
619+
OPT_BOOL(0, "dangling", &show_dangling, "show dangling objects"),
617620
OPT_BOOLEAN(0, "tags", &show_tags, "report tags"),
618621
OPT_BOOLEAN(0, "root", &show_root, "report root nodes"),
619622
OPT_BOOLEAN(0, "cache", &keep_cache_objects, "make index objects head nodes"),

t/t1450-fsck.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
2727
git init &&
2828
echo ../../../.git/objects >.git/objects/info/alternates &&
2929
test_commit C fileC one &&
30-
git fsck >../out 2>&1
30+
git fsck --no-dangling >../actual 2>&1
3131
) &&
32-
{
33-
grep -v dangling out >actual ||
34-
:
35-
} &&
3632
test_cmp empty actual
3733
'
3834

0 commit comments

Comments
 (0)