More index cleanups
cover More index cleanups
This is based on ds/cache-tree-basics.
Here are a few more cleanups that are vaguely related to the index. I discovered these while preparing my sparse-index RFC that I intend to send early next week.
The biggest patch is the final one, which creates a test script for comparing sparse-checkouts to full checkouts. There are some commands that do not behave similarly. This script will be the backbone of my testing strategy for the sparse-index by adding a new mode to compare sparse-checkouts with the two index types (full and sparse).
Thanks, -Stolee
Derrick Stolee (9):
cache-tree: clean up cache_tree_update()
cache-tree: extract subtree_pos()
fsmonitor: de-duplicate BUG()s around dirty bits
repository: add repo reference to index_state
name-hash: use trace2 regions for init
sparse-checkout: load sparse-checkout patterns
sparse-checkout: hold pattern list in index
test-lib: test_region looks for trace2 regions
t1092: test interesting sparse-checkout scenarios
builtin/sparse-checkout.c | 22 +- cache-tree.c | 20 +- cache-tree.h | 2 + cache.h | 3 + dir.c | 17 ++ dir.h | 2 + fsmonitor.c | 27 +- name-hash.c | 3 + repository.c | 4 + t/t0500-progress-display.sh | 3 +- t/t1092-sparse-checkout-compatibility.sh | 323 +++++++++++++++++++++++ t/test-lib-functions.sh | 40 +++ unpack-trees.c | 6 +- 13 files changed, 431 insertions(+), 41 deletions(-) create mode 100755 t/t1092-sparse-checkout-compatibility.sh
base-commit: a4b6d202caad83c6dc29abe9b17e53a1b3fb54a0
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-839%2Fderrickstolee%2Fmore-index-cleanups-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-839/derrickstolee/more-index-cleanups-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/839
Signature · 1 line
gitgitgadget
PATCH 1/9 cache-tree: clean up cache_tree_update()
From: Derrick Stolee <[email protected]>
Make the method safer by allocating a cache_tree member for the given index_state if it is not already present.
Also drop local variables that are used exactly once and can be found directly from the 'istate' parameter.
--- cache-tree.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
cache-tree.c +9 -5
@@ -436,16 +436,20 @@ static int update_one(struct cache_tree *it,int cache_tree_update (struct index_state *istate,int flags) { -struct cache_tree *it = istate->cache_tree; -struct cache_entry **cache = istate->cache; -int entries = istate->cache_nr; -int skip, i =verify_cache (cache, entries, flags); +int skip, i; + + i =verify_cache (istate->cache, istate->cache_nr, flags);if (i)return i; + +if (!istate->cache_tree) + istate->cache_tree =cache_tree (); +trace_performance_enter ();trace2_region_enter ("cache_tree" ,"update" , the_repository); - i =update_one (it, cache, entries,"" ,0 , &skip, flags); + i =update_one (istate->cache_tree, istate->cache, istate->cache_nr, +"" ,0 , &skip, flags);trace2_region_leave ("cache_tree" ,"update" , the_repository);trace_performance_leave ("cache_tree_update" );if (i <0 )
Signature · 1 line
gitgitgadget
Re: [PATCH 1/9] cache-tree: clean up cache_tree_update()
Quoted 19 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Make the method safer by allocating a
cache_treemember for the givenindex_stateif it is not already present.Also drop local variables that are used exactly once and can be found directly from the 'istate' parameter.
Signed-off-by Derrick Stolee <[email protected]>--- cache-tree.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)cache-tree.c +0
-0
cache-tree.c static int update_one(struct cache_tree *it, · line 441
Quoted 10 lines
cache-tree.c +3
-4@@ -436,16 +436,20 @@ static int update_one(struct cache_tree *it,int cache_tree_update (struct index_state *istate,int flags) { -struct cache_tree *it = istate->cache_tree; -struct cache_entry **cache = istate->cache; -int entries = istate->cache_nr; -int skip, i =verify_cache (cache, entries, flags); +int skip, i; + + i =verify_cache (istate->cache, istate->cache_nr, flags);
All mechanical changes so far; these look obviously correct.
cache-tree.c static int update_one(struct cache_tree *it, · line 447
Quoted 6 lines
cache-tree.c +3
-0if (i)return i; + +if (!istate->cache_tree) + istate->cache_tree =cache_tree ();
This is the only substantive change. It seems fairly innocuous, but it makes me wonder the reasoning...I don't know/remember enough about cache_tree handling to know when this would or wouldn't have already been allocated. It seems that this would have had to segfault below if istate->cache_tree were ever NULL, and I don't see you mentioning any bug you are fixing, so I presume this means you are going to be adding new codepaths somewhere that cause this function to be reached under different circumstances than previously had been and you need it to be more safe for those. Is that correct? Or is it just an abundance of caution thing that you're adding? If the latter, any reason you chose to allocate one rather than assume it's a violation of design invariants and BUG() instead? (Perhaps the commit message could add a sentence about the rationale for the extra safety?)
cache-tree.c static int update_one(struct cache_tree *it, · line 452
Quoted 6 lines
cache-tree.c +3
-1+trace_performance_enter ();trace2_region_enter ("cache_tree" ,"update" , the_repository); - i =update_one (it, cache, entries,"" ,0 , &skip, flags); + i =update_one (istate->cache_tree, istate->cache, istate->cache_nr, +"" ,0 , &skip, flags);
Another mechanical update; looks good.
Quoted 5 lines
cache-tree.c +0
-1trace2_region_leave ("cache_tree" ,"update" , the_repository);trace_performance_leave ("cache_tree_update" );if (i <0 ) --gitgitgadget
Re: [PATCH 1/9] cache-tree: clean up cache_tree_update()
Quoted 6 lines · Elijah Newren
On Wed, Jan 20, 2021 at 8:54 AM Derrick Stolee via GitGitGadget <[email protected]> wrote:...
cache-tree.c static int update_one(struct cache_tree *it, · line 447
Quoted 3 lines
cache-tree.c +3
-0+ +if (!istate->cache_tree) + istate->cache_tree =cache_tree ();
Quoted 13 lines
This is the only substantive change. It seems fairly innocuous, but it makes me wonder the reasoning...I don't know/remember enough about
cache_treehandling to know when this would or wouldn't have already been allocated. It seems that this would have had to segfault below ifistate->cache_treewere ever NULL, and I don't see you mentioning any bug you are fixing, so I presume this means you are going to be adding new codepaths somewhere that cause this function to be reached under different circumstances than previously had been and you need it to be more safe for those. Is that correct? Or is it just an abundance of caution thing that you're adding? If the latter, any reason you chose to allocate one rather than assume it's a violation of design invariants andBUG()instead? (Perhaps the commit message could add a sentence about the rationale for the extra safety?)
It's something I need in the future when I use the cache_tree_update() in more places. I think I call it two times, and either I need to initialize the cache_tree member outside of both, or just make it a feature of the method that it will re-initialize the cache-tree.
Note: the implementation treats an initialized, but empty cache-tree as "invalid" so update_one() correctly populates the full tree.
Thanks,
-Stolee
PATCH 2/9 cache-tree: extract subtree_pos()
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
This method will be helpful to use outside of cache-tree.c in a later feature. The implementation is subtle due to subtree_name_cmp() sorting by length and then lexicographically.
--- cache-tree.c | 6 +++--- cache-tree.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
cache-tree.c +3 -3
@@ -45,7 +45,7 @@ static int subtree_name_cmp(const char *one, int onelen,return memcmp (one, two, onelen); } -static int subtree_pos (struct cache_tree *it,const char *path,int pathlen) +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen) {struct cache_tree_sub **down = it->down;int lo, hi;
@@ -72,7 +72,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it, int create) {struct cache_tree_sub *down; -int pos =subtree_pos (it, path, pathlen); +int pos =cache_tree_subtree_pos (it, path, pathlen);if (0 <= pos)return it->down[pos];if (!create)
@@ -123,7 +123,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path) it->entry_count =-1 ;if (!*slash) {int pos; - pos =subtree_pos (it, path, namelen); + pos =cache_tree_subtree_pos (it, path, namelen);if (0 <= pos) {cache_tree_free (&it->down[pos]->cache_tree);free (it->down[pos]);
cache-tree.h +2 -0
@@ -27,6 +27,8 @@ void cache_tree_free(struct cache_tree **);void cache_tree_invalidate_path (struct index_state *,const char *);struct cache_tree_sub *cache_tree_sub (struct cache_tree *,const char *); +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen); +void cache_tree_write (struct strbuf *,struct cache_tree *root);struct cache_tree *cache_tree_read (const char *buffer,unsigned long size);
Signature · 1 line
gitgitgadget
Re: [PATCH 2/9] cache-tree: extract subtree_pos()
Quoted 58 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
This method will be helpful to use outside of
cache-tree.cin a later feature. The implementation is subtle due tosubtree_name_cmp()sorting by length and then lexicographically.Signed-off-by Derrick Stolee <[email protected]>--- cache-tree.c | 6 +++--- cache-tree.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)cache-tree.c +3
-3@@ -45,7 +45,7 @@ static int subtree_name_cmp(const char *one, int onelen,return memcmp (one, two, onelen); } -static int subtree_pos (struct cache_tree *it,const char *path,int pathlen) +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen) {struct cache_tree_sub **down = it->down;int lo, hi;@@ -72,7 +72,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it, int create) {struct cache_tree_sub *down; -int pos =subtree_pos (it, path, pathlen); +int pos =cache_tree_subtree_pos (it, path, pathlen);if (0 <= pos)return it->down[pos];if (!create)@@ -123,7 +123,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path) it->entry_count =-1 ;if (!*slash) {int pos; - pos =subtree_pos (it, path, namelen); + pos =cache_tree_subtree_pos (it, path, namelen);if (0 <= pos) {cache_tree_free (&it->down[pos]->cache_tree);free (it->down[pos]);cache-tree.h +2
-1@@ -27,6 +27,8 @@ void cache_tree_free(struct cache_tree **);void cache_tree_invalidate_path (struct index_state *,const char *);struct cache_tree_sub *cache_tree_sub (struct cache_tree *,const char *); +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen); +void cache_tree_write (struct strbuf *,struct cache_tree *root);struct cache_tree *cache_tree_read (const char *buffer,unsigned long size); --
Quoted 1 line
gitgitgadget
Simple, straight-forward patch for exposing the function outside the file scope; looks good.
PATCH 3/9 fsmonitor: de-duplicate BUG()s around dirty bits
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The index has an fsmonitor_dirty bitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
There are several BUG() statements that are very similar, so replace these uses with a simpler assert_index_minimum(). Since there is one caller that uses a custom 'pos' value instead of the bit_size member, we cannot simplify it too much. However, the error string is identical in each, so this simplifies things.
The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.
--- fsmonitor.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
fsmonitor.c +13 -14
@@ -13,14 +13,19 @@struct trace_key trace_fsmonitor =TRACE_KEY_INIT (FSMONITOR ); +static void assert_index_minimum (struct index_state *istate,size_t pos) +{ +if (pos > istate->cache_nr) +BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , + (uintmax_t )pos, istate->cache_nr); +} +static void fsmonitor_ewah_callback (size_t pos,void *is) {struct index_state *istate = (struct index_state *)is;struct cache_entry *ce; -if (pos >= istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" >= %u)" , - (uintmax_t )pos, istate->cache_nr); +assert_index_minimum (istate, pos); ce = istate->cache[pos]; ce->ce_flags &= ~CE_FSMONITOR_VALID ;
@@ -82,10 +87,8 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, } istate->fsmonitor_dirty = fsmonitor_dirty; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);trace_printf_key (&trace_fsmonitor,"read fsmonitor extension successful" );return 0 ;
@@ -110,10 +113,8 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)uint32_t ewah_size =0 ;int fixup =0 ; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);put_be32 (&hdr_version,INDEX_EXTENSION_VERSION2 );strbuf_add (sb, &hdr_version,sizeof (uint32_t ));
@@ -335,9 +336,7 @@ void tweak_fsmonitor(struct index_state *istate) }/* Mark all previously saved entries as dirty */ -if (istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);ewah_each_bit (istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);refresh_fsmonitor (istate);
Signature · 1 line
gitgitgadget
Re: [PATCH 3/9] fsmonitor: de-duplicate BUG()s around dirty bits
Quoted 8 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
The index has an
fsmonitor_dirtybitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
Quoted 8 lines
There are several
BUG()statements that are very similar, so replace these uses with a simplerassert_index_minimum(). Since there is one caller that uses a custom 'pos' value instead of thebit_sizemember, we cannot simplify it too much. However, the error string is identical in each, so this simplifies things.The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.
Indeed, looking through the patch, the end result is simpler to read. Nice cleanup.
Quoted 73 lines
Signed-off-by Derrick Stolee <[email protected]>--- fsmonitor.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)fsmonitor.c +13
-15@@ -13,14 +13,19 @@struct trace_key trace_fsmonitor =TRACE_KEY_INIT (FSMONITOR ); +static void assert_index_minimum (struct index_state *istate,size_t pos) +{ +if (pos > istate->cache_nr) +BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , + (uintmax_t )pos, istate->cache_nr); +} +static void fsmonitor_ewah_callback (size_t pos,void *is) {struct index_state *istate = (struct index_state *)is;struct cache_entry *ce; -if (pos >= istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" >= %u)" , - (uintmax_t )pos, istate->cache_nr); +assert_index_minimum (istate, pos); ce = istate->cache[pos]; ce->ce_flags &= ~CE_FSMONITOR_VALID ;@@ -82,10 +87,8 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, } istate->fsmonitor_dirty = fsmonitor_dirty; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);trace_printf_key (&trace_fsmonitor,"read fsmonitor extension successful" );return 0 ;@@ -110,10 +113,8 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)uint32_t ewah_size =0 ;int fixup =0 ; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);put_be32 (&hdr_version,INDEX_EXTENSION_VERSION2 );strbuf_add (sb, &hdr_version,sizeof (uint32_t ));@@ -335,9 +336,7 @@ void tweak_fsmonitor(struct index_state *istate) }/* Mark all previously saved entries as dirty */ -if (istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);ewah_each_bit (istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);refresh_fsmonitor (istate); --gitgitgadget
Re: [PATCH 3/9] fsmonitor: de-duplicate BUG()s around dirty bits
In reply to Derrick Stolee via GitGitGadgetQuoted 7 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
The index has an
fsmonitor_dirtybitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
Curious: some of the tests were >=, some were > (not >=). Now that they're shared in a function they are all ">".
It's pretty clear that for size-based ones, greater-than is the right test, but for position ones, isn't it still greater-or-equal? So perhaps the calls that pass an actual position should add 1...
Chris
Re: [PATCH 3/9] fsmonitor: de-duplicate BUG()s around dirty bits
Quoted 10 lines · Chris Torek
Quoted 7 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
The index has an
fsmonitor_dirtybitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
Quoted 6 lines
Curious: some of the tests were >=, some were > (not >=). Now that they're shared in a function they are all ">".
It's pretty clear that for size-based ones, greater-than is the right test, but for position ones, isn't it still greater-or-equal? So perhaps the calls that pass an actual position should add 1...
That's a good point. I should pass "pos + 1" in the appropriate places.
Thanks,
-Stolee
PATCH 4/9 repository: add repo reference to index_state
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index opertations that might trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct index_state that allows access to this repository.
This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct index_state *istate' parameter.
--- cache.h | 1 + repository.c | 4 ++++ 2 files changed, 5 insertions(+)
cache.h +1 -0
@@ -328,6 +328,7 @@ struct index_state {struct ewah_bitmap *fsmonitor_dirty;struct mem_pool *ce_mem_pool;struct progress *progress; +struct repository *repo; };/* Name hashing */
repository.c +4 -0
@@ -264,6 +264,10 @@ int repo_read_index(struct repository *repo)if (!repo->index) repo->index =xcalloc (1 ,sizeof (*repo->index)); +/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +return read_index_from (repo->index, repo->index_file, repo->gitdir); }
Signature · 1 line
gitgitgadget
Re: [PATCH 4/9] repository: add repo reference to index_state
Quoted 4 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index opertations that might
s/opertations/operations/
Quoted 42 lines
trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct
index_statethat allows access to this repository.This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct
index_state*istate' parameter.Signed-off-by Derrick Stolee <[email protected]>--- cache.h | 1 + repository.c | 4 ++++ 2 files changed, 5 insertions(+)cache.h +1
-0@@ -328,6 +328,7 @@ struct index_state {struct ewah_bitmap *fsmonitor_dirty;struct mem_pool *ce_mem_pool;struct progress *progress; +struct repository *repo; };/* Name hashing */ repository.c +4
-1@@ -264,6 +264,10 @@ int repo_read_index(struct repository *repo)if (!repo->index) repo->index =xcalloc (1 ,sizeof (*repo->index)); +/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +return read_index_from (repo->index, repo->index_file, repo->gitdir); } --
Quoted 1 line
gitgitgadget
Since we have repo->index and we have index->repo, which are intended to be circular...what if they aren't? Do we want or need to add assertions anywhere that repo == repo->index->repo or that index == index->repo->index ?
My initial implementations of --remerge-diff[1] played around with creating a second repo, with a different primary object store but everything else the same. The index for the two repository objects was thus the same, and thus clearly would have violated this assumed invariant for one of the two repos. I discarded that initial implementation (which I didn't quite have working) because I discovered tmp-objdir.h and was able to add some tmp_objdir_make_primary() and tmp_objdir_remove_as_primary() functions that merely altered the existing repo's primary object store, but I'm curious if there might be other cases of folks doing stuff that might have weird failures with this new invariant.
It's entirely possible that --remerge-diff was just so different, and I was so unfamiliar with repo objects (and still kind of am) that I was just doing weird stuff no one has done before, so perhaps no additional checks are needed -- I'm just throwing my gut question out there as food for thought.
[1] I have not yet submitted --remerge-diff to the list; you haven't missed anything. I'm waiting for merge-ort to be submitted, reviewed, and merged first. It's the remerge-diff branch in my fork on GitHub if anyone is curious, though.
Re: [PATCH 4/9] repository: add repo reference to index_state
Quoted 8 lines · Elijah Newren
Quoted 4 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index opertations that might
s/opertations/operations/
Thanks.
Quoted 41 lines
Quoted 41 lines
trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct
index_statethat allows access to this repository.This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct
index_state*istate' parameter.Signed-off-by Derrick Stolee <[email protected]>--- cache.h | 1 + repository.c | 4 ++++ 2 files changed, 5 insertions(+)cache.h +1
-0@@ -328,6 +328,7 @@ struct index_state {struct ewah_bitmap *fsmonitor_dirty;struct mem_pool *ce_mem_pool;struct progress *progress; +struct repository *repo; };/* Name hashing */ repository.c +4
-0@@ -264,6 +264,10 @@ int repo_read_index(struct repository *repo)if (!repo->index) repo->index =xcalloc (1 ,sizeof (*repo->index)); +/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +return read_index_from (repo->index, repo->index_file, repo->gitdir); }
Quoted 7 lines
Quoted 2 lines
--
gitgitgadgetSince we have
repo->indexand we haveindex->repo, which are intended to be circular...what if they aren't? Do we want or need to add assertions anywhere that repo ==repo->index->repoor that index ==index->repo->index?
Here, we are pairing them together and the loop is complete. I don't view that as a permanent thing. This only initializes istate->repo when we are parsing an index from a file, but not when we create one in memory.
I imagine it will be likely in some cases to have multiple index_state instances for a single repository. However, having the pointer "this index belongs to this repository" seems helpful (to me).
Quoted 11 lines
My initial implementations of --remerge-diff[1] played around with creating a second repo, with a different primary object store but everything else the same. The index for the two repository objects was thus the same, and thus clearly would have violated this assumed invariant for one of the two repos. I discarded that initial implementation (which I didn't quite have working) because I discovered
tmp-objdir.hand was able to add sometmp_objdir_make_primary()andtmp_objdir_remove_as_primary()functions that merely altered the existing repo's primary object store, but I'm curious if there might be other cases of folks doing stuff that might have weird failures with this new invariant.
This is an interesting concept, and definitely violates my expectations that an index belongs to only one repository. I'd need to know more about why this was a good design decision before being convinced that the relationship should not be many-to-one (index-to-repo).
Quoted 10 lines
It's entirely possible that --remerge-diff was just so different, and I was so unfamiliar with repo objects (and still kind of am) that I was just doing weird stuff no one has done before, so perhaps no additional checks are needed -- I'm just throwing my gut question out there as food for thought.
[1] I have not yet submitted
--remerge-diffto the list; you haven't missed anything. I'm waiting for merge-ort to be submitted, reviewed, and merged first. It's the remerge-diff branch in my fork on GitHub if anyone is curious, though.
I'm interested in what others might say about this idea. I'd be able to do most of what I want to do without this patch, but it just gets a lot messier. (istate->repo is used in the very next patch in a way that would be less clean without it.)
Thanks,
-Stolee
Re: [PATCH 4/9] repository: add repo reference to index_state
Quoted 83 lines · Derrick Stolee
Quoted 8 lines · Elijah Newren
Quoted 4 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index opertations that might
s/opertations/operations/
Thanks.
Quoted 41 lines
Quoted 41 lines
trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct
index_statethat allows access to this repository.This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct
index_state*istate' parameter.Signed-off-by Derrick Stolee <[email protected]>--- cache.h | 1 + repository.c | 4 ++++ 2 files changed, 5 insertions(+)cache.h +1
-0@@ -328,6 +328,7 @@ struct index_state {struct ewah_bitmap *fsmonitor_dirty;struct mem_pool *ce_mem_pool;struct progress *progress; +struct repository *repo; };/* Name hashing */ repository.c +4
-0@@ -264,6 +264,10 @@ int repo_read_index(struct repository *repo)if (!repo->index) repo->index =xcalloc (1 ,sizeof (*repo->index)); +/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +return read_index_from (repo->index, repo->index_file, repo->gitdir); }Quoted 7 lines
Quoted 2 lines
--
gitgitgadgetSince we have
repo->indexand we haveindex->repo, which are intended to be circular...what if they aren't? Do we want or need to add assertions anywhere that repo ==repo->index->repoor that index ==index->repo->index?Here, we are pairing them together and the loop is complete. I don't view that as a permanent thing. This only initializes
istate->repowhen we are parsing an index from a file, but not when we create one in memory.I imagine it will be likely in some cases to have multiple
index_stateinstances for a single repository. However, having the pointer "this index belongs to this repository" seems helpful (to me).Quoted 11 lines
My initial implementations of --remerge-diff[1] played around with creating a second repo, with a different primary object store but everything else the same. The index for the two repository objects was thus the same, and thus clearly would have violated this assumed invariant for one of the two repos. I discarded that initial implementation (which I didn't quite have working) because I discovered
tmp-objdir.hand was able to add sometmp_objdir_make_primary()andtmp_objdir_remove_as_primary()functions that merely altered the existing repo's primary object store, but I'm curious if there might be other cases of folks doing stuff that might have weird failures with this new invariant.
Quoted 4 lines
This is an interesting concept, and definitely violates my expectations that an index belongs to only one repository. I'd need to know more about why this was a good design decision before being convinced that the relationship should not be many-to-one (index-to-repo).
I'm not sure what I did was a good design decision; I was kind of exploring and trying to figure things out. In retrospect, I think it was probably a bad idea. But we have various guard rails in the form of BUG() calls and such when basic assumptions are violated, and here it seems that you are now making a new basic assumption that an index belongs to only one repository. (Even if all current callers happen to satisfy that assumption, it's not clear to me that git previously cared if this condition were satisfied or not). Hence my question about safety checks.
Quoted 11 lines
Quoted 10 lines
It's entirely possible that --remerge-diff was just so different, and I was so unfamiliar with repo objects (and still kind of am) that I was just doing weird stuff no one has done before, so perhaps no additional checks are needed -- I'm just throwing my gut question out there as food for thought.
[1] I have not yet submitted
--remerge-diffto the list; you haven't missed anything. I'm waiting for merge-ort to be submitted, reviewed, and merged first. It's the remerge-diff branch in my fork on GitHub if anyone is curious, though.
Quoted 4 lines
I'm interested in what others might say about this idea. I'd be able to do most of what I want to do without this patch, but it just gets a lot messier. (
istate->repois used in the very next patch in a way that would be less clean without it.)
I'm less concerned with your patch as-is (I think your assumption seems reasonable and I'm fine with labelling my former unsubmitted patches as erroneous), and more wondering whether others in the future will accidentally violate assumptions your patch starts encoding...and whether we can or should do anything about it. If there's a simple place we can add a check for such an error, then it probably makes sense to add one. If there isn't...then at least we considered it?
PATCH 5/9 name-hash: use trace2 regions for init
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The lazy_init_name_hash() populates a hashset with all filenames and another with all directories represented in the index. This is run only if we need to use the hashsets to check for existence or case-folding renames.
Place trace2 regions where there is already a performance trace.
--- name-hash.c | 3 +++ 1 file changed, 3 insertions(+)
name-hash.c +3 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" #include "thread-utils.h" +#include "trace2.h" struct dir_entry {struct hashmap_entry ent;
@@ -577,6 +578,7 @@ static void lazy_init_name_hash(struct index_state *istate)if (istate->name_hash_initialized)return ;trace_performance_enter (); +trace2_region_enter ("index" ,"name-hash-init" , istate->repo);hashmap_init (&istate->name_hash, cache_entry_cmp,NULL , istate->cache_nr);hashmap_init (&istate->dir_hash, dir_entry_cmp,NULL , istate->cache_nr);
@@ -597,6 +599,7 @@ static void lazy_init_name_hash(struct index_state *istate) } istate->name_hash_initialized =1 ; +trace2_region_leave ("index" ,"name-hash-init" , istate->repo);trace_performance_leave ("initialize name hash" ); }
Signature · 1 line
gitgitgadget
Re: [PATCH 5/9] name-hash: use trace2 regions for init
Quoted 44 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
The
lazy_init_name_hash()populates a hashset with all filenames and another with all directories represented in the index. This is run only if we need to use the hashsets to check for existence or case-folding renames.Place trace2 regions where there is already a performance trace.
Signed-off-by Derrick Stolee <[email protected]>--- name-hash.c | 3 +++ 1 file changed, 3 insertions(+)name-hash.c +3
-1@@ -7,6 +7,7 @@*/ #include "cache.h" #include "thread-utils.h" +#include "trace2.h" struct dir_entry {struct hashmap_entry ent;@@ -577,6 +578,7 @@ static void lazy_init_name_hash(struct index_state *istate)if (istate->name_hash_initialized)return ;trace_performance_enter (); +trace2_region_enter ("index" ,"name-hash-init" , istate->repo);hashmap_init (&istate->name_hash, cache_entry_cmp,NULL , istate->cache_nr);hashmap_init (&istate->dir_hash, dir_entry_cmp,NULL , istate->cache_nr);@@ -597,6 +599,7 @@ static void lazy_init_name_hash(struct index_state *istate) } istate->name_hash_initialized =1 ; +trace2_region_leave ("index" ,"name-hash-init" , istate->repo);trace_performance_leave ("initialize name hash" ); } --
Quoted 1 line
gitgitgadget
Yaay for trace2. :-)
Total sidenote: Are we ever going to get rid of the trace1 stuff? I'm sure this was discussed somewhere, but I don't know where.
PATCH 6/9 sparse-checkout: load sparse-checkout patterns
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
A future feature will want to load the sparse-checkout patterns into a pattern_list, but the current mechanism to do so is a bit complicated. This is made difficult due to needing to find the sparse-checkout file in different ways throughout the codebase.
The logic implemented in the new get_sparse_checkout_patterns() was duplicated in populate_from_existing_patterns() in unpack-trees.c. Use the new method instead, keeping the logic around handling the struct unpack_trees_options.
The callers to get_sparse_checkout_filename() in builtin/sparse-checkout.c manipulate the sparse-checkout file directly, so it is not appropriate to replace logic in that file with get_sparse_checkout_patterns().
--- builtin/sparse-checkout.c | 5 ----- dir.c | 17 +++++++++++++++++ dir.h | 2 ++ unpack-trees.c | 6 +----- 4 files changed, 20 insertions(+), 10 deletions(-)
builtin/sparse-checkout.c +0 -5
@@ -22,11 +22,6 @@ static char const * const builtin_sparse_checkout_usage[] = { NULL }; -static char *get_sparse_checkout_filename (void ) -{ -return git_pathdup ("info/sparse-checkout" ); -} -static void write_patterns_to_file (FILE *fp,struct pattern_list *pl) {int i;
dir.c +17 -0
@@ -2998,6 +2998,23 @@ void setup_standard_excludes(struct dir_struct *dir) } } +char *get_sparse_checkout_filename (void ) +{ +return git_pathdup ("info/sparse-checkout" ); +} + +int get_sparse_checkout_patterns (struct pattern_list *pl) +{ +int res; +char *sparse_filename =get_sparse_checkout_filename (); + + pl->use_cone_patterns = core_sparse_checkout_cone; + res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , pl,NULL ); + +free (sparse_filename); +return res; +} +int remove_path (const char *name) {char *slash;
dir.h +2 -0
@@ -448,6 +448,8 @@ int is_empty_dir(const char *dir);void setup_standard_excludes (struct dir_struct *dir); +char *get_sparse_checkout_filename (void ); +int get_sparse_checkout_patterns (struct pattern_list *pl);/* Constants for remove_dir_recursively: */
unpack-trees.c +1 -5
@@ -1549,14 +1549,10 @@ static void mark_new_skip_worktree(struct pattern_list *pl,static void populate_from_existing_patterns (struct unpack_trees_options *o,struct pattern_list *pl) { -char *sparse =git_pathdup ("info/sparse-checkout" ); - - pl->use_cone_patterns = core_sparse_checkout_cone; -if (add_patterns_from_file_to_list (sparse,"" ,0 , pl,NULL ) <0 ) +if (get_sparse_checkout_patterns (pl) <0 ) o->skip_sparse_checkout =1 ;else o->pl = pl; -free (sparse); }
Signature · 1 line
gitgitgadget
Re: [PATCH 6/9] sparse-checkout: load sparse-checkout patterns
Quoted 104 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
A future feature will want to load the sparse-checkout patterns into a
pattern_list, but the current mechanism to do so is a bit complicated. This is made difficult due to needing to find the sparse-checkout file in different ways throughout the codebase.The logic implemented in the new
get_sparse_checkout_patterns()was duplicated inpopulate_from_existing_patterns()inunpack-trees.c. Use the new method instead, keeping the logic around handling the structunpack_trees_options.The callers to
get_sparse_checkout_filename()inbuiltin/sparse-checkout.cmanipulate the sparse-checkout file directly, so it is not appropriate to replace logic in that file withget_sparse_checkout_patterns().Signed-off-by Derrick Stolee <[email protected]>--- builtin/sparse-checkout.c | 5 ----- dir.c | 17 +++++++++++++++++ dir.h | 2 ++ unpack-trees.c | 6 +----- 4 files changed, 20 insertions(+), 10 deletions(-)builtin/sparse-checkout.c +0
-5@@ -22,11 +22,6 @@ static char const * const builtin_sparse_checkout_usage[] = { NULL }; -static char *get_sparse_checkout_filename (void ) -{ -return git_pathdup ("info/sparse-checkout" ); -} -static void write_patterns_to_file (FILE *fp,struct pattern_list *pl) {int i;dir.c +17
-0@@ -2998,6 +2998,23 @@ void setup_standard_excludes(struct dir_struct *dir) } } +char *get_sparse_checkout_filename (void ) +{ +return git_pathdup ("info/sparse-checkout" ); +} + +int get_sparse_checkout_patterns (struct pattern_list *pl) +{ +int res; +char *sparse_filename =get_sparse_checkout_filename (); + + pl->use_cone_patterns = core_sparse_checkout_cone; + res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , pl,NULL ); + +free (sparse_filename); +return res; +} +int remove_path (const char *name) {char *slash;dir.h +2
-0@@ -448,6 +448,8 @@ int is_empty_dir(const char *dir);void setup_standard_excludes (struct dir_struct *dir); +char *get_sparse_checkout_filename (void ); +int get_sparse_checkout_patterns (struct pattern_list *pl);/* Constants for remove_dir_recursively: */ unpack-trees.c +1
-6@@ -1549,14 +1549,10 @@ static void mark_new_skip_worktree(struct pattern_list *pl,static void populate_from_existing_patterns (struct unpack_trees_options *o,struct pattern_list *pl) { -char *sparse =git_pathdup ("info/sparse-checkout" ); - - pl->use_cone_patterns = core_sparse_checkout_cone; -if (add_patterns_from_file_to_list (sparse,"" ,0 , pl,NULL ) <0 ) +if (get_sparse_checkout_patterns (pl) <0 ) o->skip_sparse_checkout =1 ;else o->pl = pl; -free (sparse); } --
Quoted 1 line
gitgitgadget
Looks straightforward and well motivated to me.
But the cherry on top that really sells this patch is that more lines of dir.c will blame to someone besides me. Win-win!
PATCH 7/9 sparse-checkout: hold pattern list in index
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
As we modify the sparse-checkout definition, we perform index operations on a pattern_list that only exists in-memory. This allows easy backing out in case the index update fails.
However, if the index write itself cares about the sparse-checkout pattern set, we need access to that in-memory copy. Place a pointer to a 'struct pattern_list' in the index so we can access this on-demand.
--- builtin/sparse-checkout.c | 17 ++++++++++------- cache.h | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-)
builtin/sparse-checkout.c +10 -7
@@ -110,6 +110,8 @@ static int update_working_directory(struct pattern_list *pl)if (is_index_unborn (r->index))return UPDATE_SPARSITY_SUCCESS ; + r->index->sparse_checkout_patterns = pl; +memset (&o,0 ,sizeof (o)); o.verbose_update =isatty (2 ); o.update =1 ;
@@ -138,6 +140,7 @@ static int update_working_directory(struct pattern_list *pl)else rollback_lock_file (&lock_file); + r->index->sparse_checkout_patterns =NULL ;return result; }
@@ -517,19 +520,18 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m) {int result;int changed_config =0 ; -struct pattern_list pl; -memset (&pl,0 ,sizeof (pl)); +struct pattern_list *pl =xcalloc (1 ,sizeof (*pl));switch (m) {case ADD :if (core_sparse_checkout_cone) -add_patterns_cone_mode (argc, argv, &pl); +add_patterns_cone_mode (argc, argv, pl);else -add_patterns_literal (argc, argv, &pl); +add_patterns_literal (argc, argv, pl);break ;case REPLACE : -add_patterns_from_input (&pl, argc, argv); +add_patterns_from_input (pl, argc, argv);break ; }
@@ -539,12 +541,13 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m) changed_config =1 ; } - result =write_patterns_and_update (&pl); + result =write_patterns_and_update (pl);if (result && changed_config)set_config (MODE_NO_PATTERNS ); -clear_pattern_list (&pl); +clear_pattern_list (pl); +free (pl);return result; }
cache.h +2 -0
@@ -305,6 +305,7 @@ static inline unsigned int canon_mode(unsigned int mode)struct split_index ;struct untracked_cache ;struct progress ; +struct pattern_list ;struct index_state {struct cache_entry **cache;
@@ -329,6 +330,7 @@ struct index_state {struct mem_pool *ce_mem_pool;struct progress *progress;struct repository *repo; +struct pattern_list *sparse_checkout_patterns; };/* Name hashing */
Signature · 1 line
gitgitgadget
Re: [PATCH 7/9] sparse-checkout: hold pattern list in index
Quoted 31 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
As we modify the sparse-checkout definition, we perform index operations on a
pattern_listthat only exists in-memory. This allows easy backing out in case the index update fails.However, if the index write itself cares about the sparse-checkout pattern set, we need access to that in-memory copy. Place a pointer to a 'struct
pattern_list' in the index so we can access this on-demand.Signed-off-by Derrick Stolee <[email protected]>--- builtin/sparse-checkout.c | 17 ++++++++++------- cache.h | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-)builtin/sparse-checkout.c +2
-0@@ -110,6 +110,8 @@ static int update_working_directory(struct pattern_list *pl)if (is_index_unborn (r->index))return UPDATE_SPARSITY_SUCCESS ; + r->index->sparse_checkout_patterns = pl; +memset (&o,0 ,sizeof (o)); o.verbose_update =isatty (2 ); o.update =1 ;
builtin/sparse-checkout.c static int update_working_directory(struct pattern_list *pl) · line 144
Quoted 5 lines
builtin/sparse-checkout.c +1
-0@@ -138,6 +140,7 @@ static int update_working_directory(struct pattern_list *pl)else rollback_lock_file (&lock_file); + r->index->sparse_checkout_patterns =NULL ;return result;
The setting back to NULL made me curious; we don't want this information to remain available later? Is it only going to be used for the updating of the working directory?
I dug a bit into the callers, and didn't find the answer to my question...but I did notice that modify_pattern_list() will correctly free the patterns after write_patterns_and_update() via calling clear_pattern_list(&pl), but sparse_checkout_init() appears to leak the patterns it allocates. That's a separate issue from this patch, but do you want to fix that up while working in this area (so I avoid stepping on your toes with all your other patches)?
Quoted 13 lines
builtin/sparse-checkout.c +1
-2}@@ -517,19 +520,18 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m) {int result;int changed_config =0 ; -struct pattern_list pl; -memset (&pl,0 ,sizeof (pl)); +struct pattern_list *pl =xcalloc (1 ,sizeof (*pl));switch (m) {case ADD :if (core_sparse_checkout_cone)
builtin/sparse-checkout.c static int modify_pattern_list(int argc, const char **argv, enum modify_type m) · line 534
Quoted 10 lines
builtin/sparse-checkout.c +3
-3-add_patterns_cone_mode (argc, argv, &pl); +add_patterns_cone_mode (argc, argv, pl); else - add_patterns_literal(argc, argv, &pl); +add_patterns_literal (argc ,argv ,pl );break ;case REPLACE : -add_patterns_from_input (&pl, argc, argv); +add_patterns_from_input (pl, argc, argv);
Slightly annoying that the other functions are (argc, argv, pl) and this one is (pl, argc, argv). But again, that's outside the scope of this patch and might not be worth the churn to fix.
Quoted 40 lines
builtin/sparse-checkout.c +3
-2break ; }@@ -539,12 +541,13 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m) changed_config =1 ; } - result =write_patterns_and_update (&pl); + result =write_patterns_and_update (pl);if (result && changed_config)set_config (MODE_NO_PATTERNS ); -clear_pattern_list (&pl); +clear_pattern_list (pl); +free (pl);return result; }cache.h +2
-1@@ -305,6 +305,7 @@ static inline unsigned int canon_mode(unsigned int mode)struct split_index ;struct untracked_cache ;struct progress ; +struct pattern_list ;struct index_state {struct cache_entry **cache;@@ -329,6 +330,7 @@ struct index_state {struct mem_pool *ce_mem_pool;struct progress *progress;struct repository *repo; +struct pattern_list *sparse_checkout_patterns; };/* Name hashing */ --
Quoted 1 line
gitgitgadget
Otherwise, this patch looks good to me.
Re: [PATCH 7/9] sparse-checkout: hold pattern list in index
Quoted 43 lines · Elijah Newren
Quoted 31 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
As we modify the sparse-checkout definition, we perform index operations on a
pattern_listthat only exists in-memory. This allows easy backing out in case the index update fails.However, if the index write itself cares about the sparse-checkout pattern set, we need access to that in-memory copy. Place a pointer to a 'struct
pattern_list' in the index so we can access this on-demand.Signed-off-by Derrick Stolee <[email protected]>--- builtin/sparse-checkout.c | 17 ++++++++++------- cache.h | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-)builtin/sparse-checkout.c +2
-0@@ -110,6 +110,8 @@ static int update_working_directory(struct pattern_list *pl)if (is_index_unborn (r->index))return UPDATE_SPARSITY_SUCCESS ; + r->index->sparse_checkout_patterns = pl; +memset (&o,0 ,sizeof (o)); o.verbose_update =isatty (2 ); o.update =1 ;builtin/sparse-checkout.c static int update_working_directory(struct pattern_list *pl) · line 144
Quoted 5 lines
builtin/sparse-checkout.c +1
-0@@ -138,6 +140,7 @@ static int update_working_directory(struct pattern_list *pl)else rollback_lock_file (&lock_file); + r->index->sparse_checkout_patterns =NULL ;return result;The setting back to NULL made me curious; we don't want this information to remain available later? Is it only going to be used for the updating of the working directory?
Quoted 7 lines
I dug a bit into the callers, and didn't find the answer to my question...but I did notice that
modify_pattern_list()will correctly free the patterns afterwrite_patterns_and_update()via callingclear_pattern_list(&pl), butsparse_checkout_init()appears to leak the patterns it allocates. That's a separate issue from this patch, but do you want to fix that up while working in this area (so I avoid stepping on your toes with all your other patches)?
The thing that caught me here is that update_working_directory() uses an in-memory pattern_list that hasn't been committed to the sparse-checkout file yet. This means we need to (temporarily) point to this pattern_list.
Perhaps this patch is premature, since nothing actually _uses_ sparse_checkout_patterns yet. When we do add such a use, it will initialize a NULL value with the patterns in the sparse-checkout file. In that case, we definitely want to inject our in-memory patterns instead.
Thanks,
-Stolee
PATCH 8/9 test-lib: test_region looks for trace2 regions
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
Most test cases can verify Git's behavior using input/output expectations or changes to the .git directory. However, sometimes we want to check that Git did or did not run a certain section of code. This is particularly important for performance-only features that we want to ensure have been enabled in certain cases.
Add a new 'test_region' function that checks if a trace2 region was entered and left in a given trace2 event log.
There is one existing test (t0500-progress-display.sh) that performs this check already, so use the helper function instead. More uses will be added in a later change.
t6423-merge-rename-directories.sh also greps for region_enter lines, but it verifies the number of such lines, which is not the same as an existence check.
--- t/t0500-progress-display.sh | 3 +-- t/test-lib-functions.sh | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-)
t/t0500-progress-display.sh +1 -2
@@ -303,8 +303,7 @@ test_expect_success 'progress generates traces' ' "Working hard" <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. - grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region category progress trace.event && grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event && grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event '
t/test-lib-functions.sh +40 -0
@@ -1655,3 +1655,43 @@ test_subcommand () { grep "\[$expr\]" fi } + +# Check that the given command was invoked as part of the +# trace2-format trace on stdin. +# +# test_region [!] <category> <label> git <command> <args>... +# +# For example, to look for trace2_region_enter("index", "do_read_index", repo) +# in an invocation of "git checkout HEAD~1", run +# +# GIT_TRACE2_EVENT="$(pwd)/trace.txt" GIT_TRACE2_EVENT_NESTING=10 \ +# git checkout HEAD~1 && +# test_region index do_read_index <trace.txt +# +# If the first parameter passed is !, this instead checks that +# the given region was not entered. +# +test_region () { + local expect_exit=0 + if test "$1" = "!" + then + expect_exit=1 + shift + fi + + grep -e "region_enter" -e "\"category\":\"$1\",\"label\":\"$2\"" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi + + grep -e "region_leave" -e "\"category\":\"$1\",\"label\":\"$2\"" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi +}
Signature · 1 line
gitgitgadget
Re: [PATCH 8/9] test-lib: test_region looks for trace2 regions
Quoted 11 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Most test cases can verify Git's behavior using input/output expectations or changes to the .git directory. However, sometimes we want to check that Git did or did not run a certain section of code. This is particularly important for performance-only features that we want to ensure have been enabled in certain cases.
Add a new '
test_region' function that checks if a trace2 region was entered and left in a given trace2 event log.
Ooh, others do this too? Sounds like a helpful function to add, but just checking for entered and left means that...
Quoted 8 lines
There is one existing test (
t0500-progress-display.sh) that performs this check already, so use the helper function instead. More uses will be added in a later change.
t6423-merge-rename-directories.shalso greps forregion_enterlines, but it verifies the number of such lines, which is not the same as an existence check.
...yeah, won't cover the case that I added. That's fine, since it appears to be a one-off for now and we don't know of any other cases, current or planned, that want to do something like that yet.
Quoted 12 lines
Signed-off-by Derrick Stolee <[email protected]>--- t/t0500-progress-display.sh | 3 +-- t/test-lib-functions.sh | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-)t/t0500-progress-display.sh +0
-0
t/t0500-progress-display.sh test_expect_success 'progress generates traces' ' · line 306
Quoted 6 lines
t/t0500-progress-display.sh +1
-2@@ -303,8 +303,7 @@ test_expect_success 'progress generates traces' ' "Working hard" <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. - grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region category progress trace.event &&
Sidenote: Hmm...about 40% of my region labels in merge-ort.c and 90% in diffcore-rename.c have spaces in them. This function could still be used, but I'm curious if I should change the labels (but then again, they are testing logical regions rather than individual functions, and the spaces instead of underscores kind of convey that...)
Quoted 52 lines
t/t0500-progress-display.sh +0
-0grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event && grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event 't/test-lib-functions.sh +40
-1@@ -1655,3 +1655,43 @@ test_subcommand () { grep "\[$expr\]" fi } + +# Check that the given command was invoked as part of the +# trace2-format trace on stdin. +# +# test_region [!] <category> <label> git <command> <args>... +# +# For example, to look for trace2_region_enter("index", "do_read_index", repo) +# in an invocation of "git checkout HEAD~1", run +# +# GIT_TRACE2_EVENT="$(pwd)/trace.txt" GIT_TRACE2_EVENT_NESTING=10 \ +# git checkout HEAD~1 && +# test_region index do_read_index <trace.txt +# +# If the first parameter passed is !, this instead checks that +# the given region was not entered. +# +test_region () { + local expect_exit=0 + if test "$1" = "!" + then + expect_exit=1 + shift + fi + + grep -e "region_enter" -e "\"category\":\"$1\",\"label\":\"$2\"" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi + + grep -e "region_leave" -e "\"category\":\"$1\",\"label\":\"$2\"" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi +} --
Quoted 1 line
gitgitgadget
This patch looks good to me.
Re: [PATCH 8/9] test-lib: test_region looks for trace2 regions
Quoted 2 lines · Elijah Newren
On Wed, Jan 20, 2021 at 8:54 AM Derrick Stolee via GitGitGadget <[email protected]> wrote:
...
Quoted 11 lines
t/t0500-progress-display.sh test_expect_success 'progress generates traces' ' · line 306
Quoted 4 lines
# t0212/parse_events.perl intentionally omits regions and data.t/t0500-progress-display.sh +1
-2- grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region category progress trace.event &&Sidenote: Hmm...about 40% of my region labels in
merge-ort.cand 90% indiffcore-rename.chave spaces in them. This function could still be used, but I'm curious if I should change the labels (but then again, they are testing logical regions rather than individual functions, and the spaces instead of underscores kind of convey that...)
You should be able to use
test_region "category with spaces" "progress with spaces" trace
but if not, then the test_region helper could be improved to match.
I do think that it's better to avoid spaces in these identifiers.
Thanks,
-Stolee
PATCH 9/9 t1092: test interesting sparse-checkout scenarios
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
These also document some behaviors that differ from a full checkout, and possibly in a way that is not intended.
--- t/t1092-sparse-checkout-compatibility.sh | 323 +++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100755 t/t1092-sparse-checkout-compatibility.sh
t/t1092-sparse-checkout-compatibility.sh new file +323 -0
@@ -0,0 +1,323 @@ +#!/bin/sh + +test_description='compare full workdir to sparse workdir' + +. ./test-lib.sh + +test_expect_success 'setup' ' + git init initial-repo && + ( + cd initial-repo && + echo a >a && + echo "after deep" >e && + echo "after folder1" >g && + mkdir folder1 folder2 deep x && + mkdir deep/deeper1 deep/deeper2 && + mkdir deep/deeper1/deepest && + echo "after deeper1" >deep/e && + echo "after deepest" >deep/deeper1/e && + cp a folder1 && + cp a folder2 && + cp a deep && + cp a deep/deeper1 && + cp a deep/deeper2 && + cp a deep/deeper1/deepest && + git add . && + git commit -m "initial commit" && + git checkout -b base && + for dir in folder1 folder2 deep + do + git checkout -b update-$dir && + echo "updated $dir" >$dir/a && + git commit -a -m "update $dir" || return 1 + done && + + git checkout -b rename-base base && + echo >folder1/larger-content <<-\EOF && + matching + lines + help + inexact + renames + EOF + cp folder1/larger-content folder2/ && + cp folder1/larger-content deep/deeper1/ && + git add . && + git commit -m "add interesting rename content" && + + git checkout -b rename-out-to-out rename-base && + mv folder1/a folder2/b && + mv folder1/larger-content folder2/edited-content && + echo >>folder2/edited-content && + git add . && + git commit -m "rename folder1/... to folder2/..." && + + git checkout -b rename-out-to-in rename-base && + mv folder1/a deep/deeper1/b && + mv folder1/larger-content deep/deeper1/edited-content && + echo >>deep/deeper1/edited-content && + git add . && + git commit -m "rename folder1/... to deep/deeper1/..." && + + git checkout -b rename-in-to-out rename-base && + mv deep/deeper1/a folder1/b && + mv deep/deeper1/larger-content folder1/edited-content && + echo >>folder1/edited-content && + git add . && + git commit -m "rename deep/deeper1/... to folder1/..." && + + git checkout -b deepest base && + echo "updated deepest" >deep/deeper1/deepest/a && + git commit -a -m "update deepest" && + + git checkout -f base && + git reset --hard + ) +' + +init_repos () { + rm -rf full-checkout sparse-checkout sparse-index && + + # create repos in initial state + cp -r initial-repo full-checkout && + git -C full-checkout reset --hard && + + cp -r initial-repo sparse-checkout && + git -C sparse-checkout reset --hard && + git -C sparse-checkout sparse-checkout init --cone && + + # initialize sparse-checkout definitions + git -C sparse-checkout sparse-checkout set deep +} + +run_on_sparse () { + ( + cd sparse-checkout && + $* >../sparse-checkout-out 2>../sparse-checkout-err + ) +} + +run_on_all () { + ( + cd full-checkout && + $* >../full-checkout-out 2>../full-checkout-err + ) && + run_on_sparse $* +} + +test_all_match () { + run_on_all $* && + test_cmp full-checkout-out sparse-checkout-out && + test_cmp full-checkout-err sparse-checkout-err +} + +test_expect_success 'status with options' ' + init_repos && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + run_on_all "touch README.md" && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno +' + +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +' + +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + run_on_all "../edit-contents README.md" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents README.md" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents deep/newfile" && + + test_all_match git status --porcelain=v2 -uno && + test_all_match git status --porcelain=v2 && + test_all_match git add . && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "add deep/newfile" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +' + +test_expect_success 'checkout and reset --hard' ' + init_repos && + + test_all_match git checkout update-folder1 && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout update-deep && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout -b reset-test && + test_all_match git reset --hard deepest && + test_all_match git reset --hard update-folder1 && + test_all_match git reset --hard update-folder2 +' + +test_expect_success 'diff --staged' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git diff && + test_all_match git diff --staged && + test_all_match git add README.md && + test_all_match git diff && + test_all_match git diff --staged +' + +test_expect_success 'diff with renames' ' + init_repos && + + for branch in rename-out-to-out rename-out-to-in rename-in-to-out + do + test_all_match git checkout rename-base && + test_all_match git checkout $branch -- .&& + test_all_match git diff --staged && + test_all_match git diff --staged --find-renames || return 1 + done +' + +test_expect_success 'log with pathspec outside sparse definition' ' + init_repos && + + test_all_match git log -- a && + test_all_match git log -- folder1/a && + test_all_match git log -- folder2/a && + test_all_match git log -- deep/a && + test_all_match git log -- deep/deeper1/a && + test_all_match git log -- deep/deeper1/deepest/a && + + test_all_match git checkout update-folder1 && + test_all_match git log -- folder1/a +' + +test_expect_success 'blame with pathspec inside sparse definition' ' + init_repos && + + test_all_match git blame a && + test_all_match git blame deep/a && + test_all_match git blame deep/deeper1/a && + test_all_match git blame deep/deeper1/deepest/a +' + +# TODO: blame currently does not support blaming files outside of the +# sparse definition. It complains that the file doesn't exist locally. +test_expect_failure 'blame with pathspec outside sparse definition' ' + init_repos && + + test_all_match git blame folder1/a && + test_all_match git blame folder2/a && + test_all_match git blame deep/deeper2/a && + test_all_match git blame deep/deeper2/deepest/a +' + +# TODO: reset currently does not behave as expected when in a +# sparse-checkout. +test_expect_failure 'checkout and reset (mixed)' ' + init_repos && + + test_all_match git checkout -b reset-test update-deep && + test_all_match git reset deepest && + test_all_match git reset update-folder1 && + test_all_match git reset update-folder2 +' + +test_expect_success 'merge' ' + init_repos && + + test_all_match git checkout -b merge update-deep && + test_all_match git merge -m "folder1" update-folder1 && + test_all_match git rev-parse HEAD^{tree} && + test_all_match git merge -m "folder2" update-folder2 && + test_all_match git rev-parse HEAD^{tree} +' + +test_expect_success 'merge with outside renames' ' + init_repos && + + for type in out-to-out out-to-in in-to-out + do + test_all_match git reset --hard && + test_all_match git checkout -f -b merge-$type update-deep && + test_all_match git merge -m "$type" rename-$type && + test_all_match git rev-parse HEAD^{tree} || return 1 + done +' + +test_expect_success 'clean' ' + init_repos && + + echo bogus >>.gitignore && + run_on_all cp ../.gitignore . && + test_all_match git add .gitignore && + test_all_match git commit -m ignore-bogus-files && + + run_on_sparse mkdir folder1 && + run_on_all touch folder1/bogus && + + test_all_match git status --porcelain=v2 && + test_all_match git clean -f && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xf && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xdf && + test_all_match git status --porcelain=v2 && + + test_path_is_dir sparse-checkout/folder1 +' + +test_done
Signature · 1 line
gitgitgadget
Re: [PATCH 9/9] t1092: test interesting sparse-checkout scenarios
Quoted 5 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
These also document some behaviors that differ from a full checkout, and possibly in a way that is not intended.
I'm in favor. I should turn some of my noted weird behaviors from [1] into testcases as well.
[1] https://lore.kernel.org/git/CABPp-BGJ_Nvi5TmgriD9Bh6eNXE2EDq2f8e8QKXAeYG3BxZafA@mail.gmail.com/
Quoted 154 lines
Signed-off-by Derrick Stolee <[email protected]>--- t/t1092-sparse-checkout-compatibility.sh | 323 +++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100755 t/t1092-sparse-checkout-compatibility.sht/t1092-sparse-checkout-compatibility.sh new file +142
-0@@ -0,0 +1,323 @@ +#!/bin/sh + +test_description='compare full workdir to sparse workdir' + +. ./test-lib.sh + +test_expect_success 'setup' ' + git init initial-repo && + ( + cd initial-repo && + echo a >a && + echo "after deep" >e && + echo "after folder1" >g && + mkdir folder1 folder2 deep x && + mkdir deep/deeper1 deep/deeper2 && + mkdir deep/deeper1/deepest && + echo "after deeper1" >deep/e && + echo "after deepest" >deep/deeper1/e && + cp a folder1 && + cp a folder2 && + cp a deep && + cp a deep/deeper1 && + cp a deep/deeper2 && + cp a deep/deeper1/deepest && + git add . && + git commit -m "initial commit" && + git checkout -b base && + for dir in folder1 folder2 deep + do + git checkout -b update-$dir && + echo "updated $dir" >$dir/a && + git commit -a -m "update $dir" || return 1 + done && + + git checkout -b rename-base base && + echo >folder1/larger-content <<-\EOF && + matching + lines + help + inexact + renames + EOF + cp folder1/larger-content folder2/ && + cp folder1/larger-content deep/deeper1/ && + git add . && + git commit -m "add interesting rename content" && + + git checkout -b rename-out-to-out rename-base && + mv folder1/a folder2/b && + mv folder1/larger-content folder2/edited-content && + echo >>folder2/edited-content && + git add . && + git commit -m "rename folder1/... to folder2/..." && + + git checkout -b rename-out-to-in rename-base && + mv folder1/a deep/deeper1/b && + mv folder1/larger-content deep/deeper1/edited-content && + echo >>deep/deeper1/edited-content && + git add . && + git commit -m "rename folder1/... to deep/deeper1/..." && + + git checkout -b rename-in-to-out rename-base && + mv deep/deeper1/a folder1/b && + mv deep/deeper1/larger-content folder1/edited-content && + echo >>folder1/edited-content && + git add . && + git commit -m "rename deep/deeper1/... to folder1/..." && + + git checkout -b deepest base && + echo "updated deepest" >deep/deeper1/deepest/a && + git commit -a -m "update deepest" && + + git checkout -f base && + git reset --hard + ) +' + +init_repos () { + rm -rf full-checkout sparse-checkout sparse-index && + + # create repos in initial state + cp -r initial-repo full-checkout && + git -C full-checkout reset --hard && + + cp -r initial-repo sparse-checkout && + git -C sparse-checkout reset --hard && + git -C sparse-checkout sparse-checkout init --cone && + + # initialize sparse-checkout definitions + git -C sparse-checkout sparse-checkout set deep +} + +run_on_sparse () { + ( + cd sparse-checkout && + $* >../sparse-checkout-out 2>../sparse-checkout-err + ) +} + +run_on_all () { + ( + cd full-checkout && + $* >../full-checkout-out 2>../full-checkout-err + ) && + run_on_sparse $* +} + +test_all_match () { + run_on_all $* && + test_cmp full-checkout-out sparse-checkout-out && + test_cmp full-checkout-err sparse-checkout-err +} + +test_expect_success 'status with options' ' + init_repos && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + run_on_all "touch README.md" && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno +' + +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - &&
t/t1092-sparse-checkout-compatibility.sh line 152
Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh new file +10
-0+ + run_on_all "../edit-contents" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +'
I was going to add comments here, but I noticed the next test had the same description and looked very similar, so I'll defer the comments...
Quoted 14 lines
t/t1092-sparse-checkout-compatibility.sh new file +14
-0+ +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + run_on_all "../edit-contents README.md" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 &&
t/t1092-sparse-checkout-compatibility.sh line 176
Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh new file +10
-0+ test_all_match git checkout - && + + run_on_all "../edit-contents README.md" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - &&
Up to here, this test is identical to the previous one. Why repeat it?
t/t1092-sparse-checkout-compatibility.sh line 188
Quoted 12 lines
t/t1092-sparse-checkout-compatibility.sh new file +12
-0+ + run_on_all "../edit-contents deep/newfile" && + + test_all_match git status --porcelain=v2 -uno && + test_all_match git status --porcelain=v2 && + test_all_match git add . && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "add deep/newfile" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +'
Think out loud...so you are only adding files that were not previously tracked and that would have been part of the sparse cone. You aren't trying to add files that would be outside the sparse cone, or manually creating files missing from the working tree due to sparseness and then attempting to add them. (Which is fine, we have to start somewhere with our testing. Also, I think my testcases didn't look at the case you did, and only covered one of these other two cases.)
Quoted 20 lines
t/t1092-sparse-checkout-compatibility.sh new file +20
-0+ +test_expect_success 'checkout and reset --hard' ' + init_repos && + + test_all_match git checkout update-folder1 && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout update-deep && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout -b reset-test && + test_all_match git reset --hard deepest && + test_all_match git reset --hard update-folder1 && + test_all_match git reset --hard update-folder2 +' + +test_expect_success 'diff --staged' ' + init_repos && + + write_script edit-contents <<-\EOF &&
t/t1092-sparse-checkout-compatibility.sh line 218
Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh new file +10
-0+ echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git diff && + test_all_match git diff --staged && + test_all_match git add README.md && + test_all_match git diff && + test_all_match git diff --staged +'
Also a case where you're operating on a file that matches the sparsity patterns (in cone mode, everything in the root directory is included).
t/t1092-sparse-checkout-compatibility.sh line 228
Quoted 9 lines
t/t1092-sparse-checkout-compatibility.sh new file +9
-0+test_expect_success 'diff with renames' ' + init_repos && + + for branch in rename-out-to-out rename-out-to-in rename-in-to-out + do + test_all_match git checkout rename-base && + test_all_match git checkout $branch -- .&& + test_all_match git diff --staged && + test_all_match git diff --staged --find-renames || return 1
Aren't these last two lines the same? (diff.renames defaults to true ever since commit 5404c116aa, "diff: activate diff.renames by default", 2016-02-25) Are they only different because you have a tweaked config that turns off renames by default?
Perhaps the first diff line should have a --no-renames flag.
Quoted 15 lines
t/t1092-sparse-checkout-compatibility.sh new file +15
-0+ done +' + +test_expect_success 'log with pathspec outside sparse definition' ' + init_repos && + + test_all_match git log -- a && + test_all_match git log -- folder1/a && + test_all_match git log -- folder2/a && + test_all_match git log -- deep/a && + test_all_match git log -- deep/deeper1/a && + test_all_match git log -- deep/deeper1/deepest/a && + + test_all_match git checkout update-folder1 && + test_all_match git log -- folder1/a
t/t1092-sparse-checkout-compatibility.sh line 253
Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh new file +10
-0+' + +test_expect_success 'blame with pathspec inside sparse definition' ' + init_repos && + + test_all_match git blame a && + test_all_match git blame deep/a && + test_all_match git blame deep/deeper1/a && + test_all_match git blame deep/deeper1/deepest/a +'
Good check.
On a side note going back to a piece of the other thread I didn't get a response to, I'm still curious whether
git blame -C -C $PATH_INSIDE_SPARSE_DEFINITION
should (optionally?) behave differently in a sparse checkout. In particular, should it limit its copy detection to other paths also in the sparse checkout, or should it always search all other files within the repository for copied lines? Searching just within the sparse checkout seems like it could be a really nice performance optimization.
t/t1092-sparse-checkout-compatibility.sh line 256
Quoted 3 lines
t/t1092-sparse-checkout-compatibility.sh new file +3
-0+ +# TODO: blame currently does not support blaming files outside of the +# sparse definition. It complains that the file doesn't exist locally.
Nice catch. Yeah, blame tries to check the local working copy for changes, and shows those lines with a changed in commit 0000000000. We should add a check that says that if the file is SKIP_WORKTREE, then we treat it the same as git blame $PATH HEAD.
t/t1092-sparse-checkout-compatibility.sh line 267
Quoted 11 lines
t/t1092-sparse-checkout-compatibility.sh new file +11
-0+test_expect_failure 'blame with pathspec outside sparse definition' ' + init_repos && + + test_all_match git blame folder1/a && + test_all_match git blame folder2/a && + test_all_match git blame deep/deeper2/a && + test_all_match git blame deep/deeper2/deepest/a +' + +# TODO: reset currently does not behave as expected when in a +# sparse-checkout.
I'm going to go to test this out to see what it does. It's the first testcase you listed that I didn't know how it worked and couldn't figure it out from your comments. However it turns out, definitely a good test to have.
Quoted 47 lines
t/t1092-sparse-checkout-compatibility.sh new file +47
-0+test_expect_failure 'checkout and reset (mixed)' ' + init_repos && + + test_all_match git checkout -b reset-test update-deep && + test_all_match git reset deepest && + test_all_match git reset update-folder1 && + test_all_match git reset update-folder2 +' + +test_expect_success 'merge' ' + init_repos && + + test_all_match git checkout -b merge update-deep && + test_all_match git merge -m "folder1" update-folder1 && + test_all_match git rev-parse HEAD^{tree} && + test_all_match git merge -m "folder2" update-folder2 && + test_all_match git rev-parse HEAD^{tree} +' + +test_expect_success 'merge with outside renames' ' + init_repos && + + for type in out-to-out out-to-in in-to-out + do + test_all_match git reset --hard && + test_all_match git checkout -f -b merge-$type update-deep && + test_all_match git merge -m "$type" rename-$type && + test_all_match git rev-parse HEAD^{tree} || return 1 + done +' + +test_expect_success 'clean' ' + init_repos && + + echo bogus >>.gitignore && + run_on_all cp ../.gitignore . && + test_all_match git add .gitignore && + test_all_match git commit -m ignore-bogus-files && + + run_on_sparse mkdir folder1 && + run_on_all touch folder1/bogus && + + test_all_match git status --porcelain=v2 && + test_all_match git clean -f && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xf &&
t/t1092-sparse-checkout-compatibility.sh
Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh new file +9
-1+ test_all_match git status --porcelain=v2 && + + test_all_match git clean -xdf && + test_all_match git status --porcelain=v2 && + + test_path_is_dir sparse-checkout/folder1 +' + +test_done --
I made lots of comments, but overall these tests look good to me other than just one question about test duplication and another about using --no-renames for diff when rename detection isn't wanted.
Re: [PATCH 9/9] t1092: test interesting sparse-checkout scenarios
Quoted 5 lines · Elijah Newren
Quoted 3 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Quoted 7 lines
Quoted 2 lines
These also document some behaviors that differ from a full checkout, and possibly in a way that is not intended.
I'm in favor. I should turn some of my noted weird behaviors from [1] into testcases as well.
[1] https://lore.kernel.org/git/CABPp-BGJ_Nvi5TmgriD9Bh6eNXE2EDq2f8e8QKXAeYG3BxZafA@mail.gmail.com/
That would be helpful, and adding them here would be helpful.
For the cases where things don't work correctly, it is good to add "test_expect_failure" cases as a TODO list for the feature space.
Quoted 18 lines
Quoted 18 lines
(quoted diff) +18
-0+ +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + run_on_all "../edit-contents README.md" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents README.md" && +
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - &&Up to here, this test is identical to the previous one. Why repeat it?
Unintentional. I cleaned this up in a later commit of my prototype, but forgot to delete that back in this patch. Will fix.
Quoted 13 lines
Review
Quoted 12 lines
(quoted diff) +12
-0+ + run_on_all "../edit-contents deep/newfile" && + + test_all_match git status --porcelain=v2 -uno && + test_all_match git status --porcelain=v2 && + test_all_match git add . && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "add deep/newfile" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +'
Quoted 7 lines
Think out loud...so you are only adding files that were not previously tracked and that would have been part of the sparse cone. You aren't trying to add files that would be outside the sparse cone, or manually creating files missing from the working tree due to sparseness and then attempting to add them. (Which is fine, we have to start somewhere with our testing. Also, I think my testcases didn't look at the case you did, and only covered one of these other two cases.)
Yes, these tests are currently focusing on the "happy" cases of what is happening within the sparse cone. I plan to expand to the more complicated cases later, as I start implementing them correctly with the sparse-index. However, it would be fine to have the tests here earlier. Extra documentation of the expected behavior (or how the current implementation is not desirable) would be good.
Quoted 49 lines
Quoted 20 lines
(quoted diff) +20
-0+ +test_expect_success 'checkout and reset --hard' ' + init_repos && + + test_all_match git checkout update-folder1 && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout update-deep && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout -b reset-test && + test_all_match git reset --hard deepest && + test_all_match git reset --hard update-folder1 && + test_all_match git reset --hard update-folder2 +' + +test_expect_success 'diff --staged' ' + init_repos && + + write_script edit-contents <<-\EOF &&Review
Quoted 10 lines
(quoted diff) +10
-0+ echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git diff && + test_all_match git diff --staged && + test_all_match git add README.md && + test_all_match git diff && + test_all_match git diff --staged +'Also a case where you're operating on a file that matches the sparsity patterns (in cone mode, everything in the root directory is included).
Review
Quoted 9 lines
(quoted diff) +9
-0+test_expect_success 'diff with renames' ' + init_repos && + + for branch in rename-out-to-out rename-out-to-in rename-in-to-out + do + test_all_match git checkout rename-base && + test_all_match git checkout $branch -- .&& + test_all_match git diff --staged && + test_all_match git diff --staged --find-renames || return 1Aren't these last two lines the same? (diff.renames defaults to true ever since commit
5404c116aa, "diff: activate diff.renames by default", 2016-02-25) Are they only different because you have a tweaked config that turns off renames by default?
Quoted 1 line
Perhaps the first diff line should have a --no-renames flag.
Thanks! Will do.
Quoted 28 lines
Quoted 15 lines
(quoted diff) +15
-0+ done +' + +test_expect_success 'log with pathspec outside sparse definition' ' + init_repos && + + test_all_match git log -- a && + test_all_match git log -- folder1/a && + test_all_match git log -- folder2/a && + test_all_match git log -- deep/a && + test_all_match git log -- deep/deeper1/a && + test_all_match git log -- deep/deeper1/deepest/a && + + test_all_match git checkout update-folder1 && + test_all_match git log -- folder1/aReview
Quoted 10 lines
(quoted diff) +10
-0+' + +test_expect_success 'blame with pathspec inside sparse definition' ' + init_repos && + + test_all_match git blame a && + test_all_match git blame deep/a && + test_all_match git blame deep/deeper1/a && + test_all_match git blame deep/deeper1/deepest/a +'Good check.
Quoted 9 lines
On a side note going back to a piece of the other thread I didn't get a response to, I'm still curious whether
git blame -C -C $PATH_INSIDE_SPARSE_DEFINITION
should (optionally?) behave differently in a sparse checkout. In particular, should it limit its copy detection to other paths also in the sparse checkout, or should it always search all other files within the repository for copied lines? Searching just within the sparse checkout seems like it could be a really nice performance optimization.
All of the "find movements or copies" logic could benefit from a "universal" option to restrict to the sparse-checkout definition.
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +# TODO: blame currently does not support blaming files outside of the +# sparse definition. It complains that the file doesn't exist locally.Nice catch. Yeah, blame tries to check the local working copy for changes, and shows those lines with a changed in commit 0000000000. We should add a check that says that if the file is
SKIP_WORKTREE, then we treat it the same asgit blame $PATH HEAD.
Right. If it's not in the working directory, then we should interpret that as HEAD.
Quoted 17 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+test_expect_failure 'blame with pathspec outside sparse definition' ' + init_repos && + + test_all_match git blame folder1/a && + test_all_match git blame folder2/a && + test_all_match git blame deep/deeper2/a && + test_all_match git blame deep/deeper2/deepest/a +' + +# TODO: reset currently does not behave as expected when in a +# sparse-checkout.I'm going to go to test this out to see what it does. It's the first testcase you listed that I didn't know how it worked and couldn't figure it out from your comments. However it turns out, definitely a good test to have.
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+test_expect_failure 'checkout and reset (mixed)' ' + init_repos && + + test_all_match git checkout -b reset-test update-deep && + test_all_match git reset deepest && + test_all_match git reset update-folder1 && + test_all_match git reset update-folder2 +'
Here are the failures:
after "git checkout -b reset-test update-deep"
sparse-checkout-out 2021-01-21 11:51:30.063713235 +0000 renamed from full-checkout-out 2021-01-21 11:51:30.059713246 +0000 +2 -2
@@ -1,5 +1,5 @@ Unstaged changes after reset: M deep/a M deep/deeper1/deepest/a -M folder1/a -M folder2/a +D folder1/a +D folder2/a
If we comment out that line, the failures for
"git reset update-folder1" is:
sparse-checkout-out 2021-01-21 11:52:36.207509976 +0000 renamed from full-checkout-out 2021-01-21 11:52:36.203509990 +0000 +1 -1
@@ -1,2 +1,2 @@ Unstaged changes after reset: -M folder1/a +D folder1/a
If we comment out that line, then the failure for
"git reset update-folder2" is:
sparse-checkout-out 2021-01-21 11:53:55.207197573 +0000 renamed from full-checkout-out 2021-01-21 11:53:55.199197608 +0000 +2 -2
@@ -1,3 +1,3 @@ Unstaged changes after reset: -M folder1/a -M folder2/a +D folder1/a +D folder2/a
Oddly, when I merge this into our branch in microsoft/git, these failures disappear. There is something in those commits that resolve this particular case. I hope to figure that out sometime.
Thanks,
-Stolee
v2 cover More index cleanups
In reply to Derrick Stolee via GitGitGadgetThis is based on ds/cache-tree-basics.
Here are a few more cleanups that are vaguely related to the index. I discovered these while preparing my sparse-index RFC that I intend to send early next week.
The biggest patch is the final one, which creates a test script for comparing sparse-checkouts to full checkouts. There are some commands that do not behave similarly. This script will be the backbone of my testing strategy for the sparse-index by adding a new mode to compare sparse-checkouts with the two index types (full and sparse).
UPDATES IN V2
=============
* Fixed duplicated test in t1092.
* Changed the implementation of 'test_region' after I discovered the negation doesn't work correctly. (I updated the test to use what was in t0500-progress-display.sh at the last minute before v1, but that implementation was wrong.) The use of it in t0500-progress-display.sh was incorrect, as well.
* Updated commit messages to be more informative and have fewer typos.
* I dropped the patch that placed the sparse-checkout patterns in struct index_state. I'll re-introduce that in time for the actual use of the member.
Thanks, -Stolee
Derrick Stolee (8):
cache-tree: clean up cache_tree_update()
cache-tree: extract subtree_pos()
fsmonitor: de-duplicate BUG()s around dirty bits
repository: add repo reference to index_state
name-hash: use trace2 regions for init
sparse-checkout: load sparse-checkout patterns
test-lib: test_region looks for trace2 regions
t1092: test interesting sparse-checkout scenarios
builtin/sparse-checkout.c | 5 - cache-tree.c | 20 +- cache-tree.h | 2 + cache.h | 1 + dir.c | 17 ++ dir.h | 2 + fsmonitor.c | 27 +- name-hash.c | 3 + repository.c | 4 + t/t0500-progress-display.sh | 3 +- t/t1092-sparse-checkout-compatibility.sh | 298 +++++++++++++++++++++++ t/test-lib-functions.sh | 40 +++ unpack-trees.c | 6 +- 13 files changed, 394 insertions(+), 34 deletions(-) create mode 100755 t/t1092-sparse-checkout-compatibility.sh
base-commit: a4b6d202caad83c6dc29abe9b17e53a1b3fb54a0
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-839%2Fderrickstolee%2Fmore-index-cleanups-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-839/derrickstolee/more-index-cleanups-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/839
Range-diff vs v1:
1: 0bccfd34ae5 ! 1: f9dccaed0ac cache-tree: clean up cache_tree_update()
@@ Commit message
cache-tree: clean up cache_tree_update()
Make the method safer by allocating a cache_tree member for the given
- index_state if it is not already present.
+ index_state if it is not already present. This is preferrable to a
+ BUG() statement or returning with an error because future callers will
+ want to populate an empty cache-tree using this method.
Also drop local variables that are used exactly once and can be found directly from the 'istate' parameter.
2: a6f2406a795 = 2: 84323e04d08 cache-tree: extract subtree_pos() 3: 838922de2e9 = 3: 31095f9aa0e fsmonitor: de-duplicate BUG()s around dirty bits 4: d4ff0468fc0 ! 4: a0d89d7a973 repository: add repo reference to index_state
@@ Metadata
## Commit message ##
repository: add repo reference to index_state
- It will be helpful to add behavior to index opertations that might
+ It will be helpful to add behavior to index operations that might
trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct index_state that allows access to this repository.
5: 3ba4b35f09c = 5: bc092f5c703 name-hash: use trace2 regions for init
6: 64358ec7ea2 = 6: 04d1daf7222 sparse-checkout: load sparse-checkout patterns
7: 91344f5108c < -: ----------- sparse-checkout: hold pattern list in index
8: 8326a9b5320 ! 7: 8832ce84623 test-lib: test_region looks for trace2 regions
@@ Commit message
entered and left in a given trace2 event log.
There is one existing test (t0500-progress-display.sh) that performs
- this check already, so use the helper function instead. More uses will
- be added in a later change.
+ this check already, so use the helper function instead. Note that this
+ changes the expectations slightly. The old test (incorrectly) used two
+ patterns for the 'grep' invocation, but this performs an OR of the
+ patterns, not an AND. This means that as long as one region_enter event
+ was logged, the test would succeed, even if it was not due to the
+ progress category.
+
+ More uses will be added in a later change.
t6423-merge-rename-directories.sh also greps for region_enter lines, but
it verifies the number of such lines, which is not the same as an
@@ t/t0500-progress-display.sh: test_expect_success 'progress generates traces' '
# t0212/parse_events.perl intentionally omits regions and data.
- grep -e "region_enter" -e "\"category\":\"progress\"" trace.event &&
- grep -e "region_leave" -e "\"category\":\"progress\"" trace.event &&
-+ test_region category progress trace.event &&
++ test_region progress "Working hard" trace.event &&
grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event &&
grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event
'
@@ t/test-lib-functions.sh: test_subcommand () {
+ shift
+ fi
+
-+ grep -e "region_enter" -e "\"category\":\"$1\",\"label\":\"$2\"" "$3"
++ grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
+ exitcode=$?
+
+ if test $exitcode != $expect_exit
@@ t/test-lib-functions.sh: test_subcommand () {
+ return 1
+ fi
+
-+ grep -e "region_leave" -e "\"category\":\"$1\",\"label\":\"$2\"" "$3"
++ grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
+ exitcode=$?
+
+ if test $exitcode != $expect_exit
9: 555e210dc03 ! 8: 984458007ed t1092: test interesting sparse-checkout scenarios
@@ Commit message
These also document some behaviors that differ from a full checkout, and
possibly in a way that is not intended.
+ The test is designed to be run with "--run=1,X" where 'X' is an
+ interesting test case. Each test uses 'init_repos' to reset the full and
+ sparse copies of the initial-repo that is created by the first test
+ case. This also makes it possible to have test cases leave the working
+ directory or index in unusual states without disturbing later cases.
+
Signed-off-by: Derrick Stolee <[email protected]>
## t/t1092-sparse-checkout-compatibility.sh (new) ##
@@ t/t1092-sparse-checkout-compatibility.sh (new)
+ init_repos &&
+
+ write_script edit-contents <<-\EOF &&
-+ echo text >>README.md
-+ EOF
-+ run_on_all "../edit-contents" &&
-+
-+ test_all_match git add README.md &&
-+ test_all_match git status --porcelain=v2 &&
-+ test_all_match git commit -m "Add README.md" &&
-+
-+ test_all_match git checkout HEAD~1 &&
-+ test_all_match git checkout - &&
-+
-+ run_on_all "../edit-contents" &&
-+
-+ test_all_match git add -A &&
-+ test_all_match git status --porcelain=v2 &&
-+ test_all_match git commit -m "Extend README.md" &&
-+
-+ test_all_match git checkout HEAD~1 &&
-+ test_all_match git checkout -
-+'
-+
-+test_expect_success 'add, commit, checkout' '
-+ init_repos &&
-+
-+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+ run_on_all "../edit-contents README.md" &&
@@ t/t1092-sparse-checkout-compatibility.sh (new)
+ do
+ test_all_match git checkout rename-base &&
+ test_all_match git checkout $branch -- .&&
-+ test_all_match git diff --staged &&
++ test_all_match git diff --staged --no-renames &&
+ test_all_match git diff --staged --find-renames || return 1
+ done
+'Signature · 1 line
gitgitgadget
PATCH v2 1/8 cache-tree: clean up cache_tree_update()
From: Derrick Stolee <[email protected]>
Make the method safer by allocating a cache_tree member for the given index_state if it is not already present. This is preferrable to a BUG() statement or returning with an error because future callers will want to populate an empty cache-tree using this method.
Also drop local variables that are used exactly once and can be found directly from the 'istate' parameter.
--- cache-tree.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
cache-tree.c +9 -5
@@ -436,16 +436,20 @@ static int update_one(struct cache_tree *it,int cache_tree_update (struct index_state *istate,int flags) { -struct cache_tree *it = istate->cache_tree; -struct cache_entry **cache = istate->cache; -int entries = istate->cache_nr; -int skip, i =verify_cache (cache, entries, flags); +int skip, i; + + i =verify_cache (istate->cache, istate->cache_nr, flags);if (i)return i; + +if (!istate->cache_tree) + istate->cache_tree =cache_tree (); +trace_performance_enter ();trace2_region_enter ("cache_tree" ,"update" , the_repository); - i =update_one (it, cache, entries,"" ,0 , &skip, flags); + i =update_one (istate->cache_tree, istate->cache, istate->cache_nr, +"" ,0 , &skip, flags);trace2_region_leave ("cache_tree" ,"update" , the_repository);trace_performance_leave ("cache_tree_update" );if (i <0 )
Signature · 1 line
gitgitgadget
Re: [PATCH v2 1/8] cache-tree: clean up cache_tree_update()
Quoted 6 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Make the method safer by allocating a
cache_treemember for the givenindex_stateif it is not already present. This is preferrable to aBUG()statement or returning with an error because future callers will want to populate an empty cache-tree using this method.
How do the current callers prepare the istate to be passed to this function? The implications of this question obviously are:
- why is it unreasonable for future callers to follow suit? or
- now the callers are no longer responsible to give an empty cache_tree to istate before calling this function, shouldn't existing callers lose code that is no longer needed?
I would imagine that the first is easily answered with "but that would be more code on the callers' side", but then the second one becomes even more relevant, no?
Quoted 2 lines
Also drop local variables that are used exactly once and can be found directly from the 'istate' parameter.
It actuall is used twice, no?
I do find it an improvement because it makes it clearer that istate->{cache,cache_nr} comes in pairs.
I wonder if verify_cache() wants to take istate as a parameter, replacing the first two? update_one() shifts where it starts working in the array and reduces the number of entries as it digs deeper, so it still has to keep taking the (base, nr) pair (iow, its second and third parameters cannot be replaced with an istate).
Quoted 35 lines
Signed-off-by Derrick Stolee <[email protected]>--- cache-tree.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)cache-tree.c +9
-5@@ -436,16 +436,20 @@ static int update_one(struct cache_tree *it,int cache_tree_update (struct index_state *istate,int flags) { -struct cache_tree *it = istate->cache_tree; -struct cache_entry **cache = istate->cache; -int entries = istate->cache_nr; -int skip, i =verify_cache (cache, entries, flags); +int skip, i; + + i =verify_cache (istate->cache, istate->cache_nr, flags);if (i)return i; + +if (!istate->cache_tree) + istate->cache_tree =cache_tree (); +trace_performance_enter ();trace2_region_enter ("cache_tree" ,"update" , the_repository); - i =update_one (it, cache, entries,"" ,0 , &skip, flags); + i =update_one (istate->cache_tree, istate->cache, istate->cache_nr, +"" ,0 , &skip, flags);trace2_region_leave ("cache_tree" ,"update" , the_repository);trace_performance_leave ("cache_tree_update" );if (i <0 )
PATCH v2 2/8 cache-tree: extract subtree_pos()
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
This method will be helpful to use outside of cache-tree.c in a later feature. The implementation is subtle due to subtree_name_cmp() sorting by length and then lexicographically.
--- cache-tree.c | 6 +++--- cache-tree.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
cache-tree.c +3 -3
@@ -45,7 +45,7 @@ static int subtree_name_cmp(const char *one, int onelen,return memcmp (one, two, onelen); } -static int subtree_pos (struct cache_tree *it,const char *path,int pathlen) +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen) {struct cache_tree_sub **down = it->down;int lo, hi;
@@ -72,7 +72,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it, int create) {struct cache_tree_sub *down; -int pos =subtree_pos (it, path, pathlen); +int pos =cache_tree_subtree_pos (it, path, pathlen);if (0 <= pos)return it->down[pos];if (!create)
@@ -123,7 +123,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path) it->entry_count =-1 ;if (!*slash) {int pos; - pos =subtree_pos (it, path, namelen); + pos =cache_tree_subtree_pos (it, path, namelen);if (0 <= pos) {cache_tree_free (&it->down[pos]->cache_tree);free (it->down[pos]);
cache-tree.h +2 -0
@@ -27,6 +27,8 @@ void cache_tree_free(struct cache_tree **);void cache_tree_invalidate_path (struct index_state *,const char *);struct cache_tree_sub *cache_tree_sub (struct cache_tree *,const char *); +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen); +void cache_tree_write (struct strbuf *,struct cache_tree *root);struct cache_tree *cache_tree_read (const char *buffer,unsigned long size);
Signature · 1 line
gitgitgadget
PATCH v2 3/8 fsmonitor: de-duplicate BUG()s around dirty bits
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The index has an fsmonitor_dirty bitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
There are several BUG() statements that are very similar, so replace these uses with a simpler assert_index_minimum(). Since there is one caller that uses a custom 'pos' value instead of the bit_size member, we cannot simplify it too much. However, the error string is identical in each, so this simplifies things.
The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.
--- fsmonitor.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
fsmonitor.c +13 -14
@@ -13,14 +13,19 @@struct trace_key trace_fsmonitor =TRACE_KEY_INIT (FSMONITOR ); +static void assert_index_minimum (struct index_state *istate,size_t pos) +{ +if (pos > istate->cache_nr) +BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , + (uintmax_t )pos, istate->cache_nr); +} +static void fsmonitor_ewah_callback (size_t pos,void *is) {struct index_state *istate = (struct index_state *)is;struct cache_entry *ce; -if (pos >= istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" >= %u)" , - (uintmax_t )pos, istate->cache_nr); +assert_index_minimum (istate, pos); ce = istate->cache[pos]; ce->ce_flags &= ~CE_FSMONITOR_VALID ;
@@ -82,10 +87,8 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, } istate->fsmonitor_dirty = fsmonitor_dirty; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);trace_printf_key (&trace_fsmonitor,"read fsmonitor extension successful" );return 0 ;
@@ -110,10 +113,8 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)uint32_t ewah_size =0 ;int fixup =0 ; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);put_be32 (&hdr_version,INDEX_EXTENSION_VERSION2 );strbuf_add (sb, &hdr_version,sizeof (uint32_t ));
@@ -335,9 +336,7 @@ void tweak_fsmonitor(struct index_state *istate) }/* Mark all previously saved entries as dirty */ -if (istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);ewah_each_bit (istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);refresh_fsmonitor (istate);
Signature · 1 line
gitgitgadget
Re: [PATCH v2 3/8] fsmonitor: de-duplicate BUG()s around dirty bits
Quoted 7 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
The index has an
fsmonitor_dirtybitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
Quoted 5 lines
There are several
BUG()statements that are very similar, so replace these uses with a simplerassert_index_minimum(). Since there is one caller that uses a custom 'pos' value instead of thebit_sizemember, we cannot simplify it too much. However, the error string is identical in each, so this simplifies things.
Also that single caller with a custom 'pos' used to allow 'pos' to point one beyond the end of istate->cache[] array, but now it is forbidden. If this is a strict bugfix, it probably deserves a mention here.
Quoted 72 lines
The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.
Signed-off-by Derrick Stolee <[email protected]>--- fsmonitor.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)fsmonitor.c +13
-14@@ -13,14 +13,19 @@struct trace_key trace_fsmonitor =TRACE_KEY_INIT (FSMONITOR ); +static void assert_index_minimum (struct index_state *istate,size_t pos) +{ +if (pos > istate->cache_nr) +BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , + (uintmax_t )pos, istate->cache_nr); +} +static void fsmonitor_ewah_callback (size_t pos,void *is) {struct index_state *istate = (struct index_state *)is;struct cache_entry *ce; -if (pos >= istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" >= %u)" , - (uintmax_t )pos, istate->cache_nr); +assert_index_minimum (istate, pos); ce = istate->cache[pos]; ce->ce_flags &= ~CE_FSMONITOR_VALID ;@@ -82,10 +87,8 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, } istate->fsmonitor_dirty = fsmonitor_dirty; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);trace_printf_key (&trace_fsmonitor,"read fsmonitor extension successful" );return 0 ;@@ -110,10 +113,8 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)uint32_t ewah_size =0 ;int fixup =0 ; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);put_be32 (&hdr_version,INDEX_EXTENSION_VERSION2 );strbuf_add (sb, &hdr_version,sizeof (uint32_t ));@@ -335,9 +336,7 @@ void tweak_fsmonitor(struct index_state *istate) }/* Mark all previously saved entries as dirty */ -if (istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);ewah_each_bit (istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);refresh_fsmonitor (istate);
PATCH v2 4/8 repository: add repo reference to index_state
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index operations that might trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct index_state that allows access to this repository.
This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct index_state *istate' parameter.
--- cache.h | 1 + repository.c | 4 ++++ 2 files changed, 5 insertions(+)
cache.h +1 -0
@@ -328,6 +328,7 @@ struct index_state {struct ewah_bitmap *fsmonitor_dirty;struct mem_pool *ce_mem_pool;struct progress *progress; +struct repository *repo; };/* Name hashing */
repository.c +4 -0
@@ -264,6 +264,10 @@ int repo_read_index(struct repository *repo)if (!repo->index) repo->index =xcalloc (1 ,sizeof (*repo->index)); +/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +return read_index_from (repo->index, repo->index_file, repo->gitdir); }
Signature · 1 line
gitgitgadget
Re: [PATCH v2 4/8] repository: add repo reference to index_state
Quoted 7 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index operations that might trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct
index_statethat allows access to this repository.
Quoted 6 lines
This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct
index_state*istate' parameter.Signed-off-by Derrick Stolee <[email protected]>---
I think this makes sense, but shouldn't we insist on these bidirectional links to point at each other? Otherwise we cannot simplify the function signatures safely later. That is ...
repository.c int repo_read_index(struct repository *repo) · line 270
Quoted 4 lines
repository.c +4
-0+/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +
else if (repo->index->repo != repo)
BUG("the repo->index instance does not belong to the repo???");... a check like this?
Quoted 2 lines
return
read_index_from(repo->index, repo->index_file, repo->gitdir);
}
PATCH v2 5/8 name-hash: use trace2 regions for init
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The lazy_init_name_hash() populates a hashset with all filenames and another with all directories represented in the index. This is run only if we need to use the hashsets to check for existence or case-folding renames.
Place trace2 regions where there is already a performance trace.
--- name-hash.c | 3 +++ 1 file changed, 3 insertions(+)
name-hash.c +3 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" #include "thread-utils.h" +#include "trace2.h" struct dir_entry {struct hashmap_entry ent;
@@ -577,6 +578,7 @@ static void lazy_init_name_hash(struct index_state *istate)if (istate->name_hash_initialized)return ;trace_performance_enter (); +trace2_region_enter ("index" ,"name-hash-init" , istate->repo);hashmap_init (&istate->name_hash, cache_entry_cmp,NULL , istate->cache_nr);hashmap_init (&istate->dir_hash, dir_entry_cmp,NULL , istate->cache_nr);
@@ -597,6 +599,7 @@ static void lazy_init_name_hash(struct index_state *istate) } istate->name_hash_initialized =1 ; +trace2_region_leave ("index" ,"name-hash-init" , istate->repo);trace_performance_leave ("initialize name hash" ); }
Signature · 1 line
gitgitgadget
PATCH v2 6/8 sparse-checkout: load sparse-checkout patterns
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
A future feature will want to load the sparse-checkout patterns into a pattern_list, but the current mechanism to do so is a bit complicated. This is made difficult due to needing to find the sparse-checkout file in different ways throughout the codebase.
The logic implemented in the new get_sparse_checkout_patterns() was duplicated in populate_from_existing_patterns() in unpack-trees.c. Use the new method instead, keeping the logic around handling the struct unpack_trees_options.
The callers to get_sparse_checkout_filename() in builtin/sparse-checkout.c manipulate the sparse-checkout file directly, so it is not appropriate to replace logic in that file with get_sparse_checkout_patterns().
--- builtin/sparse-checkout.c | 5 ----- dir.c | 17 +++++++++++++++++ dir.h | 2 ++ unpack-trees.c | 6 +----- 4 files changed, 20 insertions(+), 10 deletions(-)
builtin/sparse-checkout.c +0 -5
@@ -22,11 +22,6 @@ static char const * const builtin_sparse_checkout_usage[] = { NULL }; -static char *get_sparse_checkout_filename (void ) -{ -return git_pathdup ("info/sparse-checkout" ); -} -static void write_patterns_to_file (FILE *fp,struct pattern_list *pl) {int i;
dir.c +17 -0
@@ -2998,6 +2998,23 @@ void setup_standard_excludes(struct dir_struct *dir) } } +char *get_sparse_checkout_filename (void ) +{ +return git_pathdup ("info/sparse-checkout" ); +} + +int get_sparse_checkout_patterns (struct pattern_list *pl) +{ +int res; +char *sparse_filename =get_sparse_checkout_filename (); + + pl->use_cone_patterns = core_sparse_checkout_cone; + res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , pl,NULL ); + +free (sparse_filename); +return res; +} +int remove_path (const char *name) {char *slash;
dir.h +2 -0
@@ -448,6 +448,8 @@ int is_empty_dir(const char *dir);void setup_standard_excludes (struct dir_struct *dir); +char *get_sparse_checkout_filename (void ); +int get_sparse_checkout_patterns (struct pattern_list *pl);/* Constants for remove_dir_recursively: */
unpack-trees.c +1 -5
@@ -1549,14 +1549,10 @@ static void mark_new_skip_worktree(struct pattern_list *pl,static void populate_from_existing_patterns (struct unpack_trees_options *o,struct pattern_list *pl) { -char *sparse =git_pathdup ("info/sparse-checkout" ); - - pl->use_cone_patterns = core_sparse_checkout_cone; -if (add_patterns_from_file_to_list (sparse,"" ,0 , pl,NULL ) <0 ) +if (get_sparse_checkout_patterns (pl) <0 ) o->skip_sparse_checkout =1 ;else o->pl = pl; -free (sparse); }
Signature · 1 line
gitgitgadget
PATCH v2 7/8 test-lib: test_region looks for trace2 regions
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
Most test cases can verify Git's behavior using input/output expectations or changes to the .git directory. However, sometimes we want to check that Git did or did not run a certain section of code. This is particularly important for performance-only features that we want to ensure have been enabled in certain cases.
Add a new 'test_region' function that checks if a trace2 region was entered and left in a given trace2 event log.
There is one existing test (t0500-progress-display.sh) that performs this check already, so use the helper function instead. Note that this changes the expectations slightly. The old test (incorrectly) used two patterns for the 'grep' invocation, but this performs an OR of the patterns, not an AND. This means that as long as one region_enter event was logged, the test would succeed, even if it was not due to the progress category.
More uses will be added in a later change.
t6423-merge-rename-directories.sh also greps for region_enter lines, but it verifies the number of such lines, which is not the same as an existence check.
--- t/t0500-progress-display.sh | 3 +-- t/test-lib-functions.sh | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-)
t/t0500-progress-display.sh +1 -2
@@ -303,8 +303,7 @@ test_expect_success 'progress generates traces' ' "Working hard" <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. - grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region progress "Working hard" trace.event && grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event && grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event '
t/test-lib-functions.sh +40 -0
@@ -1655,3 +1655,43 @@ test_subcommand () { grep "\[$expr\]" fi } + +# Check that the given command was invoked as part of the +# trace2-format trace on stdin. +# +# test_region [!] <category> <label> git <command> <args>... +# +# For example, to look for trace2_region_enter("index", "do_read_index", repo) +# in an invocation of "git checkout HEAD~1", run +# +# GIT_TRACE2_EVENT="$(pwd)/trace.txt" GIT_TRACE2_EVENT_NESTING=10 \ +# git checkout HEAD~1 && +# test_region index do_read_index <trace.txt +# +# If the first parameter passed is !, this instead checks that +# the given region was not entered. +# +test_region () { + local expect_exit=0 + if test "$1" = "!" + then + expect_exit=1 + shift + fi + + grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi + + grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi +}
Signature · 1 line
gitgitgadget
Re: [PATCH v2 7/8] test-lib: test_region looks for trace2 regions
t/t0500-progress-display.sh test_expect_success 'progress generates traces' ' · line 306
Quoted 11 lines · Derrick Stolee via GitGitGadget
... Note that this
changes the expectations slightly. The old test (incorrectly) used two patterns for the 'grep' invocation, but this performs an OR of the patterns, not an AND. This means that as long as oneregion_enterevent was logged, the test would succeed, even if it was not due to the progress category.t/t0500-progress-display.sh +1
-2# t0212/parse_events.perl intentionally omits regions and data. - grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region progress "Working hard" trace.event &&
So we do want "region_enter" and the "category":"progress" on the same line in the event file, but as long as "category":"progress" exists, both will pass, regardless of enter/leave. And ...
t/test-lib-functions.sh test_subcommand () { · line 1682
Quoted 9 lines
t/test-lib-functions.sh +9
-0+test_region () { + local expect_exit=0 + if test "$1" = "!" + then + expect_exit=1 + shift + fi + + grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
... this makes sure there is enter/category on a line (and leave/category on a line with another check). Makes sense.
But...
test_region '!' '\(unmatching capture)' 'two' 'three'
would try to use an invalid regexp and cause grep to exit with 2, which would mean ...
t/test-lib-functions.sh test_subcommand () { · line 1685
Quoted 3 lines
t/test-lib-functions.sh +3
-0+ exitcode=$? + + if test $exitcode != $expect_exit
... this will not trigger and we return "success" (i.e. "failed as expected")?
Clarification. The point is *NOT* that the grep pattern is not robust against funnies in $1 and $2---after all, these strings are under our control. The point is what should happen when "grep" exits with an error when asked to ensure that there is no region detected.
t/test-lib-functions.sh test_subcommand () { · line 1690
Quoted 5 lines
t/test-lib-functions.sh +5
-0+ then + return 1 + fi + + grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
The same comment on "what about an error from grep" applies to this one.
It might be easier to read to avoid having to say too many backslash-quoted double quotes:
grep -e '"region_leave".*"category":"'"$1"'","label":"'"$2"\" "$3"
This comment applies to the earlier "grep", too.
Quoted 7 lines
t/test-lib-functions.sh +7
-0+ exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi +}
Re: [PATCH v2 7/8] test-lib: test_region looks for trace2 regions
Quoted 13 lines · Junio C Hamano
t/test-lib-functions.sh test_subcommand () { · line 1682
Quoted 1 line · Derrick Stolee via GitGitGadget
t/test-lib-functions.sh +1
-0+ grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"... this makes sure there is enter/category on a line (and leave/category on a line with another check). Makes sense.
But...
test_region'!' '\(unmatching capture)' 'two' 'three'would try to use an invalid regexp and cause grep to exit with 2, which would mean ...
Quoted 6 lines
t/test-lib-functions.sh test_subcommand () { · line 1685
Quoted 3 lines
t/test-lib-functions.sh +3
-0+ exitcode=$? + + if test $exitcode != $expect_exit... this will not trigger and we return "success" (i.e. "failed as expected")?
Am I misunderstanding something here? If exitcode is 2, then this will always trigger and return 1, signaling a failure. That would propagate to the parent test and cause the test to fail. That seems like the correct intention, but I'm not 100% confident about that.
Quoted 5 lines
Clarification. The point is *NOT* that the grep pattern is not robust against funnies in $1 and $2---after all, these strings are under our control. The point is what should happen when "grep" exits with an error when asked to ensure that there is no region detected.
I'll be more robust to these in the next version. We'll expect exit code equal to zero or _not_ equal to zero, depending on the presence of '!'. This has the downside of returning success for bad input strings when '!' is specified.
Basically, the approach I'm taking for v3 is here:
if [test $expect_exit = 1] && [test $exitcode = 0] then return 1 elif [test $expect_exit = 0] && [test $exitcode != 0] then return 1 fi
Quoted 11 lines
t/test-lib-functions.sh test_subcommand () { · line 1690
Quoted 1 line
t/test-lib-functions.sh +1
-0+ grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"The same comment on "what about an error from grep" applies to this one.
It might be easier to read to avoid having to say too many backslash-quoted double quotes:
grep -e '"region_leave".*"category":"'"$1"'","label":"'"$2"\" "$3"This comment applies to the earlier "grep", too.
Thanks. This does look a bit cleaner.
-Stolee
Re: [PATCH v2 7/8] test-lib: test_region looks for trace2 regions
Quoted 7 lines · Derrick Stolee
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if test $exitcode != $expect_exit... this will not trigger and we return "success" (i.e. "failed as expected")?
Am I misunderstanding something here? If exitcode is 2, then this will always trigger and return 1, signaling a failure.
Are, please disregard. Yes, the above does the right thing already.
PATCH v2 8/8 t1092: test interesting sparse-checkout scenarios
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
These also document some behaviors that differ from a full checkout, and possibly in a way that is not intended.
The test is designed to be run with "--run=1,X" where 'X' is an interesting test case. Each test uses 'init_repos' to reset the full and sparse copies of the initial-repo that is created by the first test case. This also makes it possible to have test cases leave the working directory or index in unusual states without disturbing later cases.
--- t/t1092-sparse-checkout-compatibility.sh | 298 +++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100755 t/t1092-sparse-checkout-compatibility.sh
t/t1092-sparse-checkout-compatibility.sh new file +298 -0
@@ -0,0 +1,298 @@ +#!/bin/sh + +test_description='compare full workdir to sparse workdir' + +. ./test-lib.sh + +test_expect_success 'setup' ' + git init initial-repo && + ( + cd initial-repo && + echo a >a && + echo "after deep" >e && + echo "after folder1" >g && + mkdir folder1 folder2 deep x && + mkdir deep/deeper1 deep/deeper2 && + mkdir deep/deeper1/deepest && + echo "after deeper1" >deep/e && + echo "after deepest" >deep/deeper1/e && + cp a folder1 && + cp a folder2 && + cp a deep && + cp a deep/deeper1 && + cp a deep/deeper2 && + cp a deep/deeper1/deepest && + git add . && + git commit -m "initial commit" && + git checkout -b base && + for dir in folder1 folder2 deep + do + git checkout -b update-$dir && + echo "updated $dir" >$dir/a && + git commit -a -m "update $dir" || return 1 + done && + + git checkout -b rename-base base && + echo >folder1/larger-content <<-\EOF && + matching + lines + help + inexact + renames + EOF + cp folder1/larger-content folder2/ && + cp folder1/larger-content deep/deeper1/ && + git add . && + git commit -m "add interesting rename content" && + + git checkout -b rename-out-to-out rename-base && + mv folder1/a folder2/b && + mv folder1/larger-content folder2/edited-content && + echo >>folder2/edited-content && + git add . && + git commit -m "rename folder1/... to folder2/..." && + + git checkout -b rename-out-to-in rename-base && + mv folder1/a deep/deeper1/b && + mv folder1/larger-content deep/deeper1/edited-content && + echo >>deep/deeper1/edited-content && + git add . && + git commit -m "rename folder1/... to deep/deeper1/..." && + + git checkout -b rename-in-to-out rename-base && + mv deep/deeper1/a folder1/b && + mv deep/deeper1/larger-content folder1/edited-content && + echo >>folder1/edited-content && + git add . && + git commit -m "rename deep/deeper1/... to folder1/..." && + + git checkout -b deepest base && + echo "updated deepest" >deep/deeper1/deepest/a && + git commit -a -m "update deepest" && + + git checkout -f base && + git reset --hard + ) +' + +init_repos () { + rm -rf full-checkout sparse-checkout sparse-index && + + # create repos in initial state + cp -r initial-repo full-checkout && + git -C full-checkout reset --hard && + + cp -r initial-repo sparse-checkout && + git -C sparse-checkout reset --hard && + git -C sparse-checkout sparse-checkout init --cone && + + # initialize sparse-checkout definitions + git -C sparse-checkout sparse-checkout set deep +} + +run_on_sparse () { + ( + cd sparse-checkout && + $* >../sparse-checkout-out 2>../sparse-checkout-err + ) +} + +run_on_all () { + ( + cd full-checkout && + $* >../full-checkout-out 2>../full-checkout-err + ) && + run_on_sparse $* +} + +test_all_match () { + run_on_all $* && + test_cmp full-checkout-out sparse-checkout-out && + test_cmp full-checkout-err sparse-checkout-err +} + +test_expect_success 'status with options' ' + init_repos && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + run_on_all "touch README.md" && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno +' + +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + run_on_all "../edit-contents README.md" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents README.md" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents deep/newfile" && + + test_all_match git status --porcelain=v2 -uno && + test_all_match git status --porcelain=v2 && + test_all_match git add . && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "add deep/newfile" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +' + +test_expect_success 'checkout and reset --hard' ' + init_repos && + + test_all_match git checkout update-folder1 && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout update-deep && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout -b reset-test && + test_all_match git reset --hard deepest && + test_all_match git reset --hard update-folder1 && + test_all_match git reset --hard update-folder2 +' + +test_expect_success 'diff --staged' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git diff && + test_all_match git diff --staged && + test_all_match git add README.md && + test_all_match git diff && + test_all_match git diff --staged +' + +test_expect_success 'diff with renames' ' + init_repos && + + for branch in rename-out-to-out rename-out-to-in rename-in-to-out + do + test_all_match git checkout rename-base && + test_all_match git checkout $branch -- .&& + test_all_match git diff --staged --no-renames && + test_all_match git diff --staged --find-renames || return 1 + done +' + +test_expect_success 'log with pathspec outside sparse definition' ' + init_repos && + + test_all_match git log -- a && + test_all_match git log -- folder1/a && + test_all_match git log -- folder2/a && + test_all_match git log -- deep/a && + test_all_match git log -- deep/deeper1/a && + test_all_match git log -- deep/deeper1/deepest/a && + + test_all_match git checkout update-folder1 && + test_all_match git log -- folder1/a +' + +test_expect_success 'blame with pathspec inside sparse definition' ' + init_repos && + + test_all_match git blame a && + test_all_match git blame deep/a && + test_all_match git blame deep/deeper1/a && + test_all_match git blame deep/deeper1/deepest/a +' + +# TODO: blame currently does not support blaming files outside of the +# sparse definition. It complains that the file doesn't exist locally. +test_expect_failure 'blame with pathspec outside sparse definition' ' + init_repos && + + test_all_match git blame folder1/a && + test_all_match git blame folder2/a && + test_all_match git blame deep/deeper2/a && + test_all_match git blame deep/deeper2/deepest/a +' + +# TODO: reset currently does not behave as expected when in a +# sparse-checkout. +test_expect_failure 'checkout and reset (mixed)' ' + init_repos && + + test_all_match git checkout -b reset-test update-deep && + test_all_match git reset deepest && + test_all_match git reset update-folder1 && + test_all_match git reset update-folder2 +' + +test_expect_success 'merge' ' + init_repos && + + test_all_match git checkout -b merge update-deep && + test_all_match git merge -m "folder1" update-folder1 && + test_all_match git rev-parse HEAD^{tree} && + test_all_match git merge -m "folder2" update-folder2 && + test_all_match git rev-parse HEAD^{tree} +' + +test_expect_success 'merge with outside renames' ' + init_repos && + + for type in out-to-out out-to-in in-to-out + do + test_all_match git reset --hard && + test_all_match git checkout -f -b merge-$type update-deep && + test_all_match git merge -m "$type" rename-$type && + test_all_match git rev-parse HEAD^{tree} || return 1 + done +' + +test_expect_success 'clean' ' + init_repos && + + echo bogus >>.gitignore && + run_on_all cp ../.gitignore . && + test_all_match git add .gitignore && + test_all_match git commit -m ignore-bogus-files && + + run_on_sparse mkdir folder1 && + run_on_all touch folder1/bogus && + + test_all_match git status --porcelain=v2 && + test_all_match git clean -f && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xf && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xdf && + test_all_match git status --porcelain=v2 && + + test_path_is_dir sparse-checkout/folder1 +' + +test_done
Signature · 1 line
gitgitgadget
Quoted 25 lines · Derrick Stolee via GitGitGadget
This is based on ds/cache-tree-basics.
Here are a few more cleanups that are vaguely related to the index. I discovered these while preparing my sparse-index RFC that I intend to send early next week.
The biggest patch is the final one, which creates a test script for comparing sparse-checkouts to full checkouts. There are some commands that do not behave similarly. This script will be the backbone of my testing strategy for the sparse-index by adding a new mode to compare sparse-checkouts with the two index types (full and sparse).
UPDATES IN V2
=============* Fixed duplicated test in t1092.
* Changed the implementation of '
test_region' after I discovered the negation doesn't work correctly. (I updated the test to use what was int0500-progress-display.shat the last minute before v1, but that implementation was wrong.) The use of it int0500-progress-display.shwas incorrect, as well.
Quoted 5 lines
* Updated commit messages to be more informative and have fewer typos.
* I dropped the patch that placed the sparse-checkout patterns in struct
index_state. I'll re-introduce that in time for the actual use of the member.
You've addressed all my feedback from v1, but it looks like you missed the pos + 1 changes highlighted by Chris in his review of patch 3. Oversight?
Quoted 4 lines · Elijah Newren
You've addressed all my feedback from v1, but it looks like you missed the pos + 1 changes highlighted by Chris in his review of patch 3. Oversight?
Yes, oversight. Thank you for the reminder.
-Stolee
v3 cover More index cleanups
In reply to Derrick Stolee via GitGitGadgetThis is based on ds/cache-tree-basics.
Here are a few more cleanups that are vaguely related to the index. I discovered these while preparing my sparse-index RFC that I intend to send early next week.
The biggest patch is the final one, which creates a test script for comparing sparse-checkouts to full checkouts. There are some commands that do not behave similarly. This script will be the backbone of my testing strategy for the sparse-index by adding a new mode to compare sparse-checkouts with the two index types (full and sparse).
UPDATES IN V3
=============
* Callers to cache_tree_update() no longer initialize the cache_tree in advance.
* Added a patch to update verify_cache() prototype.
* Added missing "pos + 1" in fsmonitor.c.
* Added a BUG() statement when repo->istate->repo is already populated, but not equal to repo.
* Cleaned up test_region pattern quoting. Thanks, Junio!
Thanks, -Stolee
Derrick Stolee (9):
cache-tree: clean up cache_tree_update()
cache-tree: simplify verify_cache() prototype
cache-tree: extract subtree_pos()
fsmonitor: de-duplicate BUG()s around dirty bits
repository: add repo reference to index_state
name-hash: use trace2 regions for init
sparse-checkout: load sparse-checkout patterns
test-lib: test_region looks for trace2 regions
t1092: test interesting sparse-checkout scenarios
builtin/checkout.c | 3 - builtin/sparse-checkout.c | 5 - cache-tree.c | 38 +-- cache-tree.h | 2 + cache.h | 1 + dir.c | 17 ++ dir.h | 2 + fsmonitor.c | 27 +- name-hash.c | 3 + repository.c | 6 + sequencer.c | 3 - t/t0500-progress-display.sh | 3 +- t/t1092-sparse-checkout-compatibility.sh | 301 +++++++++++++++++++++++ t/test-lib-functions.sh | 42 ++++ unpack-trees.c | 8 +- 15 files changed, 408 insertions(+), 53 deletions(-) create mode 100755 t/t1092-sparse-checkout-compatibility.sh
base-commit: a4b6d202caad83c6dc29abe9b17e53a1b3fb54a0
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-839%2Fderrickstolee%2Fmore-index-cleanups-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-839/derrickstolee/more-index-cleanups-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/839
Range-diff vs v2:
1: f9dccaed0ac ! 1: bdc8ecca3d2 cache-tree: clean up cache_tree_update()
@@ Commit message
BUG() statement or returning with an error because future callers will want to populate an empty cache-tree using this method.
- Also drop local variables that are used exactly once and can be found
- directly from the 'istate' parameter.
+ Callers can also remove their conditional allocations of cache_tree.
+
+ Also drop local variables that can be found directly from the 'istate'
+ parameter.
+ ## builtin/checkout.c ##
+@@ builtin/checkout.c: 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(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
+
+
## cache-tree.c ##
@@ cache-tree.c: static int update_one(struct cache_tree *it,
@@ cache-tree.c: static int update_one(struct cache_tree *it,
trace2_region_leave("cache_tree", "update", the_repository); trace_performance_leave("cache_tree_update");
if (i < 0)
+@@ cache-tree.c: static int write_index_as_tree_internal(struct object_id *oid,
+ cache_tree_valid = 0;
+ }
+
+- if (!index_state->cache_tree)
+- index_state->cache_tree = cache_tree();
+-
+ if (!cache_tree_valid && cache_tree_update(index_state, flags) < 0)
+ return WRITE_TREE_UNMERGED_INDEX;
+
+
+ ## sequencer.c ##
+@@ sequencer.c: static int do_recursive_merge(struct repository *r,
+
+ static struct object_id *get_cache_tree_oid(struct index_state *istate)
+ {
+- if (!istate->cache_tree)
+- istate->cache_tree = cache_tree();
+-
+ if (!cache_tree_fully_valid(istate->cache_tree))
+ if (cache_tree_update(istate, 0)) {
+ error(_("unable to update cache tree"));
+
+ ## unpack-trees.c ##
+@@ unpack-trees.c: int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
+ if (!ret) {
+ if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
+ cache_tree_verify(the_repository, &o->result);
+- if (!o->result.cache_tree)
+- o->result.cache_tree = cache_tree();
+ if (!cache_tree_fully_valid(o->result.cache_tree))
+ cache_tree_update(&o->result,
+ WRITE_TREE_SILENT |
-: ----------- > 2: 1b8b5680094 cache-tree: simplify verify_cache() prototype 2: 84323e04d08 = 3: 314b6b34f75 cache-tree: extract subtree_pos() 3: 31095f9aa0e ! 4: 4e688d25f8c fsmonitor: de-duplicate BUG()s around dirty bits
@@ Commit message
cannot simplify it too much. However, the error string is identical in each, so this simplifies things.
+ Be sure to add one when checking if a position if valid, since the
+ minimum is a bound on the expected size.
+
The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.
@@ fsmonitor.c
- if (pos >= istate->cache_nr)
- BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" >= %u)",
- (uintmax_t)pos, istate->cache_nr);
-+ assert_index_minimum(istate, pos);
++ assert_index_minimum(istate, pos + 1);
ce = istate->cache[pos];
ce->ce_flags &= ~CE_FSMONITOR_VALID;
4: a0d89d7a973 ! 5: 6373997e05c repository: add repo reference to index_state
@@ Commit message
repository, add a 'repo' pointer to struct index_state that allows access to this repository.
+ Add a BUG() statement if the repo already has an index, and the index
+ already has a repo, but somehow the index points to a different repo.
+
This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct index_state *istate' parameter.
@@ repository.c: int repo_read_index(struct repository *repo)
+ /* Complete the double-reference */
+ if (!repo->index->repo)
+ repo->index->repo = repo;
++ else if (repo->index->repo != repo)
++ BUG("repo's index should point back at itself");
+
return read_index_from(repo->index, repo->index_file, repo->gitdir);
}
5: bc092f5c703 = 6: 9b545d7dbec name-hash: use trace2 regions for init
6: 04d1daf7222 = 7: 554cc7647e6 sparse-checkout: load sparse-checkout patterns
7: 8832ce84623 ! 8: b37181bdec4 test-lib: test_region looks for trace2 regions
@@ t/test-lib-functions.sh: test_subcommand () {
+ shift
+ fi
+
-+ grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
++ grep -e '"region_enter".*"category":"'"$1"'","label":"'"$2"\" "$3"
+ exitcode=$?
+
-+ if test $exitcode != $expect_exit
++ if test $exitcode != $expect_exit = 1]
+ then
+ return 1
+ fi
+
-+ grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
++ grep -e '"region_leave".*"category":"'"$1"'","label":"'"$2"\" "$3"
+ exitcode=$?
+
-+ if test $exitcode != $expect_exit
++ if test $exitcode != $expect_exit = 1]
+ then
+ return 1
+ fi
++
++ return 0
+}
8: 984458007ed ! 9: 72f925353d3 t1092: test interesting sparse-checkout scenarios
@@ t/t1092-sparse-checkout-compatibility.sh (new)
+ echo a >a &&
+ echo "after deep" >e &&
+ echo "after folder1" >g &&
++ echo "after x" >z &&
+ mkdir folder1 folder2 deep x &&
+ mkdir deep/deeper1 deep/deeper2 &&
+ mkdir deep/deeper1/deepest &&
@@ t/t1092-sparse-checkout-compatibility.sh (new)
+ echo "after deepest" >deep/deeper1/e &&
+ cp a folder1 &&
+ cp a folder2 &&
++ cp a x &&
+ cp a deep &&
+ cp a deep/deeper1 &&
+ cp a deep/deeper2 &&
+ cp a deep/deeper1/deepest &&
++ cp -r deep/deeper1/deepest deep/deeper2 &&
+ git add . &&
+ git commit -m "initial commit" &&
+ git checkout -b base &&Signature · 1 line
gitgitgadget
PATCH v3 1/9 cache-tree: clean up cache_tree_update()
From: Derrick Stolee <[email protected]>
Make the method safer by allocating a cache_tree member for the given index_state if it is not already present. This is preferrable to a BUG() statement or returning with an error because future callers will want to populate an empty cache-tree using this method.
Callers can also remove their conditional allocations of cache_tree.
Also drop local variables that can be found directly from the 'istate' parameter.
--- builtin/checkout.c | 3 --- cache-tree.c | 17 +++++++++-------- sequencer.c | 3 --- unpack-trees.c | 2 -- 4 files changed, 9 insertions(+), 16 deletions(-)
builtin/checkout.c +0 -3
@@ -821,9 +821,6 @@ 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 (&the_index,WRITE_TREE_SILENT |WRITE_TREE_REPAIR );
cache-tree.c +9 -8
@@ -436,16 +436,20 @@ static int update_one(struct cache_tree *it,int cache_tree_update (struct index_state *istate,int flags) { -struct cache_tree *it = istate->cache_tree; -struct cache_entry **cache = istate->cache; -int entries = istate->cache_nr; -int skip, i =verify_cache (cache, entries, flags); +int skip, i; + + i =verify_cache (istate->cache, istate->cache_nr, flags);if (i)return i; + +if (!istate->cache_tree) + istate->cache_tree =cache_tree (); +trace_performance_enter ();trace2_region_enter ("cache_tree" ,"update" , the_repository); - i =update_one (it, cache, entries,"" ,0 , &skip, flags); + i =update_one (istate->cache_tree, istate->cache, istate->cache_nr, +"" ,0 , &skip, flags);trace2_region_leave ("cache_tree" ,"update" , the_repository);trace_performance_leave ("cache_tree_update" );if (i <0 )
@@ -635,9 +639,6 @@ static int write_index_as_tree_internal(struct object_id *oid, cache_tree_valid =0 ; } -if (!index_state->cache_tree) - index_state->cache_tree =cache_tree (); -if (!cache_tree_valid &&cache_tree_update (index_state, flags) <0 )return WRITE_TREE_UNMERGED_INDEX ;
sequencer.c +0 -3
@@ -679,9 +679,6 @@ static int do_recursive_merge(struct repository *r,static struct object_id *get_cache_tree_oid (struct index_state *istate) { -if (!istate->cache_tree) - istate->cache_tree =cache_tree (); -if (!cache_tree_fully_valid (istate->cache_tree))if (cache_tree_update (istate,0 )) {error (_ ("unable to update cache tree" ));
unpack-trees.c +0 -2
@@ -1726,8 +1726,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_optionsif (!ret) {if (git_env_bool ("GIT_TEST_CHECK_CACHE_TREE" ,0 ))cache_tree_verify (the_repository, &o->result); -if (!o->result.cache_tree) - o->result.cache_tree =cache_tree ();if (!cache_tree_fully_valid (o->result.cache_tree)) cache_tree_update(&o->result, WRITE_TREE_SILENT |
Signature · 1 line
gitgitgadget
PATCH v3 2/9 cache-tree: simplify verify_cache() prototype
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The verify_cache() method takes an array of cache entries and a count, but these are always provided directly from a struct index_state. Use a pointer to the full structure instead.
There is a subtle point when istate->cache_nr is zero that subtracting one will underflow. This triggers a failure in t0000-basic.sh, among others. Use "i + 1 < istate->cache_nr" to avoid these strange comparisons. Convert i to be unsigned as well, which also removes the potential signed overflow in the unlikely case that cache_nr is over 2.1 billion entries. The 'funny' variable has a maximum value of 11, so making it unsigned does not change anything of importance.
--- cache-tree.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
cache-tree.c +8 -9
@@ -151,16 +151,15 @@ void cache_tree_invalidate_path(struct index_state *istate, const char *path) istate->cache_changed |=CACHE_TREE_CHANGED ; } -static int verify_cache (struct cache_entry **cache, -int entries,int flags) +static int verify_cache (struct index_state *istate,int flags) { -int i, funny; +unsigned i, funny;int silent = flags &WRITE_TREE_SILENT ;/* Verify that the tree is merged */ funny =0 ; -for (i =0 ; i < entries; i++) { -const struct cache_entry *ce = cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];if (ce_stage (ce)) {if (silent)return -1 ;
@@ -180,13 +179,13 @@ static int verify_cache(struct cache_entry **cache,* stage 0 entries. */ funny =0 ; -for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];const char *this_name = this_ce->name;const char *next_name = next_ce->name;int this_len =ce_namelen (this_ce);
@@ -438,7 +437,7 @@ int cache_tree_update(struct index_state *istate, int flags) {int skip, i; - i =verify_cache (istate->cache, istate->cache_nr, flags); + i =verify_cache (istate, flags);if (i)return i;
Signature · 1 line
gitgitgadget
Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
Quoted 7 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
The
verify_cache()method takes an array of cache entries and a count, but these are always provided directly from a structindex_state. Use a pointer to the full structure instead.
Quoted 6 lines
There is a subtle point when
istate->cache_nris zero that subtracting one will underflow. This triggers a failure int0000-basic.sh, among others. Use "i + 1 <istate->cache_nr" to avoid these strange comparisons. Convert i to be unsigned as well, which also removes the potential signed overflow in the unlikely case thatcache_nris over 2.1 billion entries. The 'funny' variable has a maximum value of 11, so
AND a minimum value of 0 (which is important for the type change to be valid).
Quoted 59 lines
making it unsigned does not change anything of importance.
Signed-off-by Derrick Stolee <[email protected]>--- cache-tree.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)cache-tree.c +8
-10@@ -151,16 +151,15 @@ void cache_tree_invalidate_path(struct index_state *istate, const char *path) istate->cache_changed |=CACHE_TREE_CHANGED ; } -static int verify_cache (struct cache_entry **cache, -int entries,int flags) +static int verify_cache (struct index_state *istate,int flags) { -int i, funny; +unsigned i, funny;int silent = flags &WRITE_TREE_SILENT ;/* Verify that the tree is merged */ funny =0 ; -for (i =0 ; i < entries; i++) { -const struct cache_entry *ce = cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];if (ce_stage (ce)) {if (silent)return -1 ;@@ -180,13 +179,13 @@ static int verify_cache(struct cache_entry **cache,* stage 0 entries. */ funny =0 ; -for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];const char *this_name = this_ce->name;const char *next_name = next_ce->name;int this_len =ce_namelen (this_ce);@@ -438,7 +437,7 @@ int cache_tree_update(struct index_state *istate, int flags) {int skip, i; - i =verify_cache (istate->cache, istate->cache_nr, flags); + i =verify_cache (istate, flags);if (i)return i; --
Quoted 1 line
gitgitgadget
Makes sense. Thanks for explaining the i + 1 < istate->cache_nr bit in the commit message; made it easier to read through quickly. I'm curious if it deserves a comment in the code too, since it does feel slightly unusual.
Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
Quoted 15 lines · Elijah Newren
cache-tree.c static int verify_cache(struct cache_entry **cache, · line 191
Quoted 13 lines · Derrick Stolee via GitGitGadget
cache-tree.c +3
-3-for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];const char *this_name = this_ce->name;const char *next_name = next_ce->name;int this_len =ce_namelen (this_ce);
Quoted 4 lines
Makes sense. Thanks for explaining the i + 1 <
istate->cache_nrbit in the commit message; made it easier to read through quickly. I'm curious if it deserves a comment in the code too, since it does feel slightly unusual.
I would argue that "i + 1 < N" is a more natural way to write this, because we use "i + 1" as an index, so we want to ensure the index we are about to use is within range. "i < N - 1" is the backwards way to write that statement.
Thanks,
-Stolee
Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
Quoted 22 lines · Derrick Stolee
Quoted 15 lines · Elijah Newren
cache-tree.c static int verify_cache(struct cache_entry **cache, · line 191
Quoted 13 lines · Derrick Stolee via GitGitGadget
cache-tree.c +3
-3-for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];const char *this_name = this_ce->name;const char *next_name = next_ce->name;int this_len =ce_namelen (this_ce);Quoted 4 lines
Makes sense. Thanks for explaining the i + 1 <
istate->cache_nrbit in the commit message; made it easier to read through quickly. I'm curious if it deserves a comment in the code too, since it does feel slightly unusual.
Quoted 4 lines
I would argue that "i + 1 < N" is a more natural way to write this, because we use "i + 1" as an index, so we want to ensure the index we are about to use is within range. "i < N - 1" is the backwards way to write that statement.
Oh, right, I think I was reading too quickly and assuming one thing in my head (about what the code was going to do), and forgetting that assumption when I got to the actual code. Sorry about that; I agree with you, so ignore my previous comment.
Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
In reply to Derrick StoleeQuoted 21 lines · Derrick Stolee
Quoted 15 lines · Elijah Newren
cache-tree.c static int verify_cache(struct cache_entry **cache, · line 191
Quoted 13 lines · Derrick Stolee via GitGitGadget
cache-tree.c +3
-3-for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];const char *this_name = this_ce->name;const char *next_name = next_ce->name;int this_len =ce_namelen (this_ce);Quoted 4 lines
Makes sense. Thanks for explaining the i + 1 <
istate->cache_nrbit in the commit message; made it easier to read through quickly. I'm curious if it deserves a comment in the code too, since it does feel slightly unusual.
Quoted 4 lines
I would argue that "i + 1 < N" is a more natural way to write this, because we use "i + 1" as an index, so we want to ensure the index we are about to use is within range. "i < N - 1" is the backwards way to write that statement.
Our mails have crossed, I guess. Comparing i+1 and N is also good.
Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
In reply to Elijah NewrenQuoted 11 lines · Elijah Newren
cache-tree.c static int verify_cache(struct cache_entry **cache, · line 188
Quoted 10 lines
cache-tree.c +3
-3-for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];
Quoted 4 lines
Makes sense. Thanks for explaining the i + 1 <
istate->cache_nrbit in the commit message; made it easier to read through quickly. I'm curious if it deserves a comment in the code too, since it does feel slightly unusual.
I think this is entirely my fault.
It probably reads more natural to start from 1 and interate through to the end of the array, comparing the current one with the previous entry, i.e.
for (i = 1; i < istate->cache_nr; i++) {
prev = cache[i - 1];
this = cache[i];
compare(prev, this);Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
Quoted 20 lines · Junio C Hamano
Quoted 11 lines · Elijah Newren
cache-tree.c static int verify_cache(struct cache_entry **cache, · line 188
Quoted 10 lines
cache-tree.c +3
-3-for (i =0 ; i < entries -1 ; i++) { +for (i =0 ; i +1 < istate->cache_nr; i++) {/* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ -const struct cache_entry *this_ce = cache[i]; -const struct cache_entry *next_ce = cache[i +1 ]; +const struct cache_entry *this_ce = istate->cache[i]; +const struct cache_entry *next_ce = istate->cache[i +1 ];Quoted 4 lines
Makes sense. Thanks for explaining the i + 1 <
istate->cache_nrbit in the commit message; made it easier to read through quickly. I'm curious if it deserves a comment in the code too, since it does feel slightly unusual.I think this is entirely my fault.
Quoted 8 lines
It probably reads more natural to start from 1 and interate through to the end of the array, comparing the current one with the previous entry, i.e.
for (i = 1; i < istate->cache_nr; i++) { prev = cache[i - 1]; this = cache[i]; compare(prev, this);
This would be another natural way to make the loop extremely clear.
It's a bigger diff, changing the names of 'this' and 'next', but perhaps worthwhile.
Thanks,
-Stolee
PATCH v3 3/9 cache-tree: extract subtree_pos()
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
This method will be helpful to use outside of cache-tree.c in a later feature. The implementation is subtle due to subtree_name_cmp() sorting by length and then lexicographically.
--- cache-tree.c | 6 +++--- cache-tree.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
cache-tree.c +3 -3
@@ -45,7 +45,7 @@ static int subtree_name_cmp(const char *one, int onelen,return memcmp (one, two, onelen); } -static int subtree_pos (struct cache_tree *it,const char *path,int pathlen) +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen) {struct cache_tree_sub **down = it->down;int lo, hi;
@@ -72,7 +72,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it, int create) {struct cache_tree_sub *down; -int pos =subtree_pos (it, path, pathlen); +int pos =cache_tree_subtree_pos (it, path, pathlen);if (0 <= pos)return it->down[pos];if (!create)
@@ -123,7 +123,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path) it->entry_count =-1 ;if (!*slash) {int pos; - pos =subtree_pos (it, path, namelen); + pos =cache_tree_subtree_pos (it, path, namelen);if (0 <= pos) {cache_tree_free (&it->down[pos]->cache_tree);free (it->down[pos]);
cache-tree.h +2 -0
@@ -27,6 +27,8 @@ void cache_tree_free(struct cache_tree **);void cache_tree_invalidate_path (struct index_state *,const char *);struct cache_tree_sub *cache_tree_sub (struct cache_tree *,const char *); +int cache_tree_subtree_pos (struct cache_tree *it,const char *path,int pathlen); +void cache_tree_write (struct strbuf *,struct cache_tree *root);struct cache_tree *cache_tree_read (const char *buffer,unsigned long size);
Signature · 1 line
gitgitgadget
PATCH v3 4/9 fsmonitor: de-duplicate BUG()s around dirty bits
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The index has an fsmonitor_dirty bitmap that records which index entries are "dirty" based on the response from the FSMonitor. If this bitmap ever grows larger than the index, then there was an error in how it was constructed, and it was probably a developer's bug.
There are several BUG() statements that are very similar, so replace these uses with a simpler assert_index_minimum(). Since there is one caller that uses a custom 'pos' value instead of the bit_size member, we cannot simplify it too much. However, the error string is identical in each, so this simplifies things.
Be sure to add one when checking if a position if valid, since the minimum is a bound on the expected size.
The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.
--- fsmonitor.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
fsmonitor.c +13 -14
@@ -13,14 +13,19 @@struct trace_key trace_fsmonitor =TRACE_KEY_INIT (FSMONITOR ); +static void assert_index_minimum (struct index_state *istate,size_t pos) +{ +if (pos > istate->cache_nr) +BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , + (uintmax_t )pos, istate->cache_nr); +} +static void fsmonitor_ewah_callback (size_t pos,void *is) {struct index_state *istate = (struct index_state *)is;struct cache_entry *ce; -if (pos >= istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" >= %u)" , - (uintmax_t )pos, istate->cache_nr); +assert_index_minimum (istate, pos +1 ); ce = istate->cache[pos]; ce->ce_flags &= ~CE_FSMONITOR_VALID ;
@@ -82,10 +87,8 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, } istate->fsmonitor_dirty = fsmonitor_dirty; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);trace_printf_key (&trace_fsmonitor,"read fsmonitor extension successful" );return 0 ;
@@ -110,10 +113,8 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)uint32_t ewah_size =0 ;int fixup =0 ; -if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +if (!istate->split_index) +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);put_be32 (&hdr_version,INDEX_EXTENSION_VERSION2 );strbuf_add (sb, &hdr_version,sizeof (uint32_t ));
@@ -335,9 +336,7 @@ void tweak_fsmonitor(struct index_state *istate) }/* Mark all previously saved entries as dirty */ -if (istate->fsmonitor_dirty->bit_size > istate->cache_nr) -BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX" > %u)" , - (uintmax_t )istate->fsmonitor_dirty->bit_size, istate->cache_nr); +assert_index_minimum (istate, istate->fsmonitor_dirty->bit_size);ewah_each_bit (istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);refresh_fsmonitor (istate);
Signature · 1 line
gitgitgadget
PATCH v3 5/9 repository: add repo reference to index_state
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
It will be helpful to add behavior to index operations that might trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct index_state that allows access to this repository.
Add a BUG() statement if the repo already has an index, and the index already has a repo, but somehow the index points to a different repo.
This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct index_state *istate' parameter.
--- cache.h | 1 + repository.c | 6 ++++++ 2 files changed, 7 insertions(+)
cache.h +1 -0
@@ -328,6 +328,7 @@ struct index_state {struct ewah_bitmap *fsmonitor_dirty;struct mem_pool *ce_mem_pool;struct progress *progress; +struct repository *repo; };/* Name hashing */
repository.c +6 -0
@@ -264,6 +264,12 @@ int repo_read_index(struct repository *repo)if (!repo->index) repo->index =xcalloc (1 ,sizeof (*repo->index)); +/* Complete the double-reference */ +if (!repo->index->repo) + repo->index->repo = repo; +else if (repo->index->repo != repo) +BUG ("repo's index should point back at itself" ); +return read_index_from (repo->index, repo->index_file, repo->gitdir); }
Signature · 1 line
gitgitgadget
PATCH v3 6/9 name-hash: use trace2 regions for init
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
The lazy_init_name_hash() populates a hashset with all filenames and another with all directories represented in the index. This is run only if we need to use the hashsets to check for existence or case-folding renames.
Place trace2 regions where there is already a performance trace.
--- name-hash.c | 3 +++ 1 file changed, 3 insertions(+)
name-hash.c +3 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" #include "thread-utils.h" +#include "trace2.h" struct dir_entry {struct hashmap_entry ent;
@@ -577,6 +578,7 @@ static void lazy_init_name_hash(struct index_state *istate)if (istate->name_hash_initialized)return ;trace_performance_enter (); +trace2_region_enter ("index" ,"name-hash-init" , istate->repo);hashmap_init (&istate->name_hash, cache_entry_cmp,NULL , istate->cache_nr);hashmap_init (&istate->dir_hash, dir_entry_cmp,NULL , istate->cache_nr);
@@ -597,6 +599,7 @@ static void lazy_init_name_hash(struct index_state *istate) } istate->name_hash_initialized =1 ; +trace2_region_leave ("index" ,"name-hash-init" , istate->repo);trace_performance_leave ("initialize name hash" ); }
Signature · 1 line
gitgitgadget
PATCH v3 7/9 sparse-checkout: load sparse-checkout patterns
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
A future feature will want to load the sparse-checkout patterns into a pattern_list, but the current mechanism to do so is a bit complicated. This is made difficult due to needing to find the sparse-checkout file in different ways throughout the codebase.
The logic implemented in the new get_sparse_checkout_patterns() was duplicated in populate_from_existing_patterns() in unpack-trees.c. Use the new method instead, keeping the logic around handling the struct unpack_trees_options.
The callers to get_sparse_checkout_filename() in builtin/sparse-checkout.c manipulate the sparse-checkout file directly, so it is not appropriate to replace logic in that file with get_sparse_checkout_patterns().
--- builtin/sparse-checkout.c | 5 ----- dir.c | 17 +++++++++++++++++ dir.h | 2 ++ unpack-trees.c | 6 +----- 4 files changed, 20 insertions(+), 10 deletions(-)
builtin/sparse-checkout.c +0 -5
@@ -22,11 +22,6 @@ static char const * const builtin_sparse_checkout_usage[] = { NULL }; -static char *get_sparse_checkout_filename (void ) -{ -return git_pathdup ("info/sparse-checkout" ); -} -static void write_patterns_to_file (FILE *fp,struct pattern_list *pl) {int i;
dir.c +17 -0
@@ -2998,6 +2998,23 @@ void setup_standard_excludes(struct dir_struct *dir) } } +char *get_sparse_checkout_filename (void ) +{ +return git_pathdup ("info/sparse-checkout" ); +} + +int get_sparse_checkout_patterns (struct pattern_list *pl) +{ +int res; +char *sparse_filename =get_sparse_checkout_filename (); + + pl->use_cone_patterns = core_sparse_checkout_cone; + res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , pl,NULL ); + +free (sparse_filename); +return res; +} +int remove_path (const char *name) {char *slash;
dir.h +2 -0
@@ -448,6 +448,8 @@ int is_empty_dir(const char *dir);void setup_standard_excludes (struct dir_struct *dir); +char *get_sparse_checkout_filename (void ); +int get_sparse_checkout_patterns (struct pattern_list *pl);/* Constants for remove_dir_recursively: */
unpack-trees.c +1 -5
@@ -1549,14 +1549,10 @@ static void mark_new_skip_worktree(struct pattern_list *pl,static void populate_from_existing_patterns (struct unpack_trees_options *o,struct pattern_list *pl) { -char *sparse =git_pathdup ("info/sparse-checkout" ); - - pl->use_cone_patterns = core_sparse_checkout_cone; -if (add_patterns_from_file_to_list (sparse,"" ,0 , pl,NULL ) <0 ) +if (get_sparse_checkout_patterns (pl) <0 ) o->skip_sparse_checkout =1 ;else o->pl = pl; -free (sparse); }
Signature · 1 line
gitgitgadget
PATCH v3 8/9 test-lib: test_region looks for trace2 regions
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
Most test cases can verify Git's behavior using input/output expectations or changes to the .git directory. However, sometimes we want to check that Git did or did not run a certain section of code. This is particularly important for performance-only features that we want to ensure have been enabled in certain cases.
Add a new 'test_region' function that checks if a trace2 region was entered and left in a given trace2 event log.
There is one existing test (t0500-progress-display.sh) that performs this check already, so use the helper function instead. Note that this changes the expectations slightly. The old test (incorrectly) used two patterns for the 'grep' invocation, but this performs an OR of the patterns, not an AND. This means that as long as one region_enter event was logged, the test would succeed, even if it was not due to the progress category.
More uses will be added in a later change.
t6423-merge-rename-directories.sh also greps for region_enter lines, but it verifies the number of such lines, which is not the same as an existence check.
--- t/t0500-progress-display.sh | 3 +-- t/test-lib-functions.sh | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-)
t/t0500-progress-display.sh +1 -2
@@ -303,8 +303,7 @@ test_expect_success 'progress generates traces' ' "Working hard" <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. - grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region progress "Working hard" trace.event && grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event && grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event '
t/test-lib-functions.sh +42 -0
45 lines not on this page · raw message
Signature · 1 line
gitgitgadget
Re: [PATCH v3 8/9] test-lib: test_region looks for trace2 regions
On 1/23/2021 2:58 PM, Derrick Stolee via GitGitGadget wrote:
...
Quoted 1 line
(quoted diff) +1
-0+ if test $exitcode != $expect_exit = 1]
...
Review
Quoted 1 line
(quoted diff) +1
-0+ if test $exitcode != $expect_exit = 1]
As Elijah pointed out, these lines are bogus. I'm not sure how they passed the tests without failure, but here is a replacement for this patch:
--- >8 ---
From ff15d509b89edd4830d85d53cea3079a6b0c1c08 Mon Sep 17 00:00:00 2001
From: Derrick Stolee <[email protected]>
Date: Mon, 11 Jan 2021 08:53:09 -0500
Subject: [PATCH 8/9] test-lib: test_region looks for trace2 regions
Most test cases can verify Git's behavior using input/output expectations or changes to the .git directory. However, sometimes we want to check that Git did or did not run a certain section of code. This is particularly important for performance-only features that we want to ensure have been enabled in certain cases.
Add a new 'test_region' function that checks if a trace2 region was entered and left in a given trace2 event log.
There is one existing test (t0500-progress-display.sh) that performs this check already, so use the helper function instead. Note that this changes the expectations slightly. The old test (incorrectly) used two patterns for the 'grep' invocation, but this performs an OR of the patterns, not an AND. This means that as long as one region_enter event was logged, the test would succeed, even if it was not due to the progress category.
More uses will be added in a later change.
t6423-merge-rename-directories.sh also greps for region_enter lines, but it verifies the number of such lines, which is not the same as an existence check.
--- t/t0500-progress-display.sh | 3 +-- t/test-lib-functions.sh | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-)
t/t0500-progress-display.sh +1 -2
@@ -303,8 +303,7 @@ test_expect_success 'progress generates traces' ' "Working hard" <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. - grep -e "region_enter" -e "\"category\":\"progress\"" trace.event && - grep -e "region_leave" -e "\"category\":\"progress\"" trace.event && + test_region progress "Working hard" trace.event && grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event && grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event '
t/test-lib-functions.sh +42 -0
45 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH v3 9/9 t1092: test interesting sparse-checkout scenarios
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
These also document some behaviors that differ from a full checkout, and possibly in a way that is not intended.
The test is designed to be run with "--run=1,X" where 'X' is an interesting test case. Each test uses 'init_repos' to reset the full and sparse copies of the initial-repo that is created by the first test case. This also makes it possible to have test cases leave the working directory or index in unusual states without disturbing later cases.
--- t/t1092-sparse-checkout-compatibility.sh | 301 +++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100755 t/t1092-sparse-checkout-compatibility.sh
t/t1092-sparse-checkout-compatibility.sh new file +301 -0
@@ -0,0 +1,301 @@ +#!/bin/sh + +test_description='compare full workdir to sparse workdir' + +. ./test-lib.sh + +test_expect_success 'setup' ' + git init initial-repo && + ( + cd initial-repo && + echo a >a && + echo "after deep" >e && + echo "after folder1" >g && + echo "after x" >z && + mkdir folder1 folder2 deep x && + mkdir deep/deeper1 deep/deeper2 && + mkdir deep/deeper1/deepest && + echo "after deeper1" >deep/e && + echo "after deepest" >deep/deeper1/e && + cp a folder1 && + cp a folder2 && + cp a x && + cp a deep && + cp a deep/deeper1 && + cp a deep/deeper2 && + cp a deep/deeper1/deepest && + cp -r deep/deeper1/deepest deep/deeper2 && + git add . && + git commit -m "initial commit" && + git checkout -b base && + for dir in folder1 folder2 deep + do + git checkout -b update-$dir && + echo "updated $dir" >$dir/a && + git commit -a -m "update $dir" || return 1 + done && + + git checkout -b rename-base base && + echo >folder1/larger-content <<-\EOF && + matching + lines + help + inexact + renames + EOF + cp folder1/larger-content folder2/ && + cp folder1/larger-content deep/deeper1/ && + git add . && + git commit -m "add interesting rename content" && + + git checkout -b rename-out-to-out rename-base && + mv folder1/a folder2/b && + mv folder1/larger-content folder2/edited-content && + echo >>folder2/edited-content && + git add . && + git commit -m "rename folder1/... to folder2/..." && + + git checkout -b rename-out-to-in rename-base && + mv folder1/a deep/deeper1/b && + mv folder1/larger-content deep/deeper1/edited-content && + echo >>deep/deeper1/edited-content && + git add . && + git commit -m "rename folder1/... to deep/deeper1/..." && + + git checkout -b rename-in-to-out rename-base && + mv deep/deeper1/a folder1/b && + mv deep/deeper1/larger-content folder1/edited-content && + echo >>folder1/edited-content && + git add . && + git commit -m "rename deep/deeper1/... to folder1/..." && + + git checkout -b deepest base && + echo "updated deepest" >deep/deeper1/deepest/a && + git commit -a -m "update deepest" && + + git checkout -f base && + git reset --hard + ) +' + +init_repos () { + rm -rf full-checkout sparse-checkout sparse-index && + + # create repos in initial state + cp -r initial-repo full-checkout && + git -C full-checkout reset --hard && + + cp -r initial-repo sparse-checkout && + git -C sparse-checkout reset --hard && + git -C sparse-checkout sparse-checkout init --cone && + + # initialize sparse-checkout definitions + git -C sparse-checkout sparse-checkout set deep +} + +run_on_sparse () { + ( + cd sparse-checkout && + $* >../sparse-checkout-out 2>../sparse-checkout-err + ) +} + +run_on_all () { + ( + cd full-checkout && + $* >../full-checkout-out 2>../full-checkout-err + ) && + run_on_sparse $* +} + +test_all_match () { + run_on_all $* && + test_cmp full-checkout-out sparse-checkout-out && + test_cmp full-checkout-err sparse-checkout-err +} + +test_expect_success 'status with options' ' + init_repos && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + run_on_all "touch README.md" && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno +' + +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + run_on_all "../edit-contents README.md" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents README.md" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents deep/newfile" && + + test_all_match git status --porcelain=v2 -uno && + test_all_match git status --porcelain=v2 && + test_all_match git add . && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "add deep/newfile" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +' + +test_expect_success 'checkout and reset --hard' ' + init_repos && + + test_all_match git checkout update-folder1 && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout update-deep && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout -b reset-test && + test_all_match git reset --hard deepest && + test_all_match git reset --hard update-folder1 && + test_all_match git reset --hard update-folder2 +' + +test_expect_success 'diff --staged' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git diff && + test_all_match git diff --staged && + test_all_match git add README.md && + test_all_match git diff && + test_all_match git diff --staged +' + +test_expect_success 'diff with renames' ' + init_repos && + + for branch in rename-out-to-out rename-out-to-in rename-in-to-out + do + test_all_match git checkout rename-base && + test_all_match git checkout $branch -- .&& + test_all_match git diff --staged --no-renames && + test_all_match git diff --staged --find-renames || return 1 + done +' + +test_expect_success 'log with pathspec outside sparse definition' ' + init_repos && + + test_all_match git log -- a && + test_all_match git log -- folder1/a && + test_all_match git log -- folder2/a && + test_all_match git log -- deep/a && + test_all_match git log -- deep/deeper1/a && + test_all_match git log -- deep/deeper1/deepest/a && + + test_all_match git checkout update-folder1 && + test_all_match git log -- folder1/a +' + +test_expect_success 'blame with pathspec inside sparse definition' ' + init_repos && + + test_all_match git blame a && + test_all_match git blame deep/a && + test_all_match git blame deep/deeper1/a && + test_all_match git blame deep/deeper1/deepest/a +' + +# TODO: blame currently does not support blaming files outside of the +# sparse definition. It complains that the file doesn't exist locally. +test_expect_failure 'blame with pathspec outside sparse definition' ' + init_repos && + + test_all_match git blame folder1/a && + test_all_match git blame folder2/a && + test_all_match git blame deep/deeper2/a && + test_all_match git blame deep/deeper2/deepest/a +' + +# TODO: reset currently does not behave as expected when in a +# sparse-checkout. +test_expect_failure 'checkout and reset (mixed)' ' + init_repos && + + test_all_match git checkout -b reset-test update-deep && + test_all_match git reset deepest && + test_all_match git reset update-folder1 && + test_all_match git reset update-folder2 +' + +test_expect_success 'merge' ' + init_repos && + + test_all_match git checkout -b merge update-deep && + test_all_match git merge -m "folder1" update-folder1 && + test_all_match git rev-parse HEAD^{tree} && + test_all_match git merge -m "folder2" update-folder2 && + test_all_match git rev-parse HEAD^{tree} +' + +test_expect_success 'merge with outside renames' ' + init_repos && + + for type in out-to-out out-to-in in-to-out + do + test_all_match git reset --hard && + test_all_match git checkout -f -b merge-$type update-deep && + test_all_match git merge -m "$type" rename-$type && + test_all_match git rev-parse HEAD^{tree} || return 1 + done +' + +test_expect_success 'clean' ' + init_repos && + + echo bogus >>.gitignore && + run_on_all cp ../.gitignore . && + test_all_match git add .gitignore && + test_all_match git commit -m ignore-bogus-files && + + run_on_sparse mkdir folder1 && + run_on_all touch folder1/bogus && + + test_all_match git status --porcelain=v2 && + test_all_match git clean -f && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xf && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xdf && + test_all_match git status --porcelain=v2 && + + test_path_is_dir sparse-checkout/folder1 +' + +test_done
Signature · 1 line
gitgitgadget
Re: [PATCH v3 9/9] t1092: test interesting sparse-checkout scenarios
Quoted 7 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
These also document some behaviors that differ from a full checkout, and possibly in a way that is not intended.
The test is designed to be run with "--run=1,X" where 'X' is an
Random sidenote: Why not suggest "--run=setup,X" instead? Then if you ever add additional "setup" steps, it'd run all of them.
Quoted 320 lines
interesting test case. Each test uses '
init_repos' to reset the full and sparse copies of the initial-repo that is created by the first test case. This also makes it possible to have test cases leave the working directory or index in unusual states without disturbing later cases.Signed-off-by Derrick Stolee <[email protected]>--- t/t1092-sparse-checkout-compatibility.sh | 301 +++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100755 t/t1092-sparse-checkout-compatibility.sht/t1092-sparse-checkout-compatibility.sh new file +301
-1@@ -0,0 +1,301 @@ +#!/bin/sh + +test_description='compare full workdir to sparse workdir' + +. ./test-lib.sh + +test_expect_success 'setup' ' + git init initial-repo && + ( + cd initial-repo && + echo a >a && + echo "after deep" >e && + echo "after folder1" >g && + echo "after x" >z && + mkdir folder1 folder2 deep x && + mkdir deep/deeper1 deep/deeper2 && + mkdir deep/deeper1/deepest && + echo "after deeper1" >deep/e && + echo "after deepest" >deep/deeper1/e && + cp a folder1 && + cp a folder2 && + cp a x && + cp a deep && + cp a deep/deeper1 && + cp a deep/deeper2 && + cp a deep/deeper1/deepest && + cp -r deep/deeper1/deepest deep/deeper2 && + git add . && + git commit -m "initial commit" && + git checkout -b base && + for dir in folder1 folder2 deep + do + git checkout -b update-$dir && + echo "updated $dir" >$dir/a && + git commit -a -m "update $dir" || return 1 + done && + + git checkout -b rename-base base && + echo >folder1/larger-content <<-\EOF && + matching + lines + help + inexact + renames + EOF + cp folder1/larger-content folder2/ && + cp folder1/larger-content deep/deeper1/ && + git add . && + git commit -m "add interesting rename content" && + + git checkout -b rename-out-to-out rename-base && + mv folder1/a folder2/b && + mv folder1/larger-content folder2/edited-content && + echo >>folder2/edited-content && + git add . && + git commit -m "rename folder1/... to folder2/..." && + + git checkout -b rename-out-to-in rename-base && + mv folder1/a deep/deeper1/b && + mv folder1/larger-content deep/deeper1/edited-content && + echo >>deep/deeper1/edited-content && + git add . && + git commit -m "rename folder1/... to deep/deeper1/..." && + + git checkout -b rename-in-to-out rename-base && + mv deep/deeper1/a folder1/b && + mv deep/deeper1/larger-content folder1/edited-content && + echo >>folder1/edited-content && + git add . && + git commit -m "rename deep/deeper1/... to folder1/..." && + + git checkout -b deepest base && + echo "updated deepest" >deep/deeper1/deepest/a && + git commit -a -m "update deepest" && + + git checkout -f base && + git reset --hard + ) +' + +init_repos () { + rm -rf full-checkout sparse-checkout sparse-index && + + # create repos in initial state + cp -r initial-repo full-checkout && + git -C full-checkout reset --hard && + + cp -r initial-repo sparse-checkout && + git -C sparse-checkout reset --hard && + git -C sparse-checkout sparse-checkout init --cone && + + # initialize sparse-checkout definitions + git -C sparse-checkout sparse-checkout set deep +} + +run_on_sparse () { + ( + cd sparse-checkout && + $* >../sparse-checkout-out 2>../sparse-checkout-err + ) +} + +run_on_all () { + ( + cd full-checkout && + $* >../full-checkout-out 2>../full-checkout-err + ) && + run_on_sparse $* +} + +test_all_match () { + run_on_all $* && + test_cmp full-checkout-out sparse-checkout-out && + test_cmp full-checkout-err sparse-checkout-err +} + +test_expect_success 'status with options' ' + init_repos && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + run_on_all "touch README.md" && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno && + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git status --porcelain=v2 -z -u && + test_all_match git status --porcelain=v2 -uno +' + +test_expect_success 'add, commit, checkout' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + run_on_all "../edit-contents README.md" && + + test_all_match git add README.md && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Add README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents README.md" && + + test_all_match git add -A && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "Extend README.md" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - && + + run_on_all "../edit-contents deep/newfile" && + + test_all_match git status --porcelain=v2 -uno && + test_all_match git status --porcelain=v2 && + test_all_match git add . && + test_all_match git status --porcelain=v2 && + test_all_match git commit -m "add deep/newfile" && + + test_all_match git checkout HEAD~1 && + test_all_match git checkout - +' + +test_expect_success 'checkout and reset --hard' ' + init_repos && + + test_all_match git checkout update-folder1 && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout update-deep && + test_all_match git status --porcelain=v2 && + + test_all_match git checkout -b reset-test && + test_all_match git reset --hard deepest && + test_all_match git reset --hard update-folder1 && + test_all_match git reset --hard update-folder2 +' + +test_expect_success 'diff --staged' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>README.md + EOF + run_on_all "../edit-contents" && + + test_all_match git diff && + test_all_match git diff --staged && + test_all_match git add README.md && + test_all_match git diff && + test_all_match git diff --staged +' + +test_expect_success 'diff with renames' ' + init_repos && + + for branch in rename-out-to-out rename-out-to-in rename-in-to-out + do + test_all_match git checkout rename-base && + test_all_match git checkout $branch -- .&& + test_all_match git diff --staged --no-renames && + test_all_match git diff --staged --find-renames || return 1 + done +' + +test_expect_success 'log with pathspec outside sparse definition' ' + init_repos && + + test_all_match git log -- a && + test_all_match git log -- folder1/a && + test_all_match git log -- folder2/a && + test_all_match git log -- deep/a && + test_all_match git log -- deep/deeper1/a && + test_all_match git log -- deep/deeper1/deepest/a && + + test_all_match git checkout update-folder1 && + test_all_match git log -- folder1/a +' + +test_expect_success 'blame with pathspec inside sparse definition' ' + init_repos && + + test_all_match git blame a && + test_all_match git blame deep/a && + test_all_match git blame deep/deeper1/a && + test_all_match git blame deep/deeper1/deepest/a +' + +# TODO: blame currently does not support blaming files outside of the +# sparse definition. It complains that the file doesn't exist locally. +test_expect_failure 'blame with pathspec outside sparse definition' ' + init_repos && + + test_all_match git blame folder1/a && + test_all_match git blame folder2/a && + test_all_match git blame deep/deeper2/a && + test_all_match git blame deep/deeper2/deepest/a +' + +# TODO: reset currently does not behave as expected when in a +# sparse-checkout. +test_expect_failure 'checkout and reset (mixed)' ' + init_repos && + + test_all_match git checkout -b reset-test update-deep && + test_all_match git reset deepest && + test_all_match git reset update-folder1 && + test_all_match git reset update-folder2 +' + +test_expect_success 'merge' ' + init_repos && + + test_all_match git checkout -b merge update-deep && + test_all_match git merge -m "folder1" update-folder1 && + test_all_match git rev-parse HEAD^{tree} && + test_all_match git merge -m "folder2" update-folder2 && + test_all_match git rev-parse HEAD^{tree} +' + +test_expect_success 'merge with outside renames' ' + init_repos && + + for type in out-to-out out-to-in in-to-out + do + test_all_match git reset --hard && + test_all_match git checkout -f -b merge-$type update-deep && + test_all_match git merge -m "$type" rename-$type && + test_all_match git rev-parse HEAD^{tree} || return 1 + done +' + +test_expect_success 'clean' ' + init_repos && + + echo bogus >>.gitignore && + run_on_all cp ../.gitignore . && + test_all_match git add .gitignore && + test_all_match git commit -m ignore-bogus-files && + + run_on_sparse mkdir folder1 && + run_on_all touch folder1/bogus && + + test_all_match git status --porcelain=v2 && + test_all_match git clean -f && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xf && + test_all_match git status --porcelain=v2 && + + test_all_match git clean -xdf && + test_all_match git status --porcelain=v2 && + + test_path_is_dir sparse-checkout/folder1 +' + +test_done --gitgitgadget
Quoted 176 lines · Derrick Stolee via GitGitGadget
This is based on ds/cache-tree-basics.
Here are a few more cleanups that are vaguely related to the index. I discovered these while preparing my sparse-index RFC that I intend to send early next week.
The biggest patch is the final one, which creates a test script for comparing sparse-checkouts to full checkouts. There are some commands that do not behave similarly. This script will be the backbone of my testing strategy for the sparse-index by adding a new mode to compare sparse-checkouts with the two index types (full and sparse).
UPDATES IN V3
=============* Callers to
cache_tree_update()no longer initialize thecache_treein advance.* Added a patch to update
verify_cache()prototype.* Added missing "pos + 1" in
fsmonitor.c.* Added a
BUG()statement whenrepo->istate->repois already populated, but not equal to repo.* Cleaned up
test_regionpattern quoting. Thanks, Junio!Thanks, -Stolee
Derrick Stolee (9):
cache-tree: clean upcache_tree_update()
cache-tree: simplifyverify_cache()prototype
cache-tree: extractsubtree_pos()
fsmonitor: de-duplicate BUG()s around dirty bits
repository: add repo reference toindex_state
name-hash: use trace2 regions for init
sparse-checkout: load sparse-checkout patterns
test-lib:test_regionlooks for trace2 regions
t1092: test interesting sparse-checkout scenariosbuiltin/checkout.c | 3 - builtin/sparse-checkout.c | 5 - cache-tree.c | 38 +-- cache-tree.h | 2 + cache.h | 1 + dir.c | 17 ++ dir.h | 2 + fsmonitor.c | 27 +- name-hash.c | 3 + repository.c | 6 + sequencer.c | 3 - t/t0500-progress-display.sh | 3 +- t/t1092-sparse-checkout-compatibility.sh | 301 +++++++++++++++++++++++ t/test-lib-functions.sh | 42 ++++ unpack-trees.c | 8 +- 15 files changed, 408 insertions(+), 53 deletions(-) create mode 100755 t/t1092-sparse-checkout-compatibility.shbase-commit:
a4b6d202caad83c6dc29abe9b17e53a1b3fb54a0
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-839%2Fderrickstolee%2Fmore-index-cleanups-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-839/derrickstolee/more-index-cleanups-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/839Range-diff vs v2:
1:
f9dccaed0ac! 1:bdc8ecca3d2cache-tree: clean upcache_tree_update()
@@ Commit message
BUG()statement or returning with an error because future callers will want to populate an empty cache-tree using this method.- Also drop local variables that are used exactly once and can be found
- directly from the 'istate' parameter.
+ Callers can also remove their conditional allocations ofcache_tree.
+
+ Also drop local variables that can be found directly from the 'istate'
+ parameter.Signed-off-by Derrick Stolee <[email protected]>+ ##
builtin/checkout.c##
+@@builtin/checkout.c: static int merge_working_tree(const structcheckout_opts*opts,
+ }
+ }
+
+- if (!active_cache_tree)
+-active_cache_tree=cache_tree();
+-
+ if (!cache_tree_fully_valid(active_cache_tree))
+cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
+
+
##cache-tree.c##
@@cache-tree.c: static int update_one(structcache_tree*it,@@
cache-tree.c: static int update_one(structcache_tree*it,
trace2_region_leave("cache_tree", "update", the_repository);trace_performance_leave("cache_tree_update");
if (i < 0)
+@@cache-tree.c: static int write_index_as_tree_internal(structobject_id*oid,
+cache_tree_valid= 0;
+ }
+
+- if (!index_state->cache_tree)
+-index_state->cache_tree=cache_tree();
+-
+ if (!cache_tree_valid &&cache_tree_update(index_state, flags)< 0)
+ returnWRITE_TREE_UNMERGED_INDEX;
+
+
+ ##sequencer.c##
+@@sequencer.c: static int do_recursive_merge(struct repository *r,
+
+ static structobject_id*get_cache_tree_oid(structindex_state*istate)
+ {
+- if (!istate->cache_tree)
+-istate->cache_tree=cache_tree();
+-
+ if (!cache_tree_fully_valid(istate->cache_tree))
+ if (cache_tree_update(istate, 0)) {
+error(_("unable to update cache tree"));
+
+ ##unpack-trees.c##
+@@unpack-trees.c: int unpack_trees(unsigned len, structtree_desc*t, structunpack_trees_options
+ if (!ret) {
+ if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
+cache_tree_verify(the_repository, &o->result);
+- if (!o->result.cache_tree)
+-o->result.cache_tree=cache_tree();
+ if (!cache_tree_fully_valid(o->result.cache_tree))
+ cache_tree_update(&o->result,
+WRITE_TREE_SILENT|-: ----------- > 2: 1b8b5680094 cache-tree: simplify verify_cache() prototype 2: 84323e04d08 = 3: 314b6b34f75 cache-tree: extract subtree_pos() 3: 31095f9aa0e ! 4: 4e688d25f8c fsmonitor: de-duplicate BUG()s around dirty bits@@ Commit message
cannot simplify it too much. However, the error string is identical in each, so this simplifies things.+ Be sure to add one when checking if a position if valid, since the
+ minimum is a bound on the expected size.
+
The end result is that the code is simpler to read while also preserving these assertions for developers in the FSMonitor space.@@
fsmonitor.c
- if (pos >=istate->cache_nr)
- BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" >= %u)",
- (uintmax_t)pos,istate->cache_nr);
-+assert_index_minimum(istate, pos);
++assert_index_minimum(istate, pos + 1);ce = istate->cache[pos];
ce->ce_flags&= ~CE_FSMONITOR_VALID;
4:a0d89d7a973! 5:6373997e05crepository: add repo reference toindex_state
@@ Commit message
repository, add a 'repo' pointer to structindex_statethat allows access to this repository.+ Add a
BUG()statement if the repo already has an index, and the index
+ already has a repo, but somehow the index points to a different repo.
+
This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'structindex_state*istate' parameter.
@@repository.c: intrepo_read_index(struct repository *repo)
+ /* Complete the double-reference */
+ if (!repo->index->repo)
+repo->index->repo= repo;
++ else if (repo->index->repo!= repo)
++BUG("repo's index should point back at itself");
+
returnread_index_from(repo->index, repo->index_file, repo->gitdir);
}
Quoted 13 lines
5: bc092f5c703 = 6: 9b545d7dbec name-hash: use trace2 regions for init
6: 04d1daf7222 = 7: 554cc7647e6 sparse-checkout: load sparse-checkout patterns
7: 8832ce84623 ! 8: b37181bdec4 test-lib: test_region looks for trace2 regions
@@ t/test-lib-functions.sh: test_subcommand () {
+ shift
+ fi
+
-+ grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
++ grep -e '"region_enter".*"category":"'"$1"'","label":"'"$2"\" "$3"
+ exitcode=$?
+
-+ if test $exitcode != $expect_exit
++ if test $exitcode != $expect_exit = 1]I don't understand this change. Is it even valid code? What does it mean?
Quoted 10 lines
+ then
+ return 1
+ fi
+
-+ grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3"
++ grep -e '"region_leave".*"category":"'"$1"'","label":"'"$2"\" "$3"
+ exitcode=$?
+
-+ if test $exitcode != $expect_exit
++ if test $exitcode != $expect_exit = 1]Same comment.
Quoted 20 lines
+ then
+ return 1
+ fi
++
++ return 0
+}
8:984458007ed! 9:72f925353d3t1092: test interesting sparse-checkout scenarios
@@t/t1092-sparse-checkout-compatibility.sh(new)
+ echo a >a &&
+ echo "after deep" >e &&
+ echo "after folder1" >g &&
++ echo "after x" >z &&
+ mkdir folder1 folder2 deep x &&
+ mkdir deep/deeper1 deep/deeper2 &&
+ mkdir deep/deeper1/deepest &&
@@t/t1092-sparse-checkout-compatibility.sh(new)
+ echo "after deepest" >deep/deeper1/e &&
+ cp a folder1 &&
+ cp a folder2 &&
++ cp a x &&
Quoted 9 lines
+ cp a deep &&
+ cp a deep/deeper1 &&
+ cp a deep/deeper2 &&
+ cp a deep/deeper1/deepest &&
++ cp -r deep/deeper1/deepest deep/deeper2 &&
+ git add . &&
+ git commit -m "initial commit" &&
+ git checkout -b base &&
Having read the previous rounds, the rest of the range-diff looks good to me; I sent out separate comments on the new patch.
Quoted 4 lines · Elijah Newren
Quoted 2 lines · Derrick Stolee via GitGitGadget
This is based on ds/cache-tree-basics.
...
Quoted 20 lines
Quoted 6 lines
-+ grep -e "\"region_enter\".*\"category\":\"$1\",\"label\":\"$2\"" "$3" ++ grep -e '"region_enter".*"category":"'"$1"'","label":"'"$2"\" "$3" + exitcode=$? + -+ if test $exitcode != $expect_exit ++ if test $exitcode != $expect_exit = 1]I don't understand this change. Is it even valid code? What does it mean?
Quoted 10 lines
+ then + return 1 + fi + -+ grep -e "\"region_leave\".*\"category\":\"$1\",\"label\":\"$2\"" "$3" ++ grep -e '"region_leave".*"category":"'"$1"'","label":"'"$2"\" "$3" + exitcode=$? + -+ if test $exitcode != $expect_exit ++ if test $exitcode != $expect_exit = 1]
Quoted 1 line
Same comment
Wow. I am sorry this snuck in. It's an artifact of what I was trying [1] in response to Junio's comments, but then did not completely undo. I'm surprised this ran without error. Will fix.
Quoted 7 lines · Derrick Stolee
Quoted 4 lines
Quoted 2 lines
-+ if test $exitcode != $expect_exit ++ if test $exitcode != $expect_exit = 1]Same comment
Wow. I am sorry this snuck in. It's an artifact of what I was trying [1] in response to Junio's comments, but then did not completely undo.
Sorry about that.