summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-11-17 20:05:52 -0800
committerJunio C Hamano <gitster@pobox.com>2016-11-18 15:08:12 -0800
commite38e680a4fe37dbf678a0c943d68e233346beacf (patch)
tree6250499d1889e665c6f60ba50faab195fc2275ad /cache-tree.c
parente3826385d2b05abb4c0f7e3de248ee6b4010ea3b (diff)
downloadgit-jc/cache-tree-wip.tar.gz
cache-tree: freshen the tree object at the top leveljc/cache-tree-wip
"git write-tree" that is asked to write out a tree object out of the index may not actually write the tree object anew, when there already is the same tree object in the object store. The actual writing of the tree object is done as a side effect of updating the cache tree entries fully in the index, and the optimization to skip writing the tree out is done via "has_sha1_file()", i.e. "does the tree already exist in the object store?" After asking "git write-tree" to write a tree out, the caller may not make it reachable from any ref or other anchoring point, which makes the tree object subject to pruning. Call freshen_object() on the top-level tree object to make sure we mark the tree "young" to protect it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/cache-tree.c b/cache-tree.c
index 2fc7730df6..12dcf0b036 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -232,14 +232,17 @@ static int update_one(struct cache_tree *it,
int missing_ok = flags & WRITE_TREE_MISSING_OK;
int dryrun = flags & WRITE_TREE_DRY_RUN;
int repair = flags & WRITE_TREE_REPAIR;
+ int toplevel = flags & WRITE_TREE_TOPLEVEL;
int to_invalidate = 0;
int i;
assert(!(dryrun && repair));
+ flags &= ~WRITE_TREE_TOPLEVEL;
*skip_count = 0;
- if (0 <= it->entry_count && has_sha1_file(it->sha1))
+ if (0 <= it->entry_count &&
+ (toplevel ? freshen_object : has_sha1_file)(it->sha1))
return it->entry_count;
/*
@@ -409,7 +412,8 @@ int cache_tree_update(struct index_state *istate, int flags)
if (i)
return i;
- i = update_one(it, cache, entries, "", 0, &skip, flags);
+ i = update_one(it, cache, entries, "", 0, &skip,
+ flags | WRITE_TREE_TOPLEVEL);
if (i < 0)
return i;
istate->cache_changed |= CACHE_TREE_CHANGED;