diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-11-17 20:05:52 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-11-18 15:08:12 -0800 |
commit | e38e680a4fe37dbf678a0c943d68e233346beacf (patch) | |
tree | 6250499d1889e665c6f60ba50faab195fc2275ad | |
parent | e3826385d2b05abb4c0f7e3de248ee6b4010ea3b (diff) | |
download | git-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>
-rw-r--r-- | cache-tree.c | 8 | ||||
-rw-r--r-- | cache-tree.h | 1 |
2 files changed, 7 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; diff --git a/cache-tree.h b/cache-tree.h index f18789ceff..7e03620349 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -39,6 +39,7 @@ int update_main_cache_tree(int); #define WRITE_TREE_DRY_RUN 4 #define WRITE_TREE_SILENT 8 #define WRITE_TREE_REPAIR 16 +#define WRITE_TREE_TOPLEVEL 32 /* error return codes */ #define WRITE_TREE_UNREADABLE_INDEX (-1) |