1
0
mirror of https://github.com/git/git.git synced 2024-09-25 12:11:02 +02:00
git/builtin
Jeff King d3038d22f9 prune: keep objects reachable from recent objects
Our current strategy with prune is that an object falls into
one of three categories:

  1. Reachable (from ref tips, reflogs, index, etc).

  2. Not reachable, but recent (based on the --expire time).

  3. Not reachable and not recent.

We keep objects from (1) and (2), but prune objects in (3).
The point of (2) is that these objects may be part of an
in-progress operation that has not yet updated any refs.

However, it is not always the case that objects for an
in-progress operation will have a recent mtime. For example,
the object database may have an old copy of a blob (from an
abandoned operation, a branch that was deleted, etc). If we
create a new tree that points to it, a simultaneous prune
will leave our tree, but delete the blob. Referencing that
tree with a commit will then work (we check that the tree is
in the object database, but not that all of its referred
objects are), as will mentioning the commit in a ref. But
the resulting repo is corrupt; we are missing the blob
reachable from a ref.

One way to solve this is to be more thorough when
referencing a sha1: make sure that not only do we have that
sha1, but that we have objects it refers to, and so forth
recursively. The problem is that this is very expensive.
Creating a parent link would require traversing the entire
object graph!

Instead, this patch pushes the extra work onto prune, which
runs less frequently (and has to look at the whole object
graph anyway). It creates a new category of objects: objects
which are not recent, but which are reachable from a recent
object. We do not prune these objects, just like the
reachable and recent ones.

This lets us avoid the recursive check above, because if we
have an object, even if it is unreachable, we should have
its referent. We can make a simple inductive argument that
with this patch, this property holds (that there are no
objects with missing referents in the repository):

  0. When we have no objects, we have nothing to refer or be
     referred to, so the property holds.

  1. If we add objects to the repository, their direct
     referents must generally exist (e.g., if you create a
     tree, the blobs it references must exist; if you create
     a commit to point at the tree, the tree must exist).
     This is already the case before this patch. And it is
     not 100% foolproof (you can make bogus objects using
     `git hash-object`, for example), but it should be the
     case for normal usage.

     Therefore for any sequence of object additions, the
     property will continue to hold.

  2. If we remove objects from the repository, then we will
     not remove a child object (like a blob) if an object
     that refers to it is being kept. That is the part
     implemented by this patch.

     Note, however, that our reachability check and the
     actual pruning are not atomic. So it _is_ still
     possible to violate the property (e.g., an object
     becomes referenced just as we are deleting it). This
     patch is shooting for eliminating problems where the
     mtimes of dependent objects differ by hours or days,
     and one is dropped without the other. It does nothing
     to help with short races.

Naively, the simplest way to implement this would be to add
all recent objects as tips to the reachability traversal.
However, this does not perform well. In a recently-packed
repository, all reachable objects will also be recent, and
therefore we have to look at each object twice. This patch
instead performs the reachability traversal, then follows up
with a second traversal for recent objects, skipping any
that have already been marked.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-16 10:10:42 -07:00
..
add.c run-command: introduce CHILD_PROCESS_INIT 2014-08-20 09:53:37 -07:00
annotate.c annotate: use argv_array 2014-07-16 11:10:11 -07:00
apply.c use REALLOC_ARRAY for changing the allocation size of arrays 2014-09-18 09:13:42 -07:00
archive.c
bisect--helper.c
blame.c Merge branch 'bb/date-iso-strict' 2014-09-19 11:38:32 -07:00
branch.c branch: clean up commit flags after merge-filter walk 2014-09-18 09:21:16 -07:00
bundle.c
cat-file.c Merge branch 'jk/warn-on-object-refname-ambiguity' 2014-03-25 11:07:36 -07:00
check-attr.c Merge branch 'jc/check-attr-honor-working-tree' into maint 2014-03-18 14:03:03 -07:00
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout-index.c entry.c: update cache_changed if refresh_cache is set in checkout_entry() 2014-06-13 11:49:39 -07:00
checkout.c Merge branch 'dt/cache-tree-repair' 2014-09-11 10:33:32 -07:00
clean.c Merge branch 'rs/clean-menu-item-defn' 2014-09-09 12:54:06 -07:00
clone.c Merge branch 'da/styles' 2014-09-19 11:38:35 -07:00
column.c
commit-tree.c commit_tree: take a pointer/len pair rather than a const strbuf 2014-06-12 10:29:41 -07:00
commit.c Merge branch 'ah/grammofix' 2014-09-19 11:38:35 -07:00
config.c Merge branch 'ta/config-add-to-empty-or-true-fix' 2014-09-19 11:38:40 -07:00
count-objects.c count-objects: use for_each_loose_file_in_objdir 2014-10-16 10:10:41 -07:00
credential.c
describe.c hashmap: add simplified hashmap_get_from_hash() API 2014-07-07 13:56:35 -07:00
diff-files.c
diff-index.c
diff-tree.c diff-tree: avoid lookup_unknown_object 2014-07-28 10:14:34 -07:00
diff.c
fast-export.c teach fast-export an --anonymize option 2014-08-27 10:42:16 -07:00
fetch-pack.c
fetch.c fetch: silence git-gc if --quiet is given 2014-08-18 10:14:19 -07:00
fmt-merge-msg.c Merge branch 'jk/xstrfmt' 2014-07-09 11:34:05 -07:00
for-each-ref.c Merge branch 'rs/realloc-array' 2014-09-26 14:39:45 -07:00
fsck.c Merge branch 'js/fsck-tag-validation' 2014-09-26 14:39:43 -07:00
gc.c builtin/gc.c: replace git_config() with git_config_get_*() family 2014-08-07 13:33:28 -07:00
get-tar-commit-id.c
grep.c Merge branch 'sk/spawn-less-case-insensitively-from-grep-O-i' into maint 2014-06-25 11:47:49 -07:00
hash-object.c hash-object: add --literally option 2014-09-11 14:23:51 -07:00
help.c run-command: introduce CHILD_PROCESS_INIT 2014-08-20 09:53:37 -07:00
index-pack.c Merge branch 'rs/realloc-array' 2014-09-26 14:39:45 -07:00
init-db.c Merge branch 'rs/strbuf-getcwd' 2014-09-02 13:28:44 -07:00
log.c Merge branch 'rs/realloc-array' 2014-09-26 14:39:45 -07:00
ls-files.c grammofix in user-facing messages 2014-09-02 12:00:30 -07:00
ls-remote.c builtin/ls-remote.c: rearrange xcalloc arguments 2014-05-27 14:00:43 -07:00
ls-tree.c
mailinfo.c mailinfo: work around -Wstring-plus-int warning 2014-09-22 13:46:43 -07:00
mailsplit.c mailsplit.c: remove dead code 2014-08-13 09:50:58 -07:00
merge-base.c
merge-file.c
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c merge-tree: remove unused df_conflict arguments 2014-09-02 11:02:58 -07:00
merge.c Merge branch 'rs/realloc-array' 2014-09-26 14:39:45 -07:00
mktag.c
mktree.c
mv.c use REALLOC_ARRAY for changing the allocation size of arrays 2014-09-18 09:13:42 -07:00
name-rev.c use xstrfmt to replace xmalloc + strcpy/strcat 2014-06-19 15:20:54 -07:00
notes.c Merge branch 'ah/grammofix' 2014-09-19 11:38:35 -07:00
pack-objects.c use REALLOC_ARRAY for changing the allocation size of arrays 2014-09-18 09:13:42 -07:00
pack-redundant.c
pack-refs.c
patch-id.c patch-id: make it stable against hunk reordering 2014-06-10 13:09:24 -07:00
prune-packed.c prune-packed: use for_each_loose_file_in_objdir 2014-10-16 10:10:40 -07:00
prune.c prune: keep objects reachable from recent objects 2014-10-16 10:10:42 -07:00
push.c push: the beginning of "git push --signed" 2014-09-15 13:23:20 -07:00
read-tree.c read-tree: note about dropping split-index mode or index version 2014-06-13 11:49:41 -07:00
receive-pack.c Merge branch 'jc/push-cert' 2014-10-08 13:05:25 -07:00
reflog.c prune: keep objects reachable from recent objects 2014-10-16 10:10:42 -07:00
remote-ext.c run-command: introduce CHILD_PROCESS_INIT 2014-08-20 09:53:37 -07:00
remote-fd.c
remote.c Merge branch 'bg/xcalloc-nmemb-then-size' into maint 2014-07-22 10:25:17 -07:00
repack.c Merge branch 'jk/prune-packed-server-info' 2014-09-26 14:39:44 -07:00
replace.c Merge branch 'rs/ref-transaction-1' 2014-09-11 10:33:31 -07:00
rerere.c rerere: fix for merge.conflictstyle 2014-04-30 10:30:02 -07:00
reset.c Merge branch 'nd/split-index' 2014-07-16 11:25:40 -07:00
rev-list.c commit: record buffer length in cache 2014-06-13 12:09:38 -07:00
rev-parse.c refs: make rev-parse --quiet actually quiet 2014-09-19 10:46:15 -07:00
revert.c parse-options: multi-word argh should use dash to separate words 2014-03-24 10:43:34 -07:00
rm.c grammofix in user-facing messages 2014-09-02 12:00:30 -07:00
send-pack.c Merge branch 'jc/push-cert' 2014-10-08 13:05:25 -07:00
shortlog.c
show-branch.c Merge branch 'da/rev-parse-verify-quiet' 2014-09-29 12:36:10 -07:00
show-ref.c
stripspace.c
symbolic-ref.c
tag.c Merge branch 'rs/ref-transaction-1' 2014-09-11 10:33:31 -07:00
unpack-file.c
unpack-objects.c fsck_object(): allow passing object data separately from the object itself 2014-09-10 13:54:21 -07:00
update-index.c Merge branch 'nd/split-index' 2014-07-16 11:25:40 -07:00
update-ref.c update-ref --stdin: pass transaction around explicitly 2014-09-03 10:04:19 -07:00
update-server-info.c
upload-archive.c
var.c
verify-commit.c verify-commit: scriptable commit signature verification 2014-06-23 15:50:31 -07:00
verify-pack.c run-command: introduce CHILD_PROCESS_INIT 2014-08-20 09:53:37 -07:00
verify-tag.c
write-tree.c