@matheusbsbs / matheus-bagliano / commits / 2b86976bfd
Fork 0

git-prune: never lose objects reachable from our refs.

Explicit <head> arguments to git-prune replaces, instead of extends, the list of heads used for reachability analysis by fsck-objects. By giving a subset of heads by mistake, objects reachable only from other heads can be removed, resulting in a corrupted repository. This commit stops replacing the list of heads, and makes the command line arguments to add to them instead for safety. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 8, 2005 at 23:18 UTC 2b86976bfd6e42609692d57fffaef72bd985c23a
2 files changed +14 -19
Documentation/git-prune.txt
+9 -18
@@ -13,10 +13,11 @@ SYNOPSIS
13 DESCRIPTION
14 -----------
15
16 -This runs `git-fsck-objects --unreachable` using the heads
17 -specified on the command line (or `$GIT_DIR/refs/heads/\*` and
18 -`$GIT_DIR/refs/tags/\*` if none is specified), and prunes all
19 -unreachable objects from the object database. In addition, it
16 +This runs `git-fsck-objects --unreachable` using all the refs
17 +available in `$GIT_DIR/refs`, optionally with additional set of
18 +objects specified on the command line, and prunes all
19 +objects unreachable from any of these head objects from the object database.
20 +In addition, it
21 prunes the unpacked objects that are also found in packs by
22 running `git prune-packed`.
23
@@ -31,29 +32,19 @@ OPTIONS
32 Do not interpret any more arguments as options.
33
34 <head>...::
34 - Instead of keeping objects
35 + In addition to objects
36 reachable from any of our references, keep objects
36 - reachable from only listed <head>s.
37 -+
38 -Note that the explicitly named <head>s are *not* appended to the
39 -default set of references, but they replace them. In general you
40 -would want to say `git prune $(git-rev-parse --all) extra1
41 -extra2` to keep chains of commits leading to extra1, extra2,
42 -... in addition to what are reachable from your own refs.
43 -Saying `git prune extra1 extra2` would *lose* objects reachable
44 -only from the usual refs, which is usually not what you want.
45 -
37 + reachable from listed <head>s.
38
39 EXAMPLE
40 -------
41
50 -To prune objects not used by your repository and another that
42 +To prune objects not used by your repository nor another that
43 borrows from your repository via its
44 `.git/objects/info/alternates`:
45
46 ------------
55 -$ git prune $(git-rev-parse --all) \
56 - $(cd ../another && $(git-rev-parse --all))
47 +$ git prune $(cd ../another && $(git-rev-parse --all))
48 ------------
49
50 Author
git-prune.sh
+5 -1
@@ -16,7 +16,11 @@ do
16 done
17
18 sync
19 -git-fsck-objects --full --cache --unreachable "$@" |
19 +case "$#" in
20 +0) git-fsck-objects --full --cache --unreachable ;;
21 +*) git-fsck-objects --full --cache --unreachable $(git-rev-parse --all) "$@" ;;
22 +esac |
23 +
24 sed -ne '/unreachable /{
25 s/unreachable [^ ][^ ]* //
26 s|\(..\)|\1/|p