Skip to contentSkip to conversation

Sparse checkout fixes and improvements

PATCH In review Nguyễn Thái Ngọc Duy 5 participants 34 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover Sparse checkout fixes and improvements

The first part fixes the long standing t1011.7 and removes the work around in excluded_from_list(). As a result, the EXC_FLAG_MUSTBEDIR fix for sparse checkout [1] is no longer needed.

Another plus is that because the index is now traversed tree-alike, when a directory is match, all its children does not need to be checked, which could speed things up a bit.

[1] http://http://article.gmane.org/gmane.comp.version-control.git/160892

Nguyễn Thái Ngọc Duy (10):
add: do not rely on dtype being NULL behavior
unpack-trees: move all skip-worktree check back to unpack_trees()
unpack-trees: add function to update ce_flags based on sparse
patterns
unpack-trees: fix sparse checkout's "unable to match directories"
fault

The second part is more experimental although I think it's good change:

unpack-trees: optimize full checkout case

The intention is that $GIT_DIR/info/sparse-checkout can be always-on. But it should not impact performance when not really used.

templates: add info/sparse-checkout

I should have done this long before. I did not notice it until recently.

checkout: add -S to update sparse checkout
checkout: add --full to fully populate working directory git-checkout.txt: mention of sparse checkout

These form a friendlier interface to update sparse checkout. Users need not to dig deep in git-read-tree.txt just to use sparse checkout. "git checkout -S" resembles "cleartool edcs", which makes sense to me. Both edit a file (location "unknown" in clearcase case) and update worktree after that.

clean: support cleaning sparse checkout with -S

Sparse checkout does not prohibit you from checking out other parts of the index. But you are pretty much left alone when doing so. This helps a bit. Support "git clean -S -e" is possible with clear_ce_flags() from the first part of this series but I need to think a bit more.

 Documentation/git-checkout.txt       |   49 +++++++++
 Documentation/git-clean.txt          |    6 +-
 Documentation/git-read-tree.txt      |   18 +---
 builtin/add.c                        |    3 +-
 builtin/checkout.c                   |   59 +++++++++++-
 builtin/clean.c                      |   70 +++++++++++++
 cache.h                              |    1 +
 dir.c                                |    6 -
 t/t1011-read-tree-sparse-checkout.sh |   39 +++++++-
 t/t7301-clean-sparse.sh              |   92 +++++++++++++++++
 templates/info--sparse-checkout      |    4 +
 unpack-trees.c                       |  188 +++++++++++++++++++++++++++++++---
 12 files changed, 490 insertions(+), 45 deletions(-)
 create mode 100755 t/t7301-clean-sparse.sh
 create mode 100644 templates/info--sparse-checkout
Signature · 1 line
1.7.3.2.210.g045198
#1 lore raw

PATCH 1/10 add: do not rely on dtype being NULL behavior

Commit c84de70 (excluded_1(): support exclude files in index - 2009-08-20) added support for excluded() where dtype can be NULL. It was designed specifically for index matching because there was no other way to extract dtype information from index. It did not support wildcard matching (for example, "a*/" pattern would fail to match).

The code was probably misread when commit 108da0d (git add: Add the "--ignore-missing" option for the dry run - 2010-07-10) was made because DT_UNKNOWN happens to be zero (NULL) too.

Do not pass DT_UNKNOWN/NULL to excluded(), instead pass a pointer to a variable that contains DT_UNKNOWN. The real dtype will be extracted from worktree by excluded(), as expected.

---
 builtin/add.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
builtin/add.c +2 -1
index 56a4e0a..1a4672d 100644
@@ -446,7 +446,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 			if (!seen[i] && pathspec[i][0]
 			    && !file_exists(pathspec[i])) {
 				if (ignore_missing) {
-					if (excluded(&dir, pathspec[i], DT_UNKNOWN))
+					int dtype = DT_UNKNOWN;
+					if (excluded(&dir, pathspec[i], &dtype))
 						dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
 				} else
 					die("pathspec '%s' did not match any files",
Signature · 1 line
1.7.3.2.210.g045198
#2 lore raw

Re: [PATCH 01/10] add: do not rely on dtype being NULL behavior

Quoted 6 lines · Nguyễn Thái Ngọc Duy

Commit c84de70 (excluded_1(): support exclude files in index - 2009-08-20) added support for excluded() where dtype can be NULL. It was designed specifically for index matching because there was no other way to extract dtype information from index. It did not support wildcard matching (for example, "a*/" pattern would fail to match).

Quoted 7 lines

The code was probably misread when commit 108da0d (git add: Add the "--ignore-missing" option for the dry run - 2010-07-10) was made because DT_UNKNOWN happens to be zero (NULL) too.

Do not pass DT_UNKNOWN/NULL to excluded(), instead pass a pointer to a variable that contains DT_UNKNOWN. The real dtype will be extracted from worktree by excluded(), as expected.

Could you rephrase this in a way that contrasts current and desired behavior? Is it like this?

The "git add --ignore-missing --dry-run" codepath is interpreting .gitignore incorrectly, unlike "git add". For example:

$ test -e foo || echo missing
missing
$ echo foo/ >>.gitignore
$ mkdir bar
$ git add --ignore-missing --dry-run foo; echo $? The following paths are ignored by one of your .gitignore files:
foo/
Use -f if you really want to add them.
fatal: no files added
128
$ git add --ignore-missing --dry-run bar/foo; echo $? 0

In the original use case (preparing to add a submodule) the behavior of the first command is correct, second incorrect. If the entry to be added was a regular file, it would be the other way around.

The cause: the --ignore-missing code passes DT_UNKNOWN as the dtype_ptr argument to excluded() which happens to equal zero (NULL) and accidentally triggers the "match pathspecs in index only" codepath (see c84de70, excluded_1(): support exclude files in index, 2009-08-20) that is unfortunately a bit primitive.

Surely what was really wanted is to check paths against the index and work tree, defaulting to "regular file".

Wait --- that's not true. In the "git submodule add" case, we really want to default to (or even better, force) "directory".

#3 lore raw

Re: [PATCH 01/10] add: do not rely on dtype being NULL behavior

Quoted 48 lines · Jonathan Nieder
Quoted 6 lines · Nguyễn Thái Ngọc Duy

Commit c84de70 (excluded_1(): support exclude files in index - 2009-08-20) added support for excluded() where dtype can be NULL. It was designed specifically for index matching because there was no other way to extract dtype information from index. It did not support wildcard matching (for example, "a*/" pattern would fail to match).

Quoted 7 lines

The code was probably misread when commit 108da0d (git add: Add the "--ignore-missing" option for the dry run - 2010-07-10) was made because DT_UNKNOWN happens to be zero (NULL) too.

Do not pass DT_UNKNOWN/NULL to excluded(), instead pass a pointer to a variable that contains DT_UNKNOWN. The real dtype will be extracted from worktree by excluded(), as expected.

Could you rephrase this in a way that contrasts current and desired behavior?  Is it like this?

       The "git add --ignore-missing --dry-run" codepath is interpreting .gitignore incorrectly, unlike "git add".  For example:

               $ test -e foo || echo missing
               missing
               $ echo foo/ >>.gitignore
               $ mkdir bar
               $ git add --ignore-missing --dry-run foo; echo $?
               The following paths are ignored by one of your .gitignore files:
               foo/
               Use -f if you really want to add them.
               fatal: no files added
               128
               $ git add --ignore-missing --dry-run bar/foo; echo $?
               0

       In the original use case (preparing to add a submodule) the behavior of the first command is correct, second incorrect. If the entry to be added was a regular file, it would be the other way around.

       The cause: the --ignore-missing code passes DT_UNKNOWN as the dtype_ptr argument to excluded() which happens to equal zero (NULL) and accidentally triggers the "match pathspecs in index only" codepath (see c84de70, excluded_1(): support exclude files in index, 2009-08-20) that is unfortunately a bit primitive.

Quoted 5 lines

       Surely what was really wanted is to check paths against the index and work tree, defaulting to "regular file".

Wait --- that's not true.  In the "git submodule add" case, we really want to default to (or even better, force) "directory".

Hmm.. get_index_dtype() would return DT_DIR if the submodule exists in index. If it does not it must be a directory in worktree, right? Call flow: excluded_from_list() -> get_dtype() -> get_index_dtype()

Signature · 1 line
Duy
#4 lore raw

Re: [PATCH 01/10] add: do not rely on dtype being NULL behavior

Quoted 11 lines · Nguyen Thai Ngoc Duy
Quoted 5 lines · Jonathan Nieder

       Surely what was really wanted is to check paths against the index and work tree, defaulting to "regular file".

Wait --- that's not true.  In the "git submodule add" case, we really want to default to (or even better, force) "directory".

Hmm.. get_index_dtype() would return DT_DIR if the submodule exists in index. If it does not it must be a directory in worktree, right? Call flow: excluded_from_list() -> get_dtype() -> get_index_dtype()

based on

	git ls-files --error-unmatch "$path" >/dev/null 2>&1 &&
	die "'$path' already exists in the index"

	if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
	then
		echo >&2 "The following path is ignored by one of your .gitignore files:" &&
		echo >&2 $path &&
		echo >&2 "Use -f if you really want to add it."
		exit 1
	fi

	# perhaps the path exists and is already a git repo, else clone it
	if test -e "$path"

I'd say no, the usual case is that the potential submodule does not exist in the index or worktree, which is why that call site uses --ignore-missing.

#5 lore raw

Re: [PATCH 01/10] add: do not rely on dtype being NULL behavior

In reply to Nguyen Thai Ngoc Duy
Quoted 3 lines · Nguyen Thai Ngoc Duy

Hmm.. get_index_dtype() would return DT_DIR if the submodule exists in index. If it does not it must be a directory in worktree, right? Call flow: excluded_from_list() -> get_dtype() -> get_index_dtype()

By the way, your c84de70 (excluded_1(): support exclude files in index, 2009-08-20) looks broken. What happens when the exclude pattern wants a directory but specifies it with a wildcard?

The safest and sanest first step is to just change DT_UNKNOWN (which clearly is a wrong thing to pass) to NULL to keep the current behaviour, but it probably makes more sense to do the second step at the same time to pass a pointer to an int that holds DT_UNKNOWN to avoid triggering that broken codepath.

#6 lore raw

Re: [PATCH 01/10] add: do not rely on dtype being NULL behavior

Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Nguyen Thai Ngoc Duy

Hmm.. get_index_dtype() would return DT_DIR if the submodule exists in index. If it does not it must be a directory in worktree, right? Call flow: excluded_from_list() -> get_dtype() -> get_index_dtype()

By the way, your c84de70 (excluded_1(): support exclude files in index, 2009-08-20) looks broken.  What happens when the exclude pattern wants a directory but specifies it with a wildcard?

It fails. I realized that just this week unfortunately. That commit is reverted in this series.

Quoted 5 lines

The safest and sanest first step is to just change DT_UNKNOWN (which clearly is a wrong thing to pass) to NULL to keep the current behaviour, but it probably makes more sense to do the second step at the same time to pass a pointer to an int that holds DT_UNKNOWN to avoid triggering that broken codepath.

Yes.

Signature · 1 line
Duy
#7 lore raw

PATCH 2/10 unpack-trees: move all skip-worktree check back to unpack_trees()

In reply to Nguyễn Thái Ngọc Duy

Earlier, the will_have_skip_worktree() checks are done in various places:

1. in verify_* functions to prevent absent/uptodate checks outside worktree
2. in merged_entry for new index entries
3. in apply_sparse_checkout() for all entries

In case all entries are added new ($GIT_DIR/index is missing) all the above checks will be done for all entries, which in the worst case can become cache_nr*el->nr*3 fnmatch() calls. Quite expensive.

By moving all will_have_skip_worktree() checks to unpack_trees(), we now have two places to run the checks:

- one before calling traverse_trees(), where all current index entries are checked.
- one after traverse_trees(), where newly-added entries are checked.

In worst case, each entry will be checked once, or cache_nr*el->nr fnmatch() calls at most. The two places are a loop over all entries, which also makes optimization easier.

CE_ADDED is used to mark new entries. The flag is only used by add_to_index(), which should not be called while unpack_trees() is running.

---
 cache.h        |    1 +
 unpack-trees.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 63 insertions(+), 7 deletions(-)
cache.h +1 -0
index 33decd9..d87708a 100644
@@ -182,6 +182,7 @@ struct cache_entry {
 #define CE_WT_REMOVE (0x400000) /* remove in work directory */
 
 #define CE_UNPACKED  (0x1000000)
+#define CE_NEW_SKIP_WORKTREE (0x2000000)
 
 /*
  * Extended on-disk flags
unpack-trees.c +62 -7

119 lines not on this page · raw message

Signature · 1 line
1.7.3.2.210.g045198
#8 lore raw

Re: [PATCH 02/10] unpack-trees: move all skip-worktree check back to unpack_trees()

Quoted 10 lines · Nguyễn Thái Ngọc Duy

Earlier, the will_have_skip_worktree() checks are done in various places:

1. in verify_* functions to prevent absent/uptodate checks outside worktree
2. in merged_entry for new index entries
3. in apply_sparse_checkout() for all entries

In case all entries are added new ($GIT_DIR/index is missing) all the above checks will be done for all entries, which in the worst case can become cache_nr*el->nr*3 fnmatch() calls. Quite expensive.

Does this mean something like:

Handling of sparse checkouts is slow.

[timings]

To fix this, we will do such-and-such. As a first step, we'll do such-and-such which does not change semantics and at least does not make it any slower.

?

In other words, any commit message should make clear

1. The purpose.
2. The baseline of (sane or insane) behavior that is affected.
3. The intended resulting functionality.

How the patch works and why it succeeds are just optional extras (nice, certainly, but in 90% of cases it is obvious from the code once you know (1), (2), and (3) anyway).

cache.h struct cache_entry { · line 185

Quoted 7 lines
cache.h +1 -0
@@ -182,6 +182,7 @@ struct cache_entry {
 #define CE_WT_REMOVE (0x400000) /* remove in work directory */
 
 #define CE_UNPACKED  (0x1000000)
+#define CE_NEW_SKIP_WORKTREE (0x2000000)

Semantics?

unpack-trees.c static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt · line 262

Quoted 9 lines
unpack-trees.c +1 -1
@@ -258,7 +258,7 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
 {
 	int was_skip_worktree = ce_skip_worktree(ce);
 
-	if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+	if (ce->ce_flags & CE_NEW_SKIP_WORKTREE)
 		ce->ce_flags |= CE_SKIP_WORKTREE;

So CE_NEW_SKIP_WORKTREE roughly means "stage-0 entry outside the sparse checkout area"?

unpack-trees.c static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt · line 264

Quoted 2 lines
unpack-trees.c +0 -0
 	else
 		ce->ce_flags &= ~CE_SKIP_WORKTREE;

In particular, I guess the NEW part refers to the sparse checkout area, not the entry, since existing index entries with SKIP_WORKTREE bits need to keep that bit.

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 838

Quoted 6 lines
unpack-trees.c +2 -0
@@ -834,6 +834,49 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
 	return mask;
 }
 
+static void set_new_skip_worktree_1(struct unpack_trees_options *o)
+{

Will comment on name once we get to the call site.

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 849

Quoted 11 lines
unpack-trees.c +11 -0
+	int i;
+
+	for (i = 0;i < o->src_index->cache_nr;i++) {
+		struct cache_entry *ce = o->src_index->cache[i];
+		ce->ce_flags &= ~CE_ADDED;
+		if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+			ce->ce_flags |= CE_NEW_SKIP_WORKTREE;
+		else
+			ce->ce_flags &= ~CE_NEW_SKIP_WORKTREE;
+	}
+}

Populating the CE_NEW_SKIP_WORKTREE flags based on the new worktree area.

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 859

Quoted 10 lines
unpack-trees.c +10 -0
+
+static int verify_absent(struct cache_entry *, enum unpack_trees_error_types, struct unpack_trees_options *);
+static int set_new_skip_worktree_2(struct unpack_trees_options *o)
+{
+	int i;
+
+	/*
+	 * CE_ADDED marks new index entries. These have not been processed
+	 * by set_new_skip_worktree_1() so we do it here.
+	 */

Probably this comment belongs at the call site instead, to avoid some chasing.

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 870

Quoted 11 lines
unpack-trees.c +11 -0
+	for (i = 0;i < o->result.cache_nr;i++) {
+		struct cache_entry *ce = o->result.cache[i];
+
+		if (!(ce->ce_flags & CE_ADDED))
+			continue;
+
+		ce->ce_flags &= ~CE_ADDED;
+		if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+			ce->ce_flags |= CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE;
+		else
+			ce->ce_flags &= ~(CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);

CE_ADDED is private to the add_file_to_index() code path shared between add and rerere builtins. rerere is libified and used e.g. by cherry-pick foo..bar. Can it get us in trouble or do we have clear the flags before using them here? I think it would be worth a note in api-in-core-index.txt to warn future refactorers.

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 872

Quoted 2 lines
unpack-trees.c +2 -0
+
+		/* Left-over checks from merged_entry when old == NULL */

Huh? (That is completely cryptic outside the context of the patch.)

Quoted 3 lines
unpack-trees.c +3 -0
+		if (verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
+			return -1;
+	}

[...]

unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 910

Quoted 7 lines
unpack-trees.c +3 -0
@@ -862,6 +905,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 			o->el = &el;
 	}
 
+	if (!o->skip_sparse_checkout)
+		set_new_skip_worktree_1(o);
+

Why is this not folded into the above if ()?

This populates the NEW_SKIP_WORKTREE (= future SKIP_WORKTREE?) bit in the index that represents the preimage for a reset or merge.

Perhaps call it:

		set_new_skip_worktree(o->src_index, 0);

and mark that function __attribute__((always_inline)) if the optimizer doesn't want to cooperate?

Or:

		set_src_skip_worktree(o);

unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 974

Quoted 11 lines
unpack-trees.c +4 -0
 	memset(&o->result, 0, sizeof(o->result));
 	o->result.initialized = 1;
 	o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -922,6 +968,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 
 	if (!o->skip_sparse_checkout) {
 		int empty_worktree = 1;
+
+		if (set_new_skip_worktree_2(o))
+			goto return_failed;
+

Trivial part of the merge is over. So now we can check the new index entries against the sparse worktree patterns. They were added in that trivial part using add_entry() and will have the CE_ADDED flag.

So this might be:

		set_new_skip_worktree(&o->result, CE_ADDED);

or

		set_result_skip_worktree(o);

The CE_ADDED flag was set in merged_entry, called by the merge_fn_t implementations. If there were an api-traverse-trees.txt explaining the API, it would be worth a note there; for now it should suffice to add a note to future merge_fn_t implementors in the commit message ("each unpack-trees merge function arranges for CE_SKIP_WORKTREE and CE_SKIP_NEW_WORKTREE to be propagated and for the CE_ADDED flag to be set on entries of new paths").

Quoted 9 lines
unpack-trees.c +1 -1
 		for (i = 0;i < o->result.cache_nr;i++) {
 			struct cache_entry *ce = o->result.cache[i];
 
@@ -1017,7 +1067,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
 static int verify_uptodate(struct cache_entry *ce,
 			   struct unpack_trees_options *o)
 {
-	if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
+	if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE))

[...]

unpack-trees.c static int verify_absent(struct cache_entry *ce, · line 1257

Quoted 6 lines
unpack-trees.c +1 -1
@@ -1204,7 +1254,7 @@ static int verify_absent(struct cache_entry *ce,
 			 enum unpack_trees_error_types error_type,
 			 struct unpack_trees_options *o)
 {
-	if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
+	if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE))

The point, I hope. Currently we alternate between finding entries to remove and deciding whether if lie in the worktree. After this patch, whether they lie in the worktree is precomputed.

unpack-trees.c static int merged_entry(struct cache_entry *merge, struct cache_entry *old, · line 1284

Quoted 10 lines
unpack-trees.c +6 -0
@@ -1226,10 +1276,15 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
 	int update = CE_UPDATE;
 
 	if (!old) {
+		/*
+		 * Set CE_NEW_SKIP_WORKTREE on "merge" to make
+		 * verify_absent() no-op. The true check will be done
+		 * later on in unpack_trees().
+		 */
+		merge->ce_flags |= CE_NEW_SKIP_WORKTREE;

Mm? Since verify_absent() is a no-op, why call it? This looks like a placeholder for code that calls verify_absent later, when we know if it lies in the worktree.

unpack-trees.c static int merged_entry(struct cache_entry *merge, struct cache_entry *old, · line 1287

Quoted 5 lines
unpack-trees.c +1 -2
 		if (verify_absent(merge, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
 			return -1;
-		if (!o->skip_sparse_checkout && will_have_skip_worktree(merge, o))
-			update |= CE_SKIP_WORKTREE;
+		update |= CE_ADDED;

More of the main act. Currently we alternate between finding entries to add and deciding if they are in the worktree. After the patch, they are piled up for addition first, then checked against the worktree in one batch.

unpack-trees.c static int merged_entry(struct cache_entry *merge, struct cache_entry *old, · line 1304

Quoted 11 lines
unpack-trees.c +2 -2
 		invalidate_ce_path(merge, o);
 	} else if (!(old->ce_flags & CE_CONFLICTED)) {
 		/*
@@ -1245,8 +1300,8 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
 		} else {
 			if (verify_uptodate(old, o))
 				return -1;
-			if (ce_skip_worktree(old))
-				update |= CE_SKIP_WORKTREE;
+			/* Migrate old bits over */
+			update |= old->ce_flags & (CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);

Thanks, this looks promising.
Jonathan

#9 lore raw

Re: [PATCH 02/10] unpack-trees: move all skip-worktree check back to unpack_trees()

2010/11/15 Jonathan Nieder <[email protected]>:

Quoted 27 lines
Quoted 10 lines · Nguyễn Thái Ngọc Duy

Earlier, the will_have_skip_worktree() checks are done in various places:

1. in verify_* functions to prevent absent/uptodate checks outside worktree
2. in merged_entry for new index entries
3. in apply_sparse_checkout() for all entries

In case all entries are added new ($GIT_DIR/index is missing) all the above checks will be done for all entries, which in the worst case can become cache_nr*el->nr*3 fnmatch() calls. Quite expensive.

Does this mean something like:

       Handling of sparse checkouts is slow.

       [timings]

       To fix this, we will do such-and-such.  As a first step, we'll do such-and-such which does not change semantics and at least does not make it any slower.

?

In other words, any commit message should make clear

Quoted 7 lines

 1. The purpose.
 2. The baseline of (sane or insane) behavior that is affected.
 3. The intended resulting functionality.

How the patch works and why it succeeds are just optional extras (nice, certainly, but in 90% of cases it is obvious from the code once you know (1), (2), and (3) anyway).

Addressing the slowness is a nice side effect. My main concern is to collect all skip-worktree checks in a central place so that I can do tree-like traversing.

Quoted 9 lines

cache.h struct cache_entry { · line 185

Quoted 7 lines
cache.h +1 -0
@@ -182,6 +182,7 @@ struct cache_entry {
  #define CE_WT_REMOVE (0x400000) /* remove in work directory */
 
  #define CE_UNPACKED  (0x1000000)
+#define CE_NEW_SKIP_WORKTREE (0x2000000)

Semantics?

Yep, missed this in the commit message. While unpack_trees() is running, this bit will be set in entries that are outside worktree area, according to the (possibly updated) sparse-checkout file. Compare this bit with CE_SKIP_WORKTREE, we would know this entry should be removed/added due to sparse-checkout updates.

Quoted 11 lines

unpack-trees.c static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt · line 262

Quoted 9 lines
unpack-trees.c +1 -1
@@ -258,7 +258,7 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
  {
       int was_skip_worktree = ce_skip_worktree(ce);
 
-     if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+     if (ce->ce_flags & CE_NEW_SKIP_WORKTREE)
               ce->ce_flags |= CE_SKIP_WORKTREE;

So CE_NEW_SKIP_WORKTREE roughly means "stage-0 entry outside the sparse checkout area"?

Yes. Conflicted entries must always stay in worktree regardless sparse-checkout patterns.

Quoted 7 lines
Quoted 3 lines

      else
              ce->ce_flags &= ~CE_SKIP_WORKTREE;

In particular, I guess the NEW part refers to the sparse checkout area, not the entry, since existing index entries with SKIP_WORKTREE bits need to keep that bit.

The NEW part still refers to entry. It's basically ce_flags[CE_SKIP_WORKTREE] = ce_flags[CE_NEW_SKIP_WORKTREE]. The former bit is kept in file, the later is in memory only.

Quoted 5 lines
Quoted 5 lines
unpack-trees.c +5 -0
+
+static int verify_absent(struct cache_entry *, enum unpack_trees_error_types, struct unpack_trees_options *);
+static int set_new_skip_worktree_2(struct unpack_trees_options *o)
+{
+     int i;
Quoted 8 lines
Quoted 5 lines

+
+     /*
+      * CE_ADDED marks new index entries. These have not been processed
+      * by set_new_skip_worktree_1() so we do it here.
+      */

Probably this comment belongs at the call site instead, to avoid some chasing.

There is a comment in the callsite, though it does not directly say "set_new_skip_worktree_2". Will fix.

Quoted 9 lines
Quoted 9 lines

+     for (i = 0;i < o->result.cache_nr;i++) {
+             struct cache_entry *ce = o->result.cache[i];

unpack-trees.c +7 -0
+
+             if (!(ce->ce_flags & CE_ADDED))
+                     continue;
+
+             ce->ce_flags &= ~CE_ADDED;
+             if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+                     ce->ce_flags |= CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE;
Quoted 8 lines
Quoted 2 lines

+             else
+                     ce->ce_flags &= ~(CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);

CE_ADDED is private to the add_file_to_index() code path shared between add and rerere builtins.  rerere is libified and used e.g. by cherry-pick foo..bar.  Can it get us in trouble or do we have clear the flags before using them here?  I think it would be worth a note in api-in-core-index.txt to warn future refactorers.

If it's too much trouble, I can use a new bit. Though the number of available bits is decreasing.

Quoted 4 lines
Quoted 2 lines

+
+             /* Left-over checks from merged_entry when old == NULL */

Huh?  (That is completely cryptic outside the context of the patch.)

Will elaborate.

Quoted 13 lines

unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 910

Quoted 7 lines
unpack-trees.c +3 -0
@@ -862,6 +905,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                       o->el = &el;
       }
 
+     if (!o->skip_sparse_checkout)
+             set_new_skip_worktree_1(o);
+

Why is this not folded into the above if ()?

This populates the NEW_SKIP_WORKTREE (= future SKIP_WORKTREE?) bit in the index that represents the preimage for a reset or merge.

Quoted 6 lines

Perhaps call it:

               set_new_skip_worktree(o->src_index, 0);

and mark that function __attribute__((always_inline)) if the optimizer doesn't want to cooperate?

It's setting future skip-worktree on existing entries index, contrast with the _2() function, which is setting future skip-worktree on _new_ entries in the index. How do you name those functions? Wait..

Quoted 16 lines

unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 974

Quoted 11 lines
unpack-trees.c +4 -0
       memset(&o->result, 0, sizeof(o->result));
       o->result.initialized = 1;
       o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -922,6 +968,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 
       if (!o->skip_sparse_checkout) {
               int empty_worktree = 1;
+
+             if (set_new_skip_worktree_2(o))
+                     goto return_failed;
+

Trivial part of the merge is over.  So now we can check the new index entries against the sparse worktree patterns.  They were added in that trivial part using add_entry() and will have the CE_ADDED flag.

Quoted 8 lines

So this might be:

               set_new_skip_worktree(&o->result, CE_ADDED);

or

               set_result_skip_worktree(o);

OK I like the former over the latter.

Quoted 7 lines

The CE_ADDED flag was set in merged_entry, called by the merge_fn_t implementations.  If there were an api-traverse-trees.txt explaining the API, it would be worth a note there; for now it should suffice to add a note to future merge_fn_t implementors in the commit message ("each unpack-trees merge function arranges for CE_SKIP_WORKTREE and CE_SKIP_NEW_WORKTREE to be propagated and for the CE_ADDED flag to be set on entries of new paths").

OK

Quoted 7 lines
Quoted 6 lines
unpack-trees.c +1 -1
@@ -1017,7 +1067,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
  static int verify_uptodate(struct cache_entry *ce,
                          struct unpack_trees_options *o)
  {
-     if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
+     if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE))

[...]

Quoted 10 lines

unpack-trees.c static int verify_absent(struct cache_entry *ce, · line 1257

Quoted 6 lines
unpack-trees.c +1 -1
@@ -1204,7 +1254,7 @@ static int verify_absent(struct cache_entry *ce,
                        enum unpack_trees_error_types error_type,
                        struct unpack_trees_options *o)
  {
-     if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
+     if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE))

The point, I hope.  Currently we alternate between finding entries to remove and deciding whether if lie in the worktree.  After this patch, whether they lie in the worktree is precomputed.

Yep.

Quoted 14 lines

unpack-trees.c static int merged_entry(struct cache_entry *merge, struct cache_entry *old, · line 1284

Quoted 10 lines
unpack-trees.c +6 -0
@@ -1226,10 +1276,15 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
       int update = CE_UPDATE;
 
       if (!old) {
+             /*
+              * Set CE_NEW_SKIP_WORKTREE on "merge" to make
+              * verify_absent() no-op. The true check will be done
+              * later on in unpack_trees().
+              */
+             merge->ce_flags |= CE_NEW_SKIP_WORKTREE;

Mm?  Since verify_absent() is a no-op, why call it?  This looks like a placeholder for code that calls verify_absent later, when we know if it lies in the worktree.

It is no-op only when sparse checkout is enabled. In such cases we don't know (yet) whether we will add those files in worktree. In normal cases, everything must be added in worktree, so verify_absent() is real.

Quoted 10 lines

unpack-trees.c static int merged_entry(struct cache_entry *merge, struct cache_entry *old, · line 1304

Quoted 8 lines
unpack-trees.c +2 -2
@@ -1245,8 +1300,8 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
               } else {
                       if (verify_uptodate(old, o))
                               return -1;
-                     if (ce_skip_worktree(old))
-                             update |= CE_SKIP_WORKTREE;
+                     /* Migrate old bits over */
+                     update |= old->ce_flags & (CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);

Thanks, this looks promising.

Thanks for looking at it. These stuff can be error-prone.

Signature · 1 line
Duy
#10 lore raw

Re: [PATCH 02/10] unpack-trees: move all skip-worktree check back to unpack_trees()

In reply to Nguyễn Thái Ngọc Duy

2010/11/15 Nguyễn Thái Ngọc Duy <[email protected]>:

Quoted 9 lines

 cache.h        |    1 +
 unpack-trees.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++-----

 2 files changed, 63 insertions(+), 7 deletions(-)
cache.h +0 -0
index 33decd9..d87708a 100644

cache.h struct cache_entry { · line 186

Quoted 5 lines
cache.h +1 -0
@@ -182,6 +182,7 @@ struct cache_entry {
  #define CE_WT_REMOVE (0x400000) /* remove in work directory */
 
  #define CE_UNPACKED  (0x1000000)
+#define CE_NEW_SKIP_WORKTREE (0x2000000)
 

Would be good to remove the () around the hex here and else in this file?

Quoted 16 lines
cache.h +0 -0
  /*
  * Extended on-disk flags
unpack-trees.c +1 -1
index 803445a..9acd9be 100644
@@ -258,7 +258,7 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
  {
        int was_skip_worktree = ce_skip_worktree(ce);
 
-       if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+       if (ce->ce_flags & CE_NEW_SKIP_WORKTREE)
                ce->ce_flags |= CE_SKIP_WORKTREE;

       else
               ce->ce_flags &= ~CE_SKIP_WORKTREE;

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 841

Quoted 8 lines
unpack-trees.c +5 -0
@@ -834,6 +834,49 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
        return mask;
  }
 
+static void set_new_skip_worktree_1(struct unpack_trees_options *o)
+{
+       int i;
+
+       for (i = 0;i < o->src_index->cache_nr;i++) {

Could you add spaces after ; for readability, please? There is another for below that needs this to.

#11 lore raw

Re: [PATCH 02/10] unpack-trees: move all skip-worktree check back to unpack_trees()

2010/11/15 Thiago Farina <[email protected]>:

Quoted 12 lines

2010/11/15 Nguyễn Thái Ngọc Duy <[email protected]>:

Quoted 11 lines

 cache.h        |    1 +
 unpack-trees.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++-----

 2 files changed, 63 insertions(+), 7 deletions(-)
cache.h +0 -0
index 33decd9..d87708a 100644
@@ -182,6 +182,7 @@ struct cache_entry {
  #define CE_WT_REMOVE (0x400000) /* remove in work directory */
 
Quoted 4 lines

cache.h struct cache_entry { · line 186

Quoted 3 lines
cache.h +1 -0
  #define CE_UNPACKED  (0x1000000)
+#define CE_NEW_SKIP_WORKTREE (0x2000000)
 

Would be good to remove the () around the hex here and else in this file?

That was the tradition of CE_*. I don't know why () is there. Will do a preparation patch to remove all () first.

Quoted 20 lines
Quoted 20 lines
cache.h +0 -0
  /*
  * Extended on-disk flags
unpack-trees.c +1 -1
index 803445a..9acd9be 100644
@@ -258,7 +258,7 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
  {
        int was_skip_worktree = ce_skip_worktree(ce);
 
-       if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+       if (ce->ce_flags & CE_NEW_SKIP_WORKTREE)
                ce->ce_flags |= CE_SKIP_WORKTREE;

       else
               ce->ce_flags &= ~CE_SKIP_WORKTREE;

unpack-trees.c +0 -0
@@ -834,6 +834,49 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
        return mask;
  }
 
Quoted 8 lines

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 841

Quoted 5 lines
unpack-trees.c +5 -0
+static void set_new_skip_worktree_1(struct unpack_trees_options *o)
+{
+       int i;
+
+       for (i = 0;i < o->src_index->cache_nr;i++) {

Could you add spaces after ; for readability, please? There is another for below that needs this to.

Yes. I kept reminding myself of doing that, then forgot.

Signature · 1 line
Duy
#12 lore raw

PATCH 3/10 unpack-trees: add function to update ce_flags based on sparse patterns

In reply to Nguyễn Thái Ngọc Duy

The function will reconstruct directory structure from index and feed excluded_from_list() with proper dtype.

Another advantage over the old will_have_skip_worktree() is that when a directory is matched or not matched, we can go ahead and set ce_flags for all of its children without calling excluded_from_list() again. The old solution requires one excluded_from_list() call per index entry.

---
 unpack-trees.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)
unpack-trees.c +88 -0
index 9acd9be..6c266ef 100644
@@ -834,6 +834,94 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
 	return mask;
 }
 
+/*
+ * traverse the index, find every entry that matches according to
+ * o->el. Do "ce_flags &= ~clear_mask" on those entries. Return the
+ * number of traversed entries.
+ *
+ * If select_mask is non-zero, only entries whose ce_flags has on of
+ * those bits enabled are traversed.
+ */
+static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+			    int prefix_len, int match_all,
+			    int select_mask, int clear_mask,
+			    struct unpack_trees_options *o)
+{
+	const char *name, *slash;
+	struct cache_entry *ce = cache[0];
+	const char *prefix = ce->name;
+	int processed, original_nr = nr;
+
+	if (prefix_len && !match_all) {
+		int dtype = DT_DIR;
+		static char path[PATH_MAX];
+		int pathlen = prefix_len - 1;
+		const char *basename;
+
+		memcpy(path, prefix, pathlen);
+		path[pathlen] = '\0';
+		basename = strrchr(path, '/');
+		basename = basename ? basename+1 : path;
+		switch (excluded_from_list(path, pathlen, basename, &dtype, o->el)) {
+		case 0:
+			while (nr && !strncmp(ce->name, prefix, prefix_len)) {
+				cache++;
+				ce = *cache;
+				nr--;
+			}
+			return original_nr - nr;
+		case 1:
+			match_all = 1;
+			break;
+		default:	/* case -1, undecided */
+			break;
+		}
+	}
+
+	while (nr) {
+		if (select_mask && !(ce->ce_flags & select_mask)) {
+			cache++;
+			ce = *cache;
+			nr--;
+			continue;
+		}
+
+		if (prefix_len && strncmp(ce->name, prefix, prefix_len))
+			break;
+
+		name = ce->name + prefix_len;
+		slash = strchr(name, '/');
+
+		/* no slash, this is a file */
+		if (!slash) {
+			int dtype = ce_to_dtype(ce);
+			if (match_all ||
+			    excluded_from_list(ce->name, ce_namelen(ce), name, &dtype, o->el) > 0)
+				ce->ce_flags &= ~clear_mask;
+			cache++;
+			ce = *cache;
+			nr--;
+			continue;
+		}
+
+		/* has slash, this is a directory */
+		processed = clear_ce_flags_1(cache, nr,
+					     slash + 1 - ce->name, match_all,
+					     select_mask, clear_mask, o);
+		cache += processed;
+		ce = *cache;
+		nr -= processed;
+	}
+	return original_nr - nr;
+}
+
+static int clear_ce_flags(struct cache_entry **cache, int nr,
+			    int select_mask, int clear_mask,
+			    struct unpack_trees_options *o)
+{
+	return clear_ce_flags_1(cache, nr, 0, 0, select_mask, clear_mask, o);
+}
+
 static void set_new_skip_worktree_1(struct unpack_trees_options *o)
 {
 	int i;
Signature · 1 line
1.7.3.2.210.g045198
#13 lore raw

Re: [PATCH 03/10] unpack-trees: add function to update ce_flags based on sparse patterns

Quoted 2 lines · Nguyễn Thái Ngọc Duy

The function will reconstruct directory structure from index and feed excluded_from_list() with proper dtype.

Might be worth squashing with a patch introducing a caller; otherwise it's hard to get a sense of what these functions do.

#14 lore raw

Re: [PATCH 03/10] unpack-trees: add function to update ce_flags based on sparse patterns

In reply to Nguyễn Thái Ngọc Duy
Quoted 2 lines · Nguyễn Thái Ngọc Duy

The function will reconstruct directory structure from index and feed excluded_from_list() with proper dtype.

Okay, so I guess what this means is:

Matching 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.

Quoted 8 lines
unpack-trees.c +2 -0
@@ -834,6 +834,94 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
 	return mask;
 }
 
+/*
+ * traverse the index, find every entry that matches according to

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 848

Quoted 10 lines
unpack-trees.c +10 -0
+ * o->el. Do "ce_flags &= ~clear_mask" on those entries. Return the
+ * number of traversed entries.
+ *
+ * If select_mask is non-zero, only entries whose ce_flags has on of
+ * those bits enabled are traversed.
+ */
+static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+			    int prefix_len, int match_all,
+			    int select_mask, int clear_mask,
+			    struct unpack_trees_options *o)

o is only used for its excludes list. Why not cut out the middle man and take o->el as argument?

State (struct-worthy?):
cache pointer to an index entry
prefix_len an offset into its path
match_all a boolean telling whether we have some skipping to do

The current path (called the prefix), including trailing '/', is

	cache[0]->name[0] .. cache[0]->name[prefix_len - 1]

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 855

Quoted 7 lines
unpack-trees.c +7 -0
+{
+	const char *name, *slash;
+	struct cache_entry *ce = cache[0];
+	const char *prefix = ce->name;
+	int processed, original_nr = nr;
+
+	if (prefix_len && !match_all) {

Top level gets special handling. Let's skip to it (see [*] for where we were).

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 881

Quoted 1 line
unpack-trees.c +1 -0
+	while (nr) {

For each cache entry...

Might be nice to phrase this as a for loop.

	const char *prefix = cache[0]->name;
	struct cache_entry ** const cache_end = cache + nr;
	struct cache_entry **cep;
	for (cep = cache; cep != cache_end; ) {
		struct cache_entry *ce = *cep;

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 887

Quoted 6 lines
unpack-trees.c +6 -0
+		if (select_mask && !(ce->ce_flags & select_mask)) {
+			cache++;
+			ce = *cache;
+			nr--;
+			continue;
+		}

Some index entries are disqualified.

		if (select_mask)
			if (!(ce->ce_cflags & select_mask)) {
				cep++;
				continue;
			}

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 890

Quoted 2 lines
unpack-trees.c +2 -0
+		if (prefix_len && strncmp(ce->name, prefix, prefix_len))
+			break;

Entries not under prefix are handled by the caller.

		if (prefix_len)
			if (strncmp(ce->name, prefix, prefix_len))
				return cep - cache;	/* number processed */

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 896

Quoted 5 lines
unpack-trees.c +5 -0
+		name = ce->name + prefix_len;
+		slash = strchr(name, '/');
+
+		/* no slash, this is a file */
+		if (!slash) {

Leaf!

			/* File or directory?  Check if it's a submodule. */

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 905

Quoted 9 lines
unpack-trees.c +9 -0
+			int dtype = ce_to_dtype(ce);
+			if (match_all ||
+			    excluded_from_list(ce->name, ce_namelen(ce), name, &dtype, o->el) > 0)
+				ce->ce_flags &= ~clear_mask;
+			cache++;
+			ce = *cache;
+			nr--;
+			continue;
+		}
			if (excluded_block ||
			    excluded_from_list(...		/* Excluded? */
				ce->ce_flags &= ~clear_mask;
			cep++;
			continue;
		}

Putting the loop body in its own function could allow some nice depth reduction.

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 915

Quoted 10 lines
unpack-trees.c +10 -0
+
+		/* has slash, this is a directory */
+		processed = clear_ce_flags_1(cache, nr,
+					     slash + 1 - ce->name, match_all,
+					     select_mask, clear_mask, o);
+		cache += processed;
+		ce = *cache;
+		nr -= processed;
+	}
+	return original_nr - nr;
		/* Non-leaf.  Recurse. */
		cep += clear_ce_ ...
	}

How about the other case, mentioned before (see [*] above)?

assert(prefix_len); /* Not toplevel but a subdirectory. */
assert(!match_all); /* Not wholesale excluded. */

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 863

Quoted 8 lines
unpack-trees.c +8 -0
+		int dtype = DT_DIR;
+		static char path[PATH_MAX];
+		int pathlen = prefix_len - 1;
+		const char *basename;
+
+		memcpy(path, prefix, pathlen);
+		path[pathlen] = '\0';
+		basename = strrchr(path, '/');

Use memrchr?

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 872

Quoted 9 lines
unpack-trees.c +9 -0
+		basename = basename ? basename+1 : path;
+		switch (excluded_from_list(path, pathlen, basename, &dtype, o->el)) {
+		case 0:
+			while (nr && !strncmp(ce->name, prefix, prefix_len)) {
+				cache++;
+				ce = *cache;
+				nr--;
+			}
+			return original_nr - nr;
		case 0:	/* Included.  Great, no flag to clear. */
			for (; cep != cache_end; cep++)
				if (strncmp((*cep)->name, prefix, prefix_len))
					break;
			return cep - cache;

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 875

Quoted 3 lines
unpack-trees.c +3 -0
+		case 1:
+			match_all = 1;
+			break;
		case 1:	/* Excluded.  Great, clear them wholesale. */
			match_all = 1;
			continue;

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 878

Quoted 3 lines
unpack-trees.c +3 -0
+		default:	/* case -1, undecided */
+			break;
+		}
		case -1:	/* Undecided.
			continue;
		}

unpack-trees.c static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str · line 878

Quoted 3 lines
unpack-trees.c +3 -0
+	}
+	return original_nr - nr;
+}
	}
	/* Ran off the end. */
	return cep - cache;

}

That last bit could even longjmp() if expecting deeply nested directory hierarchies. (Sorry, joking, you should not do such an awful thing unless timing it proves it useful.)

That was clean, thanks.

Hope some of my musings are useful anyway.

#15 lore raw

PATCH 4/10 unpack-trees: fix sparse checkout's "unable to match directories" fault

In reply to Nguyễn Thái Ngọc Duy

excluded_from_list() is designed to be work with a directory structure, where there are files and directories. Index however is a list of files, no directories, not really fit in excluded_from_list() design.

Commit c84de70 (excluded_1(): support exclude files in index - 2009-08-20) helped make it work somewhat. Although the lack of proper dtype means pattern "blah" won't match entries "blah/..." in the index.

clear_ce_flags() is now used to match the index against sparse patterns. It does generate directories for excluded_from_list() so the "blah" case should now work.

Also revert c84de70 because it is no longer needed.

---
 Documentation/git-read-tree.txt      |    7 -------
 dir.c                                |    6 ------
 t/t1011-read-tree-sparse-checkout.sh |   14 +++++++++++---
 unpack-trees.c                       |   33 ++++++++++++++++++---------------
 4 files changed, 29 insertions(+), 31 deletions(-)
Documentation/git-read-tree.txt +0 -7
index e88e9c2..634423a 100644
@@ -416,13 +416,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];
dir.c +0 -6
index d1e5e5e..2b38f94 100644
@@ -359,12 +359,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))
-						return to_exclude;
-					else
-						continue;
-				}
 				if (*dtype == DT_UNKNOWN)
 					*dtype = get_dtype(NULL, pathname, pathlen);
 				if (*dtype != DT_DIR)
t/t1011-read-tree-sparse-checkout.sh +11 -3
index 9a07de1..50f7dfe 100755
@@ -91,12 +91,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 +18 -15
index 6c266ef..f005454 100644
@@ -245,15 +245,6 @@ static int check_updates(struct unpack_trees_options *o)
 static int verify_uptodate_sparse(struct cache_entry *ce, struct unpack_trees_options *o);
 static int verify_absent_sparse(struct cache_entry *ce, enum unpack_trees_error_types, struct unpack_trees_options *o);
 
-static int will_have_skip_worktree(const struct cache_entry *ce, struct unpack_trees_options *o)
-{
-	const char *basename;
-
-	basename = strrchr(ce->name, '/');
-	basename = basename ? basename+1 : ce->name;
-	return excluded_from_list(ce->name, ce_namelen(ce), basename, NULL, o->el) <= 0;
-}
-
 static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_options *o)
 {
 	int was_skip_worktree = ce_skip_worktree(ce);
@@ -926,14 +917,19 @@ static void set_new_skip_worktree_1(struct unpack_trees_options *o)
 {
 	int i;
 
+	/* Mark everything out (except staged entries) */
 	for (i = 0;i < o->src_index->cache_nr;i++) {
 		struct cache_entry *ce = o->src_index->cache[i];
 		ce->ce_flags &= ~CE_ADDED;
-		if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
+		if (!ce_stage(ce))
 			ce->ce_flags |= CE_NEW_SKIP_WORKTREE;
 		else
 			ce->ce_flags &= ~CE_NEW_SKIP_WORKTREE;
 	}
+
+	/* Then mark some of them in again according to o->el */
+	clear_ce_flags(o->src_index->cache, o->src_index->cache_nr,
+		       0, CE_NEW_SKIP_WORKTREE, o);
 }
 
 static int verify_absent(struct cache_entry *, enum unpack_trees_error_types, struct unpack_trees_options *);
@@ -943,19 +939,26 @@ static int set_new_skip_worktree_2(struct unpack_trees_options *o)
 
 	/*
 	 * CE_ADDED marks new index entries. These have not been processed
-	 * by set_new_skip_worktree_1() so we do it here.
+	 * by set_new_skip_worktree_1() so we do it here. Mark every new
+	 * entries out.
 	 */
 	for (i = 0;i < o->result.cache_nr;i++) {
 		struct cache_entry *ce = o->result.cache[i];
+		if (ce->ce_flags & CE_ADDED)
+			ce->ce_flags |= CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE;
+	}
+
+	/* Then mark some of them in again */
+	clear_ce_flags(o->result.cache, o->result.cache_nr, CE_ADDED,
+		       CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE, o);
+
+	for (i = 0;i < o->result.cache_nr;i++) {
+		struct cache_entry *ce = o->result.cache[i];
 
 		if (!(ce->ce_flags & CE_ADDED))
 			continue;
 
 		ce->ce_flags &= ~CE_ADDED;
-		if (!ce_stage(ce) && will_have_skip_worktree(ce, o))
-			ce->ce_flags |= CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE;
-		else
-			ce->ce_flags &= ~(CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);
 
 		/* Left-over checks from merged_entry when old == NULL */
 		if (verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
Signature · 1 line
1.7.3.2.210.g045198
#16 lore raw

Re: [PATCH 04/10] unpack-trees: fix sparse checkout's "unable to match directories" fault

Quoted 2 lines · Nguyễn Thái Ngọc Duy

excluded_from_list() is designed to be work with a directory structure, where there are files and directories. Index however is a

                                                   ^
                                                   The
Quoted 1 line

list of files, no directories, not really fit in excluded_from_list()

^with no separate entries for directories, so it does

Quoted 1 line

design.

[...]

Quoted 2 lines

clear_ce_flags() is now used to match the index against sparse patterns. It does generate directories for excluded_from_list()

Sounds exciting. I can't believe I missed that, but I guess what was needed is a simple example caller. Let's see how this patch works in that vein.

Documentation/git-read-tree.txt turn `core.sparseCheckout` on in order to have sparse checkout · line 423

Quoted 11 lines
Documentation/git-read-tree.txt +0 -5
@@ -416,13 +416,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.

Nice.

[...]

t/t1011-read-tree-sparse-checkout.sh test_expect_success 'match directories with trailing slash' ' · line 94

Quoted 10 lines
t/t1011-read-tree-sparse-checkout.sh +1 -1
index 9a07de1..50f7dfe 100755
@@ -91,12 +91,20 @@ test_expect_success 'match directories with trailing slash' '
 	test -f sub/added
 '
 
-test_expect_failure 'match directories without trailing slash' '
+test_expect_success 'match directories without trailing slash' '

Also nice.

t/t1011-read-tree-sparse-checkout.sh test_expect_success 'match directories with trailing slash' ' · line 100

Quoted 8 lines
t/t1011-read-tree-sparse-checkout.sh +3 -2
-	echo init.t >.git/info/sparse-checkout &&
 	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

Maybe the new

test_path_is_missing

and

test_path_is_file

would be a good fit here, for better behavior when the path is a directory in the former case and better debugging output for failures in the latter.

t/t1011-read-tree-sparse-checkout.sh test_expect_success 'match directories with trailing slash' ' · line 110

Quoted 10 lines
t/t1011-read-tree-sparse-checkout.sh +7 -0
+'
+
+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
 '

A pattern change that changes the list of matched paths would be more impressive. (Though I understand, this version already works for demonstrating progress.)

[...]

dir.c int excluded_from_list(const char *pathname, · line 367

Quoted 12 lines
dir.c +0 -6
@@ -359,12 +359,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))
-						return to_exclude;
-					else
-						continue;
-				}

Removing the no longer used !dtype codepath.

This hunk could be a separate patch (simplifying the diff and decoupling this series from patch 1).

Quoted 2 lines
unpack-trees.c +0 -0

[...]

unpack-trees.c static void set_new_skip_worktree_1(struct unpack_trees_options *o) · line 924

Quoted 9 lines
unpack-trees.c +2 -0
@@ -926,14 +917,19 @@ static void set_new_skip_worktree_1(struct unpack_trees_options *o)
 {
 	int i;
 
+	/* Mark everything out (except staged entries) */
 	for (i = 0;i < o->src_index->cache_nr;i++) {
 		struct cache_entry *ce = o->src_index->cache[i];
 		ce->ce_flags &= ~CE_ADDED;
+		if (!ce_stage(ce))

Not a fan of this new definition of "staged". The following might be clearer:

/*
* The WILL_BE_SKIP_WORKTREE bit is initialized in two stages:
*
* 1. Pretend the checkout is so narrow it contains no files.
* Only unresolved entries participating in a merge would
* get written to the worktree.
*
* 2. Add back entries according to .git/info/sparse-checkout */

[...]

unpack-trees.c static int set_new_skip_worktree_2(struct unpack_trees_options *o) · line 944

Quoted 8 lines
unpack-trees.c +2 -1
@@ -943,19 +939,26 @@ static int set_new_skip_worktree_2(struct unpack_trees_options *o)
 
 	/*
 	 * CE_ADDED marks new index entries. These have not been processed
-	 * by set_new_skip_worktree_1() so we do it here.
+	 * by set_new_skip_worktree_1() so we do it here. Mark every new
+	 * entries out.
 	 */

Nit: "every" wants a singular noun. But even better would be to move the description of effect to the call site.

The description of strategy can stay here so it doesn't go out of date when the code changes:

/*
* Just like set_new_skip_worktree_1.
* unpack-trees never writes conflicted entries to the worktree,
* so there is no need to worry about conflicted files. *
* 1. Set WILL_BE_SKIP_WORKTREE for all new entries.
* 2. Clear it again for paths within the sparse checkout. */

Is it possible to make the two code paths share code without sacrificing speed?

#17 lore raw

Re: [PATCH 04/10] unpack-trees: fix sparse checkout's "unable to match directories" fault

2010/11/16 Jonathan Nieder <[email protected]>:

Quoted 2 lines

Is it possible to make the two code paths share code without sacrificing speed?

I think so. I'll merge the two functions in set_new_skip_worktree() as you suggested in the previous mail.

Signature · 1 line
Duy
#18 lore raw

PATCH 5/10 unpack-trees: optimize full checkout case

In reply to Nguyễn Thái Ngọc Duy
---
 unpack-trees.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
unpack-trees.c +10 -0
index f005454..eb5d357 100644
@@ -996,6 +996,16 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 			o->el = &el;
 	}
 
+	if (!o->skip_sparse_checkout &&
+	    o->el->nr == 1 &&
+	    !strcmp(o->el->excludes[0]->pattern, "*")) {
+		for (i = 0; i < o->src_index->cache_nr; i++)
+			if (ce_skip_worktree(o->src_index->cache[i]))
+				break;
+		if (i == o->src_index->cache_nr)
+			o->skip_sparse_checkout = 1;
+	}
+
 	if (!o->skip_sparse_checkout)
 		set_new_skip_worktree_1(o);
 
Signature · 1 line
1.7.3.2.210.g045198
#19 lore raw

Re: [PATCH 05/10] unpack-trees: optimize full checkout case

Quoted 1 line · Nguyễn Thái Ngọc Duy

So, what does it do? What workflow was not optimized (yes, I know full checkout means pattern "*", but the reader might not), why ought it to be optimized, and what are the side-effects, if any?

Quoted 4 lines
unpack-trees.c +0 -0
@@ -996,6 +996,16 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 			o->el = &el;

unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 1006

Quoted 10 lines
unpack-trees.c +8 -0
 	}
 
+	if (!o->skip_sparse_checkout &&
+	    o->el->nr == 1 &&
+	    !strcmp(o->el->excludes[0]->pattern, "*")) {
+		for (i = 0; i < o->src_index->cache_nr; i++)
+			if (ce_skip_worktree(o->src_index->cache[i]))
+				break;
+		if (i == o->src_index->cache_nr)
+			o->skip_sparse_checkout = 1;

Millinit:

	if (!o->skip_sparse_checkout &&
			checkout_is_whole_tree(o) &&
			index_uses_flag(o->src_index, CE_SKIP_WORKTREE))
		o->skip_sparse_checkout = 1;

Functions for the two conditions (especially the second) would make this clearer, I think.

Sensible.

#20 lore raw

PATCH 6/10 templates: add info/sparse-checkout

In reply to Nguyễn Thái Ngọc Duy
---
 templates/info--sparse-checkout |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 templates/info--sparse-checkout
templates/info--sparse-checkout new file +3 -0
new file mode 100644
index 0000000..7426475
@@ -0,0 +1,3 @@
+# Specify what files are checked out in working directory
+# Run "git checkout" after updating this file to update working directory
+*
Signature · 1 line
1.7.3.2.210.g045198
#21 lore raw

PATCH 7/10 checkout: add -S to update sparse checkout

In reply to Nguyễn Thái Ngọc Duy

The traditional way of updating sparse checkout is to open $GIT_DIR/info/sparse-checkout manually, edit it, save, then run "git checkout" or "git read-tree -m -u HEAD". That's not convenient.

"git checkout -S" is introduced to combine those steps in one. It also provides some additional checks:

- warn users if core.sparseCheckout is off
- refuse to update sparse checkout if there is no valid sparse patterns (faulty sparse-checkout file for example)

---
 Documentation/git-checkout.txt       |   16 +++++++++++++
 builtin/checkout.c                   |   42 +++++++++++++++++++++++++++++++++-
 t/t1011-read-tree-sparse-checkout.sh |   18 ++++++++++++++
 templates/info--sparse-checkout      |    1 +
 4 files changed, 76 insertions(+), 1 deletions(-)
Documentation/git-checkout.txt +16 -0
index 22d3611..478bfe7 100644
@@ -12,6 +12,7 @@ SYNOPSIS
 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
 'git checkout' --patch [<tree-ish>] [--] [<paths>...]
+'git checkout' -S
 
 DESCRIPTION
 -----------
@@ -176,6 +177,13 @@ the conflicted merge in the specified paths.
 This means that you can use `git checkout -p` to selectively discard
 edits from your current working tree.
 
+-S::
+--update-sparse-checkout::
+	An editor is invoked to let you update your sparse checkout
+	patterns. The updated patterns will be saved in
+	$GIT_DIR/info/sparse-checkout. The working directory is also
+	updated. An empty file will abort the process.
+
 <branch>::
 	Branch to checkout; if it refers to a branch (i.e., a name that,
 	when prepended with "refs/heads/", is a valid ref), then that
@@ -316,6 +324,14 @@ $ git add frotz
 ------------
 
 
+ENVIRONMENT AND CONFIGURATION VARIABLES
+---------------------------------------
+The editor used to edit the commit log message will be chosen from the
+GIT_EDITOR environment variable, the core.editor configuration variable, the
+VISUAL environment variable, or the EDITOR environment variable (in that
+order).  See linkgit:git-var[1] for details.
+
+
 Author
 ------
 Written by Linus Torvalds <[email protected]>
builtin/checkout.c +41 -1

84 lines not on this page · raw message

t/t1011-read-tree-sparse-checkout.sh +18 -0
index 50f7dfe..fe4716c 100755
@@ -184,4 +184,22 @@ test_expect_success 'read-tree --reset removes outside worktree' '
 	test_cmp empty result
 '
 
+test_expect_success 'git checkout -S fails to launch editor' '
+	GIT_EDITOR=/non-existent test_must_fail git checkout -S &&
+	grep init.t .git/info/sparse-checkout
+'
+
+test_expect_success 'git checkout -S' '
+	git checkout -f top &&
+	cat >editor.sh <<\EOF &&
+#!/bin/sh
+echo sub > "$1"
+EOF
+	chmod 755 editor.sh &&
+	GIT_EDITOR="./editor.sh" git checkout -S &&
+	grep sub .git/info/sparse-checkout &&
+	test -f sub/added &&
+	test ! -f init.t
+'
+
 test_done
templates/info--sparse-checkout +1 -0
index 7426475..588008b 100644
@@ -1,3 +1,4 @@
 # Specify what files are checked out in working directory
 # Run "git checkout" after updating this file to update working directory
+# If this is opened by "git checkout -S", empty this file will abort it.
 *
Signature · 1 line
1.7.3.2.210.g045198
#22 lore raw

Re: [PATCH 07/10] checkout: add -S to update sparse checkout

Quoted 11 lines · Nguyễn Thái Ngọc Duy
Documentation/git-checkout.txt +1 -0
@@ -12,6 +12,7 @@ SYNOPSIS
 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
 'git checkout' --patch [<tree-ish>] [--] [<paths>...]
+'git checkout' -S
 
 DESCRIPTION
 -----------

Documentation/git-checkout.txt the conflicted merge in the specified paths. · line 185

Quoted 9 lines
Documentation/git-checkout.txt +6 -0
@@ -176,6 +177,13 @@ the conflicted merge in the specified paths.
 This means that you can use `git checkout -p` to selectively discard
 edits from your current working tree.
 
+-S::
+--update-sparse-checkout::
+	An editor is invoked to let you update your sparse checkout
+	patterns. The updated patterns will be saved in
+	$GIT_DIR/info/sparse-checkout. The working directory is also
+	updated. An empty file will abort the process.

Wording nit: this doesn't make the worktree more up-to-date. How about:

--edit-sparse-checkout
--define-work-area
--narrow-worktree

Hmph.

--edit-sparse-checkout seems best for consistency of the choices I can think of.

[...]

Documentation/git-checkout.txt $ git add frotz · line 329

Quoted 7 lines
Documentation/git-checkout.txt +3 -0
@@ -316,6 +324,14 @@ $ git add frotz
 ------------
 
 
+ENVIRONMENT AND CONFIGURATION VARIABLES
+---------------------------------------
+The editor used to edit the commit log message will be chosen from the
                                 ^

patterns defining what subset of the tracked tree to work on

Documentation/git-checkout.txt $ git add frotz · line 330

Quoted 1 line
Documentation/git-checkout.txt +1 -0
+GIT_EDITOR environment variable, the core.editor configuration variable, the

Might be simpler to say:

CONFIGURATION
-------------
--edit-sparse-checkout uses the configured editor. See git-var(1) for details.

[...]

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 680

Quoted 9 lines
builtin/checkout.c +3 -0
@@ -675,6 +675,31 @@ static const char *unique_tracking_name(const char *name)
 	return NULL;
 }
 
+static void edit_info_sparse_checkout()
+{
+	char *tmpfile = xstrdup(git_path("sparse-checkout"));

git_pathdup()?

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 692

Quoted 12 lines
builtin/checkout.c +12 -0
+	struct exclude_list el;
+	int i;
+
+	copy_file(tmpfile, git_path("info/sparse-checkout"), 0666);
+
+	if (launch_editor(tmpfile, NULL, NULL))
+		exit(1);
+
+	memset(&el, 0, sizeof(el));
+	if (add_excludes_from_file_to_list(tmpfile, "", 0, NULL, &el, 0) < 0 ||
+	    el.nr == 0)
+		die("No valid sparse patterns. Abort.");

Perhaps the error message should mention the temp file.

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 695

Quoted 3 lines
builtin/checkout.c +3 -0
+	for (i = 0; i < el.nr; i++)
+		free(el.excludes[i]);
+	free(el.excludes);

Neat.

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 698

Quoted 3 lines
builtin/checkout.c +3 -0
+
+	if (rename(tmpfile, git_path("info/sparse-checkout")) < 0)
+		die_errno("Can't update %s", git_path("info/sparse-checkout"));

Wouldn't git_path() clobber errno? Probably worth keeping a temporary with the result from git_path before the rename.

Quoted 25 lines
builtin/checkout.c +7 -0
+
+	free(tmpfile);
+}
+
 int cmd_checkout(int argc, const char **argv, const char *prefix)
 {
 	struct checkout_opts opts;
@@ -685,6 +710,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	char *conflict_style = NULL;
 	int patch_mode = 0;
 	int dwim_new_local_branch = 1;
+	int update_sparse_checkout = 0;
 	struct option options[] = {
 		OPT__QUIET(&opts.quiet),
 		OPT_STRING('b', NULL, &opts.new_branch, "branch",
@@ -704,6 +730,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "conflict", &conflict_style, "style",
 			   "conflict style (merge or diff3)"),
 		OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
+		OPT_BOOLEAN('S', "update-sparse-checkout", &update_sparse_checkout,
+			    "open up editor to edit $GIT_DIR/info/sparse-checkout" ),
 		{ OPTION_BOOLEAN, 0, "guess", &dwim_new_local_branch, NULL,
 		  "second guess 'git checkout no-such-branch'",
 		  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },

builtin/checkout.c int cmd_checkout(int argc, const char **argv, const char *prefix) · line 754

Quoted 5 lines
builtin/checkout.c +2 -0
@@ -722,6 +750,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, checkout_usage,
 			     PARSE_OPT_KEEP_DASHDASH);
 
+	if (update_sparse_checkout && !core_apply_sparse_checkout)
+		die("core.sparseCheckout needs to be turned on");

--%s requires core.sparsecheckout to be turned out

builtin/checkout.c no_reference: · line 910

Quoted 11 lines
builtin/checkout.c +4 -0
+
 	/* we can assume from now on new_branch = !new_branch_force */
 	if (opts.new_branch && opts.new_branch_force)
 		die("-B cannot be used with -b");
@@ -874,6 +905,9 @@ no_reference:
 		if (!pathspec)
 			die("invalid path specification");
 
+		if (update_sparse_checkout)
+			die("git checkout: update paths is incompatible with updating sparse checkout.");
+

"updating paths is incompatible", I think.

Maybe an area for future work. :)

builtin/checkout.c no_reference: · line 931

Quoted 8 lines
builtin/checkout.c +3 -1
@@ -892,8 +926,11 @@ no_reference:
 		return checkout_paths(source_tree, pathspec, &opts);
 	}
 
-	if (patch_mode)
+	if (patch_mode) {
+		if (update_sparse_checkout)
+			die("git checkout: interactive checkout is incompatible with updating sparse checkout.");

Hmm, I'd put

	if (patch_mode && update_sparse_checkout)
		die(...

earlier as part of option validation.

[...]

t/t1011-read-tree-sparse-checkout.sh test_expect_success 'read-tree --reset removes outside worktree' ' · line 188

Quoted 8 lines
t/t1011-read-tree-sparse-checkout.sh +2 -0
@@ -184,4 +184,22 @@ test_expect_success 'read-tree --reset removes outside worktree' '
 	test_cmp empty result
 '
 
+test_expect_success 'git checkout -S fails to launch editor' '
+	GIT_EDITOR=/non-existent test_must_fail git checkout -S &&

Exporting envvars via a function is non-portable. The usual workaround:

	(
		GIT_EDITOR=... &&
		export  GIT_EDITOR &&
		test_must_fail ...
	) &&

Maybe it's time to introduce

eval_must_fail GIT_EDITOR=/non-existent git checkout -S

?

[...]

t/t1011-read-tree-sparse-checkout.sh test_expect_success 'read-tree --reset removes outside worktree' ' · line 197

Quoted 6 lines
t/t1011-read-tree-sparse-checkout.sh +6 -0
+test_expect_success 'git checkout -S' '
+	git checkout -f top &&
+	cat >editor.sh <<\EOF &&
+#!/bin/sh
+echo sub > "$1"
+EOF

Style: the git test scripts usually omit the space after >.

templates/info--sparse-checkout line 4

Quoted 7 lines
templates/info--sparse-checkout +1 -0
@@ -1,3 +1,4 @@
 # Specify what files are checked out in working directory
 # Run "git checkout" after updating this file to update working directory
+# If this is opened by "git checkout -S", empty this file will abort it.
 *

Usage nits: s/if/when/; s/opened/edited/; s/will/to/; s/it//.

# When editing with "git checkout -S", empty this file to abort.

#23 lore raw

Re: [PATCH 07/10] checkout: add -S to update sparse checkout

Quoted 10 lines · Jonathan Nieder

Documentation/git-checkout.txt the conflicted merge in the specified paths. · line 185

Quoted 6 lines
+-S::
+--update-sparse-checkout::
Documentation/git-checkout.txt +4 -0
+	An editor is invoked to let you update your sparse checkout
+	patterns. The updated patterns will be saved in
+	$GIT_DIR/info/sparse-checkout. The working directory is also
+	updated. An empty file will abort the process.

Wording nit: this doesn't make the worktree more up-to-date. How about:

Quoted 8 lines

--edit-sparse-checkout
--define-work-area
--narrow-worktree

Hmph.

--edit-sparse-checkout seems best for consistency of the choices I can think of.

"--change-sparse-checkout"?

Onna-account of "edit" sounding like you're actually somehow editting the checkout itself... OTOH, since it invokes the editor... hmmm

BTW, wouldn't it be more convenient to allow specifying patterns directly via the command line? I'd think in many (maybe the majority of) cases people will really only want one entry, and having to edit a file to specify it seems vaguely annoying...

-Miles

Signature · 1 line
.Numeric stability is probably not all that important when you're guessing.
#24 lore raw

Re: [PATCH 07/10] checkout: add -S to update sparse checkout

2010/11/16 Miles Bader <[email protected]>:

Quoted 22 lines
Quoted 10 lines · Jonathan Nieder
Quoted 6 lines
+-S::
+--update-sparse-checkout::

+    An editor is invoked to let you update your sparse checkout
+    patterns. The updated patterns will be saved in
+    $GIT_DIR/info/sparse-checkout. The working directory is also
+    updated. An empty file will abort the process.

Wording nit: this doesn't make the worktree more up-to-date.  How about:

Quoted 8 lines

 --edit-sparse-checkout
 --define-work-area
 --narrow-worktree

Hmph.

--edit-sparse-checkout seems best for consistency of the choices I can think of.

"--change-sparse-checkout"?

Quoted 7 lines

Onna-account of "edit" sounding like you're actually somehow editting the checkout itself...  OTOH, since it invokes the editor... hmmm

BTW, wouldn't it be more convenient to allow specifying patterns directly via the command line?  I'd think in many (maybe the majority of) cases people will really only want one entry, and having to edit a file to specify it seems vaguely annoying...

A command line option to append patterns only sounds good to me. But it would clutter up sparse-checkout file over time and may decrease performance. The same option can also be reused for git-clone. Do you suggest any name? I'm bad at naming.

I don't think I can make an option to remove patterns though.

Signature · 1 line
Duy
#25 lore raw

Re: [PATCH 07/10] checkout: add -S to update sparse checkout

In reply to Jonathan Nieder

2010/11/16 Jonathan Nieder <[email protected]>:

Quoted 16 lines
Quoted 6 lines

 DESCRIPTION
 -----------

(quoted diff) +0 -0
@@ -176,6 +177,13 @@ the conflicted merge in the specified paths.

 This means that you can use git checkout -p to selectively discard edits from your current working tree.

Quoted 6 lines
+-S::
+--update-sparse-checkout::

+     An editor is invoked to let you update your sparse checkout
+     patterns. The updated patterns will be saved in
+     $GIT_DIR/info/sparse-checkout. The working directory is also
+     updated. An empty file will abort the process.

Wording nit: this doesn't make the worktree more up-to-date.  How about:

Quoted 8 lines

 --edit-sparse-checkout
 --define-work-area
 --narrow-worktree

Hmph.

--edit-sparse-checkout seems best for consistency of the choices I can think of.

Yep. --edit-sparse-checkout.

Quoted 10 lines

Documentation/git-checkout.txt $ git add frotz · line 329

Quoted 7 lines
(quoted diff) +0 -0
@@ -316,6 +324,14 @@ $ git add frotz

 ------------

Documentation/git-checkout.txt +3 -0
+ENVIRONMENT AND CONFIGURATION VARIABLES
+---------------------------------------
+The editor used to edit the commit log message will be chosen from the

                                ^
 patterns defining what subset of the tracked tree to work on

Quoted 3 lines
Quoted 1 line

+GIT_EDITOR environment variable, the core.editor configuration variable, the

Might be simpler to say:

That was copied from git-commit.txt (I think). Maybe that file should be updated too.

Quoted 7 lines

[...]

Quoted 6 lines
builtin/checkout.c +0 -0
@@ -675,6 +675,31 @@ static const char *unique_tracking_name(const char *name)
       return NULL;
  }
 
Quoted 5 lines

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 680

Quoted 3 lines
builtin/checkout.c +3 -0
+static void edit_info_sparse_checkout()
+{
+     char *tmpfile = xstrdup(git_path("sparse-checkout"));

git_pathdup()?

Yup.

Quoted 6 lines

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 695

Quoted 4 lines
builtin/checkout.c +3 -0
+     for (i = 0; i < el.nr; i++)
+             free(el.excludes[i]);
+     free(el.excludes);

Neat.

This code is actually duplicated in unpack_trees(). It's time to create free_exclude() function.

Quoted 6 lines

builtin/checkout.c static const char *unique_tracking_name(const char *name) · line 698

Quoted 3 lines
builtin/checkout.c +3 -0
+
+     if (rename(tmpfile, git_path("info/sparse-checkout")) < 0)
+             die_errno("Can't update %s", git_path("info/sparse-checkout"));

Wouldn't git_path() clobber errno?  Probably worth keeping a temporary with the result from git_path before the rename.

OK

Quoted 17 lines
Quoted 8 lines
t/t1011-read-tree-sparse-checkout.sh +0 -0
@@ -184,4 +184,22 @@ test_expect_success 'read-tree --reset removes outside worktree' '

      test_cmp empty result
 '

+test_expect_success 'git checkout -S fails to launch editor' '
+     GIT_EDITOR=/non-existent test_must_fail git checkout -S &&

Exporting envvars via a function is non-portable.  The usual workaround:

       (
               GIT_EDITOR=... &&
               export  GIT_EDITOR &&
               test_must_fail ...
       ) &&

Quoted 5 lines

Maybe it's time to introduce

       eval_must_fail GIT_EDITOR=/non-existent git checkout -S

?

I'll go with the former.

Signature · 1 line
Duy
#26 lore raw

PATCH 8/10 checkout: add --full to fully populate working directory

In reply to Nguyễn Thái Ngọc Duy
---
 Documentation/git-checkout.txt       |    6 +++++-
 builtin/checkout.c                   |   23 ++++++++++++++++++++---
 t/t1011-read-tree-sparse-checkout.sh |    7 +++++++
 3 files changed, 32 insertions(+), 4 deletions(-)
Documentation/git-checkout.txt +5 -1
index 478bfe7..1d82063 100644
@@ -12,7 +12,7 @@ SYNOPSIS
 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
 'git checkout' --patch [<tree-ish>] [--] [<paths>...]
-'git checkout' -S
+'git checkout' [-S|--full]
 
 DESCRIPTION
 -----------
@@ -184,6 +184,10 @@ edits from your current working tree.
 	$GIT_DIR/info/sparse-checkout. The working directory is also
 	updated. An empty file will abort the process.
 
+--full:
+	Reset $GIT_DIR/info/sparse-checkout to include everything and
+	update working directory accordingly.
+
 <branch>::
 	Branch to checkout; if it refers to a branch (i.e., a name that,
 	when prepended with "refs/heads/", is a valid ref), then that
builtin/checkout.c +20 -3
index 47847b3..f070930 100644
@@ -710,7 +710,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	char *conflict_style = NULL;
 	int patch_mode = 0;
 	int dwim_new_local_branch = 1;
-	int update_sparse_checkout = 0;
+	int update_sparse_checkout = 0, full_checkout = 0;
 	struct option options[] = {
 		OPT__QUIET(&opts.quiet),
 		OPT_STRING('b', NULL, &opts.new_branch, "branch",
@@ -732,6 +732,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
 		OPT_BOOLEAN('S', "update-sparse-checkout", &update_sparse_checkout,
 			    "open up editor to edit $GIT_DIR/info/sparse-checkout" ),
+		OPT_BOOLEAN(0, "full", &full_checkout,
+			    "reset $GIT_DIR/info/sparse-checkout to checkout everything" ),
 		{ OPTION_BOOLEAN, 0, "guess", &dwim_new_local_branch, NULL,
 		  "second guess 'git checkout no-such-branch'",
 		  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
@@ -750,6 +752,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, checkout_usage,
 			     PARSE_OPT_KEEP_DASHDASH);
 
+	if (full_checkout)
+		update_sparse_checkout = 1;
+
 	if (update_sparse_checkout && !core_apply_sparse_checkout)
 		die("core.sparseCheckout needs to be turned on");
 
@@ -952,8 +957,20 @@ no_reference:
 	if (opts.writeout_stage)
 		die("--ours/--theirs is incompatible with switching branches.");
 
-	if (update_sparse_checkout)
-		edit_info_sparse_checkout();
+	if (update_sparse_checkout) {
+		if (full_checkout) {
+			FILE *fp = fopen(git_path("info/sparse-checkout"), "w+");
+			if (!fp)
+				die_errno("Unable to reset %s", git_path("info/sparse-checkout"));
+			fprintf(fp, "# Specify what files are checked out in working directory\n");
+			fprintf(fp, "# Run \"git checkout\" after updating this file to update working directory\n");
+			fprintf(fp, "# If this is opened by \"git checkout -S\", empty this file will abort it.\n");
+			fprintf(fp, "*\n");
+			fclose(fp);
+		}
+		else
+			edit_info_sparse_checkout(full_checkout);
+	}
 
 	return switch_branches(&opts, &new);
 }
t/t1011-read-tree-sparse-checkout.sh +7 -0
index fe4716c..055e858 100755
@@ -202,4 +202,11 @@ EOF
 	test ! -f init.t
 '
 
+test_expect_success 'git checkout --full' '
+	git checkout --full &&
+	grep "^\*$" .git/info/sparse-checkout &&
+	test -f sub/added &&
+	test -f init.t
+'
+
 test_done
Signature · 1 line
1.7.3.2.210.g045198
#27 lore raw

Re: [PATCH 08/10] checkout: add --full to fully populate working directory

Documentation/git-checkout.txt SYNOPSIS · line 15

Quoted 8 lines · Nguyễn Thái Ngọc Duy
Documentation/git-checkout.txt +1 -1
@@ -12,7 +12,7 @@ SYNOPSIS
 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
 'git checkout' --patch [<tree-ish>] [--] [<paths>...]
-'git checkout' -S
+'git checkout' [-S|--full]

Brackets mean "optional".

Documentation/git-checkout.txt edits from your current working tree. · line 189

Quoted 7 lines
Documentation/git-checkout.txt +3 -0
@@ -184,6 +184,10 @@ edits from your current working tree.
 	$GIT_DIR/info/sparse-checkout. The working directory is also
 	updated. An empty file will abort the process.
 
+--full:
+	Reset $GIT_DIR/info/sparse-checkout to include everything and
+	update working directory accordingly.

Maybe say something about "widen" and "whole project"?

builtin/checkout.c no_reference: · line 962

Quoted 11 lines
builtin/checkout.c +3 -2
@@ -952,8 +957,20 @@ no_reference:
 	if (opts.writeout_stage)
 		die("--ours/--theirs is incompatible with switching branches.");
 
-	if (update_sparse_checkout)
-		edit_info_sparse_checkout();
+	if (update_sparse_checkout) {
+		if (full_checkout) {
+			FILE *fp = fopen(git_path("info/sparse-checkout"), "w+");

What should --full --edit-worktree-shape-or-whatever-that-was-called do?

t/t1011-read-tree-sparse-checkout.sh EOF · line 209

Quoted 11 lines
t/t1011-read-tree-sparse-checkout.sh +5 -0
@@ -202,4 +202,11 @@ EOF
 	test ! -f init.t
 '
 
+test_expect_success 'git checkout --full' '
+	git checkout --full &&
+	grep "^\*$" .git/info/sparse-checkout &&
+	test -f sub/added &&
+	test -f init.t

Probably worth checking that that's the only pattern in the file so short-circuiting happens.

#28 lore raw

Re: [PATCH 08/10] checkout: add --full to fully populate working directory

2010/11/16 Jonathan Nieder <[email protected]>:

Quoted 6 lines
Quoted 6 lines
builtin/checkout.c +0 -0
@@ -952,8 +957,20 @@ no_reference:
       if (opts.writeout_stage)
               die("--ours/--theirs is incompatible with switching branches.");
 
Quoted 7 lines

builtin/checkout.c no_reference: · line 962

Quoted 5 lines
builtin/checkout.c +3 -2
-     if (update_sparse_checkout)
-             edit_info_sparse_checkout();
+     if (update_sparse_checkout) {
+             if (full_checkout) {
+                     FILE *fp = fopen(git_path("info/sparse-checkout"), "w+");

What should --full --edit-worktree-shape-or-whatever-that-was-called do?

Should die().

Signature · 1 line
Duy
#29 lore raw

PATCH 9/10 git-checkout.txt: mention of sparse checkout

In reply to Nguyễn Thái Ngọc Duy

All the boring technical stuff still resides in git-read-tree.txt. The introduction here targets end users.

---
 Documentation/git-checkout.txt  |   29 +++++++++++++++++++++++++++++
 Documentation/git-read-tree.txt |   11 +----------
 2 files changed, 30 insertions(+), 10 deletions(-)
Documentation/git-checkout.txt +29 -0
index 1d82063..b9a97c9 100644
@@ -253,6 +253,35 @@ $ git log -g -2 HEAD
 ------------
 
 
+Sparse checkout
+---------------
+
+"Sparse checkout" allows to sparsely populate working directory
+according to patterns defined in `$GIT_DIR/info/sparse-checkout`. The
+syntax of this file is similar to linkgit:gitignore[5].  This feature
+requires core.sparseCheckout to be turned on. `git checkout -S` should
+be used when editing this file. It will update working directory
+properly after editing. See linkgit:git-read-tree[1] for more
+information.
+
+Normally sparse-checkout file contains only one rule, which indicates
+that all files are checked out:
+
+----------------
+*
+----------------
+
+You can update the file to only contain files you want to be checked
+out, or files _not_ to be checked out, using negate patterns. For
+example, to remove file "unwanted":
+
+----------------
+*
+!unwanted
+----------------
+
+To fully populate working directory again, use "git checkout --full".
+
 EXAMPLES
 --------
 
Documentation/git-read-tree.txt +1 -10
index 634423a..4b72c96 100644
@@ -390,16 +390,7 @@ Then it compares the new skip-worktree value with the previous one. If
 skip-worktree turns from unset to set, it will add the corresponding
 file back. If it turns from set to unset, that file will be removed.
 
-While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
-files are in. You can also specify what files are _not_ in, using
-negate patterns. For example, to remove file "unwanted":
-
-----------------
-*
-!unwanted
-----------------
-
-Another tricky thing is fully repopulating working directory when you
+A tricky thing is fully repopulating working directory when you
 no longer want sparse checkout. You cannot just disable "sparse
 checkout" because skip-worktree are still in the index and you working
 directory is still sparsely populated. You should re-populate working
Signature · 1 line
1.7.3.2.210.g045198
#30 lore raw

PATCH 10/10 clean: support cleaning sparse checkout with -S

In reply to Nguyễn Thái Ngọc Duy

Those files that are managed by git, but out of working directory due to sparse-checkout file are subjected to be cleaned by "-S". Files that match the index exactly will be cleaned without "-f". Otherwise '-f' is needed.

---
 Documentation/git-clean.txt |    6 ++-
 builtin/clean.c             |   70 ++++++++++++++++++++++++++++++++
 t/t7301-clean-sparse.sh     |   92 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 167 insertions(+), 1 deletions(-)
 create mode 100755 t/t7301-clean-sparse.sh
Documentation/git-clean.txt +5 -1
index 60e38e6..e0c95b1 100644
@@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree
 SYNOPSIS
 --------
 [verse]
-'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...
+'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X | -S] [--] <path>...
 
 DESCRIPTION
 -----------
@@ -61,6 +61,10 @@ OPTIONS
 	Remove only files ignored by git.  This may be useful to rebuild
 	everything from scratch, but keep manually created files.
 
+-S::
+	Remove files tracked by git but are outside of sparse checkout.
+	Files that match the index exactly will be removed even when
+	'-f' is not given and clean.requireForce is no.
 
 Author
 ------
builtin/clean.c +70 -0

93 lines not on this page · raw message

t/t7301-clean-sparse.sh new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
1.7.3.2.210.g045198
#31 lore raw

Re: [PATCH 10/10] clean: support cleaning sparse checkout with -S

Quoted 2 lines · Nguyễn Thái Ngọc Duy

Files
that match the index exactly will be cleaned without "-f".

Hmm, that's new. Seems fine, though; a person using -S would be forwarned.

Documentation/git-clean.txt git-clean - Remove untracked files from the working tree · line 11

Quoted 8 lines
Documentation/git-clean.txt +1 -1
@@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree
 SYNOPSIS
 --------
 [verse]
-'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...
+'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X | -S] [--] <path>...

So -S and -x don't combine?

Documentation/git-clean.txt OPTIONS · line 67

Quoted 11 lines
Documentation/git-clean.txt +4 -0
 DESCRIPTION
 -----------
@@ -61,6 +61,10 @@ OPTIONS
 	Remove only files ignored by git.  This may be useful to rebuild
 	everything from scratch, but keep manually created files.
 
+-S::
+	Remove files tracked by git but are outside of sparse checkout.
+	Files that match the index exactly will be removed even when
+	'-f' is not given and clean.requireForce is no.

Does "no" mean "yes" here?

Probably worth mentioning that -S does not apply here.

Would it be worth adding a -s/--clean-full-worktree option to complete the analogy to -X?

builtin/clean.c

Quoted 2 lines
builtin/clean.c +0 -0

Not reading the code or tests because I'm trusting that I wouldn't need to use this command. :)

Thanks, sparse checkout is looking sane now.

#32 lore raw

Re: [PATCH 10/10] clean: support cleaning sparse checkout with -S

2010/11/16 Jonathan Nieder <[email protected]>:

Quoted 7 lines
Quoted 2 lines · Nguyễn Thái Ngọc Duy

                                                             Files that match the index exactly will be cleaned without "-f".

Hmm, that's new.  Seems fine, though; a person using -S would be forwarned.

It's safe, which is why I let it do that without '-f'. One can always checkout those entries again (provided that they know what entries to checkout).

How do you want them to be warned?

Quoted 10 lines
Quoted 8 lines
Documentation/git-clean.txt +0 -0
@@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree

 SYNOPSIS
 --------
 [verse]
-'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>... +'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X | -S] [--] <path>...

So -S and -x don't combine?

No. Technical difficulties. Wait, nothing prevents me from doing that. Yes combination is possible.

Quoted 7 lines
Quoted 7 lines

 DESCRIPTION
 -----------

Documentation/git-clean.txt +0 -0
@@ -61,6 +61,10 @@ OPTIONS

      Remove only files ignored by git.  This may be useful to rebuild everything from scratch, but keep manually created files.

Quoted 6 lines
Quoted 4 lines

+-S::
+     Remove files tracked by git but are outside of sparse checkout.
+     Files that match the index exactly will be removed even when
+     '-f' is not given and clean.requireForce is no.

Does "no" mean "yes" here?

Probably, need to look at the that config variable again :(

Signature · 1 line
Duy
#33 lore raw

Re: [PATCH 10/10] clean: support cleaning sparse checkout with -S

Quoted 10 lines · Nguyen Thai Ngoc Duy

2010/11/16 Jonathan Nieder <[email protected]>:

Quoted 2 lines

Hmm, that's new.  Seems fine, though; a person using -S would be forwarned.

It's safe, which is why I let it do that without '-f'. One can always checkout those entries again (provided that they know what entries to checkout).

How do you want them to be warned?

Manual and -h output, ideally.

Quoted 1 line

OPT_BOOLEAN('S', NULL, &sparse, "remove tracked files outside sparse checkout"),

Maybe something to the effect of

		OPT_SET_INT('S', NULL, &sparse,
			"prune worktree to sparse pattern (even without -f)", 1),

Probably someone will chime in with the perfect wording that fits in the 80-column "git clean -h" output format. :)