]> git.ipfire.org Git - thirdparty/git.git/commit - sha1-file.c
write_sha1_file: freshen existing objects
authorJeff King <peff@peff.net>
Wed, 15 Oct 2014 22:42:22 +0000 (18:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Oct 2014 17:10:43 +0000 (10:10 -0700)
commit33d4221c79c89844bed6b9558cc2bc497251ef70
treeb4a7b668169de14ba0d6033d299d97cb8df1b823
parentabcb86553d3ec4afffa4e3963089dffe0559740e
write_sha1_file: freshen existing objects

When we try to write a loose object file, we first check
whether that object already exists. If so, we skip the
write as an optimization. However, this can interfere with
prune's strategy of using mtimes to mark files in progress.

For example, if a branch contains a particular tree object
and is deleted, that tree object may become unreachable, and
have an old mtime. If a new operation then tries to write
the same tree, this ends up as a noop; we notice we
already have the object and do nothing. A prune running
simultaneously with this operation will see the object as
old, and may delete it.

We can solve this by "freshening" objects that we avoid
writing by updating their mtime. The algorithm for doing so
is essentially the same as that of has_sha1_file. Therefore
we provide a new (static) interface "check_and_freshen",
which finds and optionally freshens the object. It's trivial
to implement freshening and simple checking by tweaking a
single parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c
t/t6501-freshen-objects.sh