* [PATCH v5 1/4] cache-tree: Create/update cache-tree on checkout @ 2014-07-08 0:33 David Turner 2014-07-08 0:33 ` [PATCH v5 2/4] test-dump-cache-tree: invalid trees are not errors David Turner ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: David Turner @ 2014-07-08 0:33 UTC (permalink / raw) To: git; +Cc: David Turner 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> --- builtin/checkout.c | 8 ++++++++ cache-tree.c | 12 +++++++++++- cache-tree.h | 1 + t/t0090-cache-tree.sh | 19 ++++++++++++++++--- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 07cf555..054214f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -553,6 +553,14 @@ static int merge_working_tree(const struct checkout_opts *opts, } } + if (!active_cache_tree) + active_cache_tree = cache_tree(); + + if (!cache_tree_fully_valid(active_cache_tree)) + cache_tree_update(active_cache_tree, + (const struct cache_entry * const *)active_cache, + active_nr, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); + if (write_cache(newfd, active_cache, active_nr) || commit_locked_index(lock_file)) die(_("unable to write new index file")); diff --git a/cache-tree.c b/cache-tree.c index 7fa524a..f951d7d 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); diff --git a/cache-tree.h b/cache-tree.h index f1923ad..666d18f 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -39,6 +39,7 @@ int update_main_cache_tree(int); #define WRITE_TREE_IGNORE_CACHE_TREE 2 #define WRITE_TREE_DRY_RUN 4 #define WRITE_TREE_SILENT 8 +#define WRITE_TREE_REPAIR 16 /* error return codes */ #define WRITE_TREE_UNREADABLE_INDEX (-1) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 6c33e28..98fb1ab 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -44,14 +44,14 @@ test_expect_success 'read-tree HEAD establishes cache-tree' ' test_expect_success 'git-add invalidates cache-tree' ' test_when_finished "git reset --hard; git read-tree HEAD" && - echo "I changed this file" > foo && + echo "I changed this file" >foo && git add foo && test_invalid_cache_tree ' test_expect_success 'update-index invalidates cache-tree' ' test_when_finished "git reset --hard; git read-tree HEAD" && - echo "I changed this file" > foo && + echo "I changed this file" >foo && git update-index --add foo && test_invalid_cache_tree ' @@ -85,9 +85,22 @@ test_expect_success 'reset --hard without index gives cache-tree' ' test_shallow_cache_tree ' -test_expect_failure 'checkout gives cache-tree' ' +test_expect_success 'checkout gives cache-tree' ' + git tag current && git checkout HEAD^ && test_shallow_cache_tree ' +test_expect_success 'checkout -b gives cache-tree' ' + git checkout current && + git checkout -b prev HEAD^ && + test_shallow_cache_tree +' + +test_expect_success 'checkout -B gives cache-tree' ' + git checkout current && + git checkout -B prev HEAD^ && + test_shallow_cache_tree +' + test_done -- 2.0.0.390.gcb682f8 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/4] test-dump-cache-tree: invalid trees are not errors 2014-07-08 0:33 [PATCH v5 1/4] cache-tree: Create/update cache-tree on checkout David Turner @ 2014-07-08 0:33 ` David Turner 2014-07-08 0:33 ` [PATCH v5 3/4] cache-tree: subdirectory tests David Turner 2014-07-08 0:33 ` [PATCH v5 4/4] cache-tree: Write updated cache-tree after commit David Turner 2 siblings, 0 replies; 6+ messages in thread From: David Turner @ 2014-07-08 0:33 UTC (permalink / raw) To: git; +Cc: David Turner Do not treat known-invalid trees as errors even when their subtree_nr is incorrect. Because git already knows that these trees are invalid, an incorrect subtree_nr will not cause problems. Add a couple of comments. Signed-off-by: David Turner <dturner@twitter.com> --- test-dump-cache-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-dump-cache-tree.c b/test-dump-cache-tree.c index 47eab97..cbbbd8e 100644 --- a/test-dump-cache-tree.c +++ b/test-dump-cache-tree.c @@ -26,16 +26,16 @@ static int dump_cache_tree(struct cache_tree *it, return 0; if (it->entry_count < 0) { + /* invalid */ dump_one(it, pfx, ""); dump_one(ref, pfx, "#(ref) "); - if (it->subtree_nr != ref->subtree_nr) - errs = 1; } else { dump_one(it, pfx, ""); if (hashcmp(it->sha1, ref->sha1) || ref->entry_count != it->entry_count || ref->subtree_nr != it->subtree_nr) { + /* claims to be valid but is lying */ dump_one(ref, pfx, "#(ref) "); errs = 1; } -- 2.0.0.390.gcb682f8 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 3/4] cache-tree: subdirectory tests 2014-07-08 0:33 [PATCH v5 1/4] cache-tree: Create/update cache-tree on checkout David Turner 2014-07-08 0:33 ` [PATCH v5 2/4] test-dump-cache-tree: invalid trees are not errors David Turner @ 2014-07-08 0:33 ` David Turner 2014-07-08 17:38 ` Junio C Hamano 2014-07-08 0:33 ` [PATCH v5 4/4] cache-tree: Write updated cache-tree after commit David Turner 2 siblings, 1 reply; 6+ messages in thread From: David Turner @ 2014-07-08 0:33 UTC (permalink / raw) To: git; +Cc: David Turner Add tests to confirm that invalidation of subdirectories neither over- nor under-invalidates. Signed-off-by: David Turner <dturner@twitter.com> --- t/t0090-cache-tree.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 98fb1ab..496c034 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -22,9 +22,10 @@ test_shallow_cache_tree () { } test_invalid_cache_tree () { - echo "invalid (0 subtrees)" >expect && - printf "SHA #(ref) (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >>expect && - cmp_cache_tree expect + printf "invalid %s ()\n" "" "$@" >expect && + test-dump-cache-tree | \ + sed -n -e "s/$_x40/SHA/" -e "s/[0-9]* subtrees//g" -e '/#(ref)/d' -e '/^invalid /p' >actual && + test_cmp expect actual } test_no_cache_tree () { @@ -49,6 +50,25 @@ test_expect_success 'git-add invalidates cache-tree' ' test_invalid_cache_tree ' +test_expect_success 'git-add in subdir invalidates cache-tree' ' + test_when_finished "git reset --hard; git read-tree HEAD" && + mkdir dirx && + echo "I changed this file" >dirx/foo && + git add dirx/foo && + test_invalid_cache_tree +' + +test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' + git tag no-children && + test_when_finished "git reset --hard no-children; git read-tree HEAD" && + mkdir dir1 dir2 && + test_commit dir1/a && + test_commit dir2/b && + echo "I changed this file" >dir1/a && + git add dir1/a && + test_invalid_cache_tree dir1/ +' + test_expect_success 'update-index invalidates cache-tree' ' test_when_finished "git reset --hard; git read-tree HEAD" && echo "I changed this file" >foo && -- 2.0.0.390.gcb682f8 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 3/4] cache-tree: subdirectory tests 2014-07-08 0:33 ` [PATCH v5 3/4] cache-tree: subdirectory tests David Turner @ 2014-07-08 17:38 ` Junio C Hamano 0 siblings, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2014-07-08 17:38 UTC (permalink / raw) To: David Turner; +Cc: git, David Turner David Turner <dturner@twopensource.com> writes: > + printf "invalid %s ()\n" "" "$@" >expect && > + test-dump-cache-tree | \ > + sed -n -e "s/$_x40/SHA/" -e "s/[0-9]* subtrees//g" -e '/#(ref)/d' -e '/^invalid /p' >actual && You only show lines that begin with "invalid ". Does the first "redact any object name to S H A" matter? Also do more than one "N subtrees" appear on an output line? > + test_cmp expect actual > } > > test_no_cache_tree () { > @@ -49,6 +50,25 @@ test_expect_success 'git-add invalidates cache-tree' ' > test_invalid_cache_tree > ' > > +test_expect_success 'git-add in subdir invalidates cache-tree' ' > + test_when_finished "git reset --hard; git read-tree HEAD" && > + mkdir dirx && > + echo "I changed this file" >dirx/foo && > + git add dirx/foo && > + test_invalid_cache_tree > +' > + > +test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' > + git tag no-children && > + test_when_finished "git reset --hard no-children; git read-tree HEAD" && > + mkdir dir1 dir2 && > + test_commit dir1/a && > + test_commit dir2/b && > + echo "I changed this file" >dir1/a && > + git add dir1/a && > + test_invalid_cache_tree dir1/ > +' > + > test_expect_success 'update-index invalidates cache-tree' ' > test_when_finished "git reset --hard; git read-tree HEAD" && > echo "I changed this file" >foo && ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 4/4] cache-tree: Write updated cache-tree after commit 2014-07-08 0:33 [PATCH v5 1/4] cache-tree: Create/update cache-tree on checkout David Turner 2014-07-08 0:33 ` [PATCH v5 2/4] test-dump-cache-tree: invalid trees are not errors David Turner 2014-07-08 0:33 ` [PATCH v5 3/4] cache-tree: subdirectory tests David Turner @ 2014-07-08 0:33 ` David Turner 2014-07-08 17:55 ` Junio C Hamano 2 siblings, 1 reply; 6+ messages in thread From: David Turner @ 2014-07-08 0:33 UTC (permalink / raw) To: git; +Cc: David Turner During the commit process, update the cache-tree. Write this updated cache-tree so that it's ready for subsequent commands. Add test code which demonstrates that git commit now writes the cache tree. Make all tests test the entire cache-tree, not just the root level. Signed-off-by: David Turner <dturner@twitter.com> --- builtin/commit.c | 9 +++++- t/t0090-cache-tree.sh | 79 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 9cfef6c..99c9054 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -342,6 +342,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, discard_cache(); read_cache_from(index_lock.filename); + if (update_main_cache_tree(WRITE_TREE_SILENT) >= 0) + write_cache(fd, active_cache, active_nr); commit_style = COMMIT_NORMAL; return index_lock.filename; @@ -383,8 +385,12 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, if (!only && !pathspec.nr) { fd = hold_locked_index(&index_lock, 1); refresh_cache_or_die(refresh_flags); - if (active_cache_changed) { + if (active_cache_changed + || !cache_tree_fully_valid(active_cache_tree)) { update_main_cache_tree(WRITE_TREE_SILENT); + active_cache_changed = 1; + } + if (active_cache_changed) { if (write_cache(fd, active_cache, active_nr) || commit_locked_index(&index_lock)) die(_("unable to write new_index file")); @@ -435,6 +441,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, fd = hold_locked_index(&index_lock, 1); add_remove_files(&partial); refresh_cache(REFRESH_QUIET); + update_main_cache_tree(WRITE_TREE_SILENT); if (write_cache(fd, active_cache, active_nr) || close_lock_file(&index_lock)) die(_("unable to write new_index file")); diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 496c034..8c89689 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -8,7 +8,7 @@ cache-tree extension. . ./test-lib.sh cmp_cache_tree () { - test-dump-cache-tree >actual && + test-dump-cache-tree | sed -e '/#(ref)/d' >actual && sed "s/$_x40/SHA/" <actual >filtered && test_cmp "$1" filtered } @@ -16,8 +16,26 @@ cmp_cache_tree () { # We don't bother with actually checking the SHA1: # test-dump-cache-tree already verifies that all existing data is # correct. -test_shallow_cache_tree () { - printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect && +generate_expected_cache_tree () { + dir="$1${1:+/}" && + parent="$2" && + # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux + # We want to count only foo because it's the only direct child + subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && + subtree_count=$(echo "$subtrees"|awk '$1 {++c} END {print c}') && + entries=$(git ls-files|wc -l) && + printf "SHA $dir (%d entries, %d subtrees)\n" $entries $subtree_count && + for subtree in $subtrees + do + cd "$subtree" + generate_expected_cache_tree "$dir$subtree" $dir || return 1 + cd .. + done && + dir=$parent +} + +test_cache_tree () { + generate_expected_cache_tree >expect && cmp_cache_tree expect } @@ -33,14 +51,14 @@ test_no_cache_tree () { cmp_cache_tree expect } -test_expect_failure 'initial commit has cache-tree' ' +test_expect_success 'initial commit has cache-tree' ' test_commit foo && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'read-tree HEAD establishes cache-tree' ' git read-tree HEAD && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'git-add invalidates cache-tree' ' @@ -58,6 +76,18 @@ test_expect_success 'git-add in subdir invalidates cache-tree' ' test_invalid_cache_tree ' +cat >before <<\EOF +SHA (3 entries, 2 subtrees) +SHA dir1/ (1 entries, 0 subtrees) +SHA dir2/ (1 entries, 0 subtrees) +EOF + +cat >expect <<\EOF +invalid (2 subtrees) +invalid dir1/ (0 subtrees) +SHA dir2/ (1 entries, 0 subtrees) +EOF + test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' git tag no-children && test_when_finished "git reset --hard no-children; git read-tree HEAD" && @@ -65,8 +95,10 @@ test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' test_commit dir1/a && test_commit dir2/b && echo "I changed this file" >dir1/a && + cmp_cache_tree before && + echo "I changed this file" >dir1/a && git add dir1/a && - test_invalid_cache_tree dir1/ + cmp_cache_tree expect ' test_expect_success 'update-index invalidates cache-tree' ' @@ -79,7 +111,7 @@ test_expect_success 'update-index invalidates cache-tree' ' test_expect_success 'write-tree establishes cache-tree' ' test-scrap-cache-tree && git write-tree && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'test-scrap-cache-tree works' ' @@ -90,37 +122,56 @@ test_expect_success 'test-scrap-cache-tree works' ' test_expect_success 'second commit has cache-tree' ' test_commit bar && - test_shallow_cache_tree + test_cache_tree +' + +test_expect_success 'commit in child dir has cache-tree' ' + mkdir dir && + >dir/child.t && + git add dir/child.t && + git commit -m dir/child.t && + test_cache_tree ' test_expect_success 'reset --hard gives cache-tree' ' test-scrap-cache-tree && git reset --hard && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'reset --hard without index gives cache-tree' ' rm -f .git/index && git reset --hard && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'checkout gives cache-tree' ' git tag current && git checkout HEAD^ && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'checkout -b gives cache-tree' ' git checkout current && git checkout -b prev HEAD^ && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'checkout -B gives cache-tree' ' git checkout current && git checkout -B prev HEAD^ && - test_shallow_cache_tree + test_cache_tree +' + +test_expect_success 'partial commit gives cache-tree' ' + git checkout -b partial no-children && + test_commit one && + test_commit two && + echo "some change" >one.t && + git add one.t && + echo "some other change" >two.t && + git commit two.t -m partial && + test_cache_tree ' test_done -- 2.0.0.390.gcb682f8 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 4/4] cache-tree: Write updated cache-tree after commit 2014-07-08 0:33 ` [PATCH v5 4/4] cache-tree: Write updated cache-tree after commit David Turner @ 2014-07-08 17:55 ` Junio C Hamano 0 siblings, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2014-07-08 17:55 UTC (permalink / raw) To: David Turner; +Cc: git, David Turner David Turner <dturner@twopensource.com> writes: > @@ -16,8 +16,26 @@ cmp_cache_tree () { > # We don't bother with actually checking the SHA1: > # test-dump-cache-tree already verifies that all existing data is > # correct. > -test_shallow_cache_tree () { > - printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect && > +generate_expected_cache_tree () { > + dir="$1${1:+/}" && > + parent="$2" && > + # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux > + # We want to count only foo because it's the only direct child > + subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && > + subtree_count=$(echo "$subtrees"|awk '$1 {++c} END {print c}') && > + entries=$(git ls-files|wc -l) && > + printf "SHA $dir (%d entries, %d subtrees)\n" $entries $subtree_count && > + for subtree in $subtrees > + do > + cd "$subtree" > + generate_expected_cache_tree "$dir$subtree" $dir || return 1 > + cd .. If the || return 1 ever triggers, would the main test process end up in an unexpected place? A test piece executes test_cache_tree whose control eventually reaches here and returns failure; the next test piece will start at a wrong directory, no? > + done && > + dir=$parent > +} > + > +test_cache_tree () { > + generate_expected_cache_tree >expect && > cmp_cache_tree expect > } > > @@ -33,14 +51,14 @@ test_no_cache_tree () { > cmp_cache_tree expect > } > > -test_expect_failure 'initial commit has cache-tree' ' > +test_expect_success 'initial commit has cache-tree' ' > test_commit foo && > - test_shallow_cache_tree > + test_cache_tree > ' > > test_expect_success 'read-tree HEAD establishes cache-tree' ' > git read-tree HEAD && > - test_shallow_cache_tree > + test_cache_tree > ' ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-07-08 17:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-07-08 0:33 [PATCH v5 1/4] cache-tree: Create/update cache-tree on checkout David Turner 2014-07-08 0:33 ` [PATCH v5 2/4] test-dump-cache-tree: invalid trees are not errors David Turner 2014-07-08 0:33 ` [PATCH v5 3/4] cache-tree: subdirectory tests David Turner 2014-07-08 17:38 ` Junio C Hamano 2014-07-08 0:33 ` [PATCH v5 4/4] cache-tree: Write updated cache-tree after commit David Turner 2014-07-08 17:55 ` Junio C Hamano
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).