Skip to content

Commit 2dc94da

Browse files
committed
Merge branch 'en/sparse-checkout-set'
The "init" and "set" subcommands in "git sparse-checkout" have been unified for a better user experience and performance. * en/sparse-checkout-set: sparse-checkout: remove stray trailing space clone: avoid using deprecated `sparse-checkout init` Documentation: clarify/correct a few sparsity related statements git-sparse-checkout.txt: update to document init/set/reapply changes sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} sparse-checkout: enable `set` to initialize sparse-checkout mode sparse-checkout: split out code for tweaking settings config sparse-checkout: disallow --no-stdin as an argument to set sparse-checkout: add sanity-checks on initial sparsity state sparse-checkout: break apart functions for sparse_checkout_(set|add) sparse-checkout: pass use_stdin as a parameter instead of as a global
2 parents 4f4b184 + dfac9b6 commit 2dc94da

File tree

5 files changed

+227
-97
lines changed

5 files changed

+227
-97
lines changed

Documentation/git-clone.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ objects from the source repository into a pack in the cloned repository.
167167
configuration variables are created.
168168

169169
--sparse::
170-
Initialize the sparse-checkout file so the working
171-
directory starts with only the files in the root
172-
of the repository. The sparse-checkout file can be
173-
modified to grow the working directory as needed.
170+
Employ a sparse-checkout, with only files in the toplevel
171+
directory initially being present. The
172+
linkgit:git-sparse-checkout[1] command can be used to grow the
173+
working directory as needed.
174174

175175
--filter=<filter-spec>::
176176
Use the partial clone feature and request that the server sends

Documentation/git-sparse-checkout.txt

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,36 @@ COMMANDS
3030
'list'::
3131
Describe the patterns in the sparse-checkout file.
3232

33-
'init'::
34-
Enable the `core.sparseCheckout` setting. If the
35-
sparse-checkout file does not exist, then populate it with
36-
patterns that match every file in the root directory and
37-
no other directories, then will remove all directories tracked
38-
by Git. Add patterns to the sparse-checkout file to
39-
repopulate the working directory.
33+
'set'::
34+
Enable the necessary config settings
35+
(extensions.worktreeConfig, core.sparseCheckout,
36+
core.sparseCheckoutCone) if they are not already enabled, and
37+
write a set of patterns to the sparse-checkout file from the
38+
list of arguments following the 'set' subcommand. Update the
39+
working directory to match the new patterns.
4040
+
41-
To avoid interfering with other worktrees, it first enables the
42-
`extensions.worktreeConfig` setting and makes sure to set the
43-
`core.sparseCheckout` setting in the worktree-specific config file.
41+
When the `--stdin` option is provided, the patterns are read from
42+
standard in as a newline-delimited list instead of from the arguments.
4443
+
45-
When `--cone` is provided, the `core.sparseCheckoutCone` setting is
46-
also set, allowing for better performance with a limited set of
47-
patterns (see 'CONE PATTERN SET' below).
44+
When `--cone` is passed or `core.sparseCheckoutCone` is enabled, the
45+
input list is considered a list of directories instead of
46+
sparse-checkout patterns. This allows for better performance with a
47+
limited set of patterns (see 'CONE PATTERN SET' below). Note that the
48+
set command will write patterns to the sparse-checkout file to include
49+
all files contained in those directories (recursively) as well as
50+
files that are siblings of ancestor directories. The input format
51+
matches the output of `git ls-tree --name-only`. This includes
52+
interpreting pathnames that begin with a double quote (") as C-style
53+
quoted strings. This may become the default in the future; --no-cone
54+
can be passed to request non-cone mode.
4855
+
49-
Use the `--[no-]sparse-index` option to toggle the use of the sparse
50-
index format. This reduces the size of the index to be more closely
51-
aligned with your sparse-checkout definition. This can have significant
52-
performance advantages for commands such as `git status` or `git add`.
53-
This feature is still experimental. Some commands might be slower with
54-
a sparse index until they are properly integrated with the feature.
56+
Use the `--[no-]sparse-index` option to use a sparse index (the
57+
default is to not use it). A sparse index reduces the size of the
58+
index to be more closely aligned with your sparse-checkout
59+
definition. This can have significant performance advantages for
60+
commands such as `git status` or `git add`. This feature is still
61+
experimental. Some commands might be slower with a sparse index until
62+
they are properly integrated with the feature.
5563
+
5664
**WARNING:** Using a sparse index requires modifying the index in a way
5765
that is not completely understood by external tools. If you have trouble
@@ -60,23 +68,6 @@ to rewrite your index to not be sparse. Older versions of Git will not
6068
understand the sparse directory entries index extension and may fail to
6169
interact with your repository until it is disabled.
6270

63-
'set'::
64-
Write a set of patterns to the sparse-checkout file, as given as
65-
a list of arguments following the 'set' subcommand. Update the
66-
working directory to match the new patterns. Enable the
67-
core.sparseCheckout config setting if it is not already enabled.
68-
+
69-
When the `--stdin` option is provided, the patterns are read from
70-
standard in as a newline-delimited list instead of from the arguments.
71-
+
72-
When `core.sparseCheckoutCone` is enabled, the input list is considered a
73-
list of directories instead of sparse-checkout patterns. The command writes
74-
patterns to the sparse-checkout file to include all files contained in those
75-
directories (recursively) as well as files that are siblings of ancestor
76-
directories. The input format matches the output of `git ls-tree --name-only`.
77-
This includes interpreting pathnames that begin with a double quote (") as
78-
C-style quoted strings.
79-
8071
'add'::
8172
Update the sparse-checkout file to include additional patterns.
8273
By default, these patterns are read from the command-line arguments,
@@ -93,12 +84,35 @@ C-style quoted strings.
9384
cases, it can make sense to run `git sparse-checkout reapply` later
9485
after cleaning up affected paths (e.g. resolving conflicts, undoing
9586
or committing changes, etc.).
87+
+
88+
The `reapply` command can also take `--[no-]cone` and `--[no-]sparse-index`
89+
flags, with the same meaning as the flags from the `set` command, in order
90+
to change which sparsity mode you are using without needing to also respecify
91+
all sparsity paths.
9692

9793
'disable'::
9894
Disable the `core.sparseCheckout` config setting, and restore the
99-
working directory to include all files. Leaves the sparse-checkout
100-
file intact so a later 'git sparse-checkout init' command may
101-
return the working directory to the same state.
95+
working directory to include all files.
96+
97+
'init'::
98+
Deprecated command that behaves like `set` with no specified paths.
99+
May be removed in the future.
100+
+
101+
Historically, `set` did not handle all the necessary config settings,
102+
which meant that both `init` and `set` had to be called. Invoking
103+
both meant the `init` step would first remove nearly all tracked files
104+
(and in cone mode, ignored files too), then the `set` step would add
105+
many of the tracked files (but not ignored files) back. In addition
106+
to the lost files, the performance and UI of this combination was
107+
poor.
108+
+
109+
Also, historically, `init` would not actually initialize the
110+
sparse-checkout file if it already existed. This meant it was
111+
possible to return to a sparse-checkout without remembering which
112+
paths to pass to a subsequent 'set' or 'add' command. However,
113+
`--cone` and `--sparse-index` options would not be remembered across
114+
the disable command, so the easy restore of calling a plain `init`
115+
decreased in utility.
102116

103117
SPARSE CHECKOUT
104118
---------------
@@ -107,7 +121,7 @@ SPARSE CHECKOUT
107121
It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
108122
Git whether a file in the working directory is worth looking at. If
109123
the skip-worktree bit is set, then the file is ignored in the working
110-
directory. Git will not populate the contents of those files, which
124+
directory. Git will avoid populating the contents of those files, which
111125
makes a sparse checkout helpful when working in a repository with many
112126
files, but only a few are important to the current user.
113127

@@ -117,10 +131,8 @@ directory, it updates the skip-worktree bits in the index based
117131
on this file. The files matching the patterns in the file will
118132
appear in the working directory, and the rest will not.
119133

120-
To enable the sparse-checkout feature, run `git sparse-checkout init` to
121-
initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
122-
config setting. Then, run `git sparse-checkout set` to modify the patterns in
123-
the sparse-checkout file.
134+
To enable the sparse-checkout feature, run `git sparse-checkout set` to
135+
set the patterns you want to use.
124136

125137
To repopulate the working directory with all files, use the
126138
`git sparse-checkout disable` command.

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static int git_sparse_checkout_init(const char *repo)
633633
{
634634
struct strvec argv = STRVEC_INIT;
635635
int result = 0;
636-
strvec_pushl(&argv, "-C", repo, "sparse-checkout", "init", NULL);
636+
strvec_pushl(&argv, "-C", repo, "sparse-checkout", "set", NULL);
637637

638638
/*
639639
* We must apply the setting in the current process

0 commit comments

Comments
 (0)