aboutsummaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2014-07-05 21:06:56 -0700
committerJunio C Hamano <gitster@pobox.com>2014-07-07 12:30:34 -0700
commitaecf567cbfb6ab46e82f7f5df36fb6a2dd5bee69 (patch)
treebb7e31b4b9ebe4adb3a78a9f2012815658b17ca3 /cache-tree.c
parentc2f7b1026e33e308782fcb1b60e3d7af107fdc18 (diff)
downloadgit-aecf567cbfb6ab46e82f7f5df36fb6a2dd5bee69.tar.gz
git-aecf567cbfb6ab46e82f7f5df36fb6a2dd5bee69.tar.xz
cache-tree: create/update cache-tree on checkout
When git checkout checks out a branch, create or update the cache-tree so that subsequent operations are faster. update_main_cache_tree learned a new flag, WRITE_TREE_REPAIR. When WRITE_TREE_REPAIR is set, portions of the cache-tree which do not correspond to existing tree objects are invalidated (and portions which do are marked as valid). No new tree objects are created. Signed-off-by: David Turner <dturner@twitter.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/cache-tree.c b/cache-tree.c
index 7fa524a11..f951d7d3c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,9 +239,12 @@ static int update_one(struct cache_tree *it,
struct strbuf buffer;
int missing_ok = flags & WRITE_TREE_MISSING_OK;
int dryrun = flags & WRITE_TREE_DRY_RUN;
+ int repair = flags & WRITE_TREE_REPAIR;
int to_invalidate = 0;
int i;
+ assert(!(dryrun && repair));
+
*skip_count = 0;
if (0 <= it->entry_count && has_sha1_file(it->sha1))
@@ -374,7 +377,14 @@ static int update_one(struct cache_tree *it,
#endif
}
- if (dryrun)
+ if (repair) {
+ unsigned char sha1[20];
+ hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
+ if (has_sha1_file(sha1))
+ hashcpy(it->sha1, sha1);
+ else
+ to_invalidate = 1;
+ } else if (dryrun)
hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1);
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) {
strbuf_release(&buffer);