git-gc.txt: expand discussion of races with other processes
In general, "git gc" may delete objects that another concurrent process is using but hasn't created a reference to. Git has some mitigations, but they fall short of a complete solution. Document this in the git-gc(1) man page and add a reference from the documentation of the gc.pruneExpire config variable. Based on a write-up by Jeff King: http://marc.info/?l=git&m=147922960131779&w=2 Signed-off-by: Matt McCutchen <matt@mattmccutchen.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matt McCutchen committed
Nov 15, 2016 at 14:08 UTC
f1350d0c125a1e6a73e3b6461fa90c77843c5f74
2 files changed
+29
-9
Documentation/config.txt
+3
-1
@@ -1341,7 +1341,9 @@ gc.pruneExpire::
1341
Override the grace period with this config variable. The value
1342
"now" may be used to disable this grace period and always prune
1343
unreachable objects immediately, or "never" may be used to
1344
- suppress pruning.
1344
+ suppress pruning. This feature helps prevent corruption when
1345
+ 'git gc' runs concurrently with another process writing to the
1346
+ repository; see the "NOTES" section of linkgit:git-gc[1].
1347
1348
gc.worktreePruneExpire::
1349
When 'git gc' is run, it calls
Documentation/git-gc.txt
+26
-8
@@ -63,11 +63,10 @@ automatic consolidation of packs.
63
--prune=<date>::
64
Prune loose objects older than date (default is 2 weeks ago,
65
overridable by the config variable `gc.pruneExpire`).
66
- --prune=all prunes loose objects regardless of their age (do
67
- not use --prune=all unless you know exactly what you are doing.
68
- Unless the repository is quiescent, you will lose newly created
69
- objects that haven't been anchored with the refs and end up
70
- corrupting your repository). --prune is on by default.
66
+ --prune=all prunes loose objects regardless of their age and
67
+ increases the risk of corruption if another process is writing to
68
+ the repository concurrently; see "NOTES" below. --prune is on by
69
+ default.
70
71
--no-prune::
72
Do not prune any loose objects.
@@ -138,17 +137,36 @@ default is "2 weeks ago".
137
Notes
138
-----
139
141
-'git gc' tries very hard to be safe about the garbage it collects. In
140
+'git gc' tries very hard not to delete objects that are referenced
141
+anywhere in your repository. In
142
particular, it will keep not only objects referenced by your current set
143
of branches and tags, but also objects referenced by the index,
144
remote-tracking branches, refs saved by 'git filter-branch' in
145
refs/original/, or reflogs (which may reference commits in branches
146
that were later amended or rewound).
147
-
148
-If you are expecting some objects to be collected and they aren't, check
147
+If you are expecting some objects to be deleted and they aren't, check
148
all of those locations and decide whether it makes sense in your case to
149
remove those references.
150
151
+On the other hand, when 'git gc' runs concurrently with another process,
152
+there is a risk of it deleting an object that the other process is using
153
+but hasn't created a reference to. This may just cause the other process
154
+to fail or may corrupt the repository if the other process later adds a
155
+reference to the deleted object. Git has two features that significantly
156
+mitigate this problem:
157
+
158
+. Any object with modification time newer than the `--prune` date is kept,
159
+ along with everything reachable from it.
160
+
161
+. Most operations that add an object to the database update the
162
+ modification time of the object if it is already present so that #1
163
+ applies.
164
+
165
+However, these features fall short of a complete solution, so users who
166
+run commands concurrently have to live with some risk of corruption (which
167
+seems to be low in practice) unless they turn off automatic garbage
168
+collection with 'git config gc.auto 0'.
169
+
170
HOOKS
171
-----
172