Sparse checkout fixes
cover Sparse checkout fixes
[on top of nd/maint-fix-add-typo-detection]
This fixes a sparse pattern sometimes won't match a directory if
- it does not end with a slash
- it has wildcards
The series also improves performance a bit, thanks to 3/5, skip-worktree bits are precomputed.
Improvements in the previous round [1] are left out. I will need to polish them a bit more.
[1] http://thread.gmane.org/gmane.comp.version-control.git/161477
Nguyễn Thái Ngọc Duy (5):
cache.h: remove surrounding brackes and realign CE_* constants dir.c: add free_excludes()
unpack-trees: move all skip-worktree checks back to unpack_trees()
unpack-trees: fix sparse checkout's "unable to match directories" Revert "excluded_1(): support exclude files in index"
Documentation/git-read-tree.txt | 7 - cache.h | 26 ++-- dir.c | 19 ++- dir.h | 1 + t/t1011-read-tree-sparse-checkout.sh | 14 ++- unpack-trees.c | 240 ++++++++++++++++++++++++++++++---- 6 files changed, 254 insertions(+), 53 deletions(-)
Signature · 1 line
1.7.3.2.316.gda8b3
PATCH 1/5 cache.h: remove surrounding brackes and realign CE_* constants
--- cache.h | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-)
cache.h +12 -13
@@ -170,26 +170,25 @@ struct cache_entry {* * In-memory only flags */ -#define CE_UPDATE (0x10000) -#define CE_REMOVE (0x20000) -#define CE_UPTODATE (0x40000) -#define CE_ADDED (0x80000) +#define CE_UPDATE 0x10000 +#define CE_REMOVE 0x20000 +#define CE_UPTODATE 0x40000 +#define CE_ADDED 0x80000 -#define CE_HASHED (0x100000) -#define CE_UNHASHED (0x200000) -#define CE_CONFLICTED (0x800000) +#define CE_HASHED 0x100000 +#define CE_UNHASHED 0x200000 +#define CE_WT_REMOVE 0x400000/* remove in work directory */ +#define CE_CONFLICTED 0x800000 -#define CE_WT_REMOVE (0x400000)/* remove in work directory */ - -#define CE_UNPACKED (0x1000000) +#define CE_UNPACKED 0x1000000/* * Extended on-disk flags */ -#define CE_INTENT_TO_ADD 0x20000000 -#define CE_SKIP_WORKTREE 0x40000000 +#define CE_INTENT_TO_ADD 0x20000000 +#define CE_SKIP_WORKTREE 0x40000000/* CE_EXTENDED2 is for future extension */ -#define CE_EXTENDED2 0x80000000 +#define CE_EXTENDED2 0x80000000#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
Signature · 1 line
1.7.3.2.316.gda8b3
Re: [PATCH 1/5] cache.h: remove surrounding brackes and realign CE_* constants
2010/11/26 Nguyễn Thái Ngọc Duy <[email protected]>:
Quoted 13 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
cache.h | 25 ++++++++++++-------------1 files changed, 12 insertions(+), 13 deletions(-)cache.h +0
-0@@ -170,26 +170,25 @@ struct cache_entry { * * In-memory only flags
cache.h struct cache_entry { · line 177
Quoted 10 lines
cache.h +4
-4*/ -#define CE_UPDATE (0x10000) -#define CE_REMOVE (0x20000) -#define CE_UPTODATE (0x40000) -#define CE_ADDED (0x80000) +#define CE_UPDATE 0x10000 +#define CE_REMOVE 0x20000 +#define CE_UPTODATE 0x40000 +#define CE_ADDED 0x80000
Thanks for fixing this. Maybe these hex can be rewriting as 1 << 0, 1 << 1 and so on?
PATCH 1/5 cache.h: realign and use (1 << x) form for CE_* constants
---
2010/11/27 Thiago Farina <[email protected]>:
Quoted 3 lines
Thanks for fixing this. Maybe these hex can be rewriting as 1 << 0, 1 << 1 and so on?
It does look better. There a few 0xXXXX constants above, but they are short enough.
cache.h | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-)
cache.h +12 -13
@@ -170,26 +170,25 @@ struct cache_entry {* * In-memory only flags */ -#define CE_UPDATE (0x10000) -#define CE_REMOVE (0x20000) -#define CE_UPTODATE (0x40000) -#define CE_ADDED (0x80000) +#define CE_UPDATE (1 << 16) +#define CE_REMOVE (1 << 17) +#define CE_UPTODATE (1 << 18) +#define CE_ADDED (1 << 19) -#define CE_HASHED (0x100000) -#define CE_UNHASHED (0x200000) -#define CE_CONFLICTED (0x800000) +#define CE_HASHED (1 << 20) +#define CE_UNHASHED (1 << 21) +#define CE_WT_REMOVE (1 << 22)/* remove in work directory */ +#define CE_CONFLICTED (1 << 23) -#define CE_WT_REMOVE (0x400000)/* remove in work directory */ - -#define CE_UNPACKED (0x1000000) +#define CE_UNPACKED (1 << 24)/* * Extended on-disk flags */ -#define CE_INTENT_TO_ADD 0x20000000 -#define CE_SKIP_WORKTREE 0x40000000 +#define CE_INTENT_TO_ADD (1 << 29) +#define CE_SKIP_WORKTREE (1 << 30)/* CE_EXTENDED2 is for future extension */ -#define CE_EXTENDED2 0x80000000 +#define CE_EXTENDED2 (1 << 31)#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
Signature · 1 line
1.7.3.2.316.gda8b3
PATCH 2/5 dir.c: add free_excludes()
In reply to Nguyễn Thái Ngọc Duy--- dir.c | 12 ++++++++++++ dir.h | 1 + unpack-trees.c | 6 +----- 3 files changed, 14 insertions(+), 5 deletions(-)
dir.c +12 -0
@@ -223,6 +223,18 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size)return data; } +void free_excludes (struct exclude_list *el) +{ +int i; + +for (i =0 ; i < el->nr; i++) +free (el->excludes[i]); +free (el->excludes); + + el->nr =0 ; + el->excludes =NULL ; +} + int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
dir.h +1 -0
@@ -78,6 +78,7 @@ extern int add_excludes_from_file_to_list(const char *fname, const char *base, iextern void add_excludes_from_file (struct dir_struct *,const char *fname);extern void add_exclude (const char *string,const char *base,int baselen,struct exclude_list *which); +extern void free_excludes (struct exclude_list *el);extern int file_exists (const char *);extern char *get_relative_cwd (char *buffer,int size,const char *dir);
unpack-trees.c +1 -5
@@ -945,11 +945,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o->dst_index = o->result; done: -for (i =0 ;i < el.nr;i++) -free (el.excludes[i]); -if (el.excludes) -free (el.excludes); - +free_excludes (&el);return ret; return_failed:
Signature · 1 line
1.7.3.2.316.gda8b3
PATCH 3/5 unpack-trees: move all skip-worktree checks back to unpack_trees()
In reply to Nguyễn Thái Ngọc DuyEarlier, the will_have_skip_worktree() checks are done in various places, which makes it hard to traverse the index tree-alike, required by excluded_from_list(). This patch moves all the checks into two loops in unpack_trees().
Entries in index in this operation can be classified into two
groups: ones already in index before unpack_trees() is called and ones added to index after traverse_trees() is called.
In both groups, before checking file status on worktree, the future skip-worktree bit must be checked, so that if an entry will be outside worktree, worktree should not be checked.
For the first group, the future skip-worktree bit is precomputed and stored as CE_NEW_SKIP_WORKTREE in the first loop before traverse_trees() is called so that *way_merge() function does not need to compute it again.
For the second group, because we don't know what entries will be in this group until traverse_trees() finishes, operations that need future skip-worktree check is delayed until CE_NEW_SKIP_WORKTREE is computed in the second loop. CE_ADDED is used to mark entries in the second group.
CE_ADDED and CE_NEW_SKIP_WORKTREE are temporary flags used in unpack_trees(). CE_ADDED is only used by add_to_index(), which should not be called while unpack_trees() is running.
--- cache.h | 1 + unpack-trees.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 9 deletions(-)
cache.h +1 -0
@@ -181,6 +181,7 @@ struct cache_entry {#define CE_CONFLICTED 0x800000#define CE_UNPACKED 0x1000000 +#define CE_NEW_SKIP_WORKTREE 0x2000000/* * Extended on-disk flags
unpack-trees.c +73 -9
142 lines not on this page · raw message
Signature · 1 line
1.7.3.2.316.gda8b3
PATCH 3/5 unpack-trees: move all skip-worktree checks back to unpack_trees()
Earlier, the will_have_skip_worktree() checks are done in various places, which makes it hard to traverse the index tree-alike, required by excluded_from_list(). This patch moves all the checks into two loops in unpack_trees().
Entries in index in this operation can be classified into two
groups: ones already in index before unpack_trees() is called and ones added to index after traverse_trees() is called.
In both groups, before checking file status on worktree, the future skip-worktree bit must be checked, so that if an entry will be outside worktree, worktree should not be checked.
For the first group, the future skip-worktree bit is precomputed and stored as CE_NEW_SKIP_WORKTREE in the first loop before traverse_trees() is called so that *way_merge() function does not need to compute it again.
For the second group, because we don't know what entries will be in this group until traverse_trees() finishes, operations that need future skip-worktree check is delayed until CE_NEW_SKIP_WORKTREE is computed in the second loop. CE_ADDED is used to mark entries in the second group.
CE_ADDED and CE_NEW_SKIP_WORKTREE are temporary flags used in unpack_trees(). CE_ADDED is only used by add_to_index(), which should not be called while unpack_trees() is running.
---
CE_NEW_SKIP_WORKTREE is changed to (1 << 25) instead of 0x2000000
cache.h | 1 + unpack-trees.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 9 deletions(-)
cache.h +1 -0
@@ -181,6 +181,7 @@ struct cache_entry {#define CE_CONFLICTED (1 << 23)#define CE_UNPACKED (1 << 24) +#define CE_NEW_SKIP_WORKTREE (1 << 25)/* * Extended on-disk flags
unpack-trees.c +73 -9
142 lines not on this page · raw message
Signature · 1 line
1.7.3.2.316.gda8b3
PATCH 4/5 unpack-trees: fix sparse checkout's "unable to match directories"
In reply to Nguyễn Thái Ngọc DuyMatching index entries against an excludes file currently has two problems.
First, there's no function to do it. Code paths (like sparse checkout) that wanted to try it would iterate over index entries and for each index entry pass that path to excluded_from_list(). But that is not how excluded_from_list() works; one is supposed to feed in each ancester of a path before a given path to find out if it was excluded because of some parent or grandparent matching a
bigsubdirectory/
pattern despite the path not matching any .gitignore pattern directly.
Second, it's inefficient. The excludes mechanism is supposed to let us block off vast swaths of the filesystem as uninteresting; separately checking every index entry doesn't fit that model.
Introduce a new function to take care of both these problems. This traverses the index in depth-first order (well, that's what order the index is in) to mark un-excluded entries.
Maybe some day the in-core index format will be restructured to make this sort of operation easier. Or maybe we will want to try some binary search based thing. The interface is simple enough to allow all those things. Example:
clear_ce_flags(the_index.cache, the_index.cache_nr,
CE_CANDIDATE, CE_CLEARME, exclude_list);
would clear the CE_CLEARME flag on all index entries with CE_CANDIDATE flag and not matched by exclude_list.
--- Documentation/git-read-tree.txt | 7 -- t/t1011-read-tree-sparse-checkout.sh | 14 +++- unpack-trees.c | 154 +++++++++++++++++++++++++++++++-- 3 files changed, 155 insertions(+), 20 deletions(-)
Documentation/git-read-tree.txt +0 -7
@@ -412,13 +412,6 @@ turn `core.sparseCheckout` on in order to have sparse checkout support. -BUGS ----- -In order to match a directory with $GIT_DIR/info/sparse-checkout, -trailing slash must be used. The form without trailing slash, while -works with .gitignore, does not work with sparse checkout. - - SEE ALSO -------- linkgit:git-write-tree[1]; linkgit:git-ls-files[1];
t/t1011-read-tree-sparse-checkout.sh +11 -3
@@ -94,12 +94,20 @@ test_expect_success 'match directories with trailing slash' ' test -f sub/added ' -test_expect_failure 'match directories without trailing slash' ' - echo init.t >.git/info/sparse-checkout && +test_expect_success 'match directories without trailing slash' ' echo sub >>.git/info/sparse-checkout && git read-tree -m -u HEAD && git ls-files -t >result && - test_cmp expected.swt result && + test_cmp expected.swt-noinit result && + test ! -f init.t && + test -f sub/added +' + +test_expect_success 'match directory pattern' ' + echo "s?b" >>.git/info/sparse-checkout && + git read-tree -m -u HEAD && + git ls-files -t >result && + test_cmp expected.swt-noinit result && test ! -f init.t && test -f sub/added '
unpack-trees.c +144 -10
182 lines not on this page · raw message
Signature · 1 line
1.7.3.2.316.gda8b3
PATCH 5/5 Revert "excluded_1(): support exclude files in index"
In reply to Nguyễn Thái Ngọc DuyThis reverts commit c84de70781674a35b9bfd20aa5bc8c47582615df. The commit provided a workaround for matching directories in index. But it is no longer needed.
--- dir.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
dir.c +0 -7
@@ -371,13 +371,6 @@ int excluded_from_list(const char *pathname,int to_exclude = x->to_exclude;if (x->flags &EXC_FLAG_MUSTBEDIR ) { -if (!dtype) { -if (!prefixcmp (pathname, exclude) && - pathname[x->patternlen] =='/' ) -return to_exclude; -else -continue ; - }if (*dtype ==DT_UNKNOWN ) *dtype =get_dtype (NULL , pathname, pathlen);if (*dtype !=DT_DIR )
Signature · 1 line
1.7.3.2.316.gda8b3