forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sparse-checkout builtin: upstreamable version #180
Merged
derrickstolee
merged 10 commits into
microsoft:features/sparse-checkout-2.23.0
from
derrickstolee:sparse-checkout/v1
Aug 22, 2019
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ab2e063
sparse-checkout: create builtin with 'list' subcommand
derrickstolee 35700b3
sparse-checkout: create 'init' subcommand
derrickstolee 4e8e6c3
clone: add --sparse mode
derrickstolee 8913c25
sparse-checkout: 'add' subcommand
derrickstolee c08d037
sparse-checkout: create 'disable' subcommand
derrickstolee 4aee073
trace2:experiment: clear_ce_flags_1
jeffhostetler 6c1b7fb
sparse-checkout: add 'cone' mode
derrickstolee 79a042c
sparse-checkout: use hashmaps for cone patterns
derrickstolee 19ad979
sparse-checkout: init and add in cone mode
derrickstolee 181fb3b
Merge branch 'sparse-checkout/v1'
derrickstolee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
git-sparse-checkout(1) | ||
======================= | ||
|
||
NAME | ||
---- | ||
git-sparse-checkout - Initialize and modify the sparse-checkout | ||
configuration, which reduces the checkout to a set of directories | ||
given by a list of prefixes. | ||
|
||
|
||
SYNOPSIS | ||
-------- | ||
[verse] | ||
'git sparse-checkout <subcommand> [options]' | ||
|
||
|
||
DESCRIPTION | ||
----------- | ||
|
||
Initialize and modify the sparse-checkout configuration, which reduces | ||
the checkout to a set of directories given by a list of prefixes. | ||
|
||
|
||
COMMANDS | ||
-------- | ||
'list':: | ||
Provide a list of the contents in the sparse-checkout file. | ||
|
||
|
||
SPARSE CHECKOUT | ||
---------------- | ||
|
||
"Sparse checkout" allows populating the working directory sparsely. | ||
It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell | ||
Git whether a file in the working directory is worth looking at. If | ||
the skip-worktree bit is set, then the file is ignored in the working | ||
directory. Git will not populate the contents of those files, which | ||
makes a sparse checkout helpful when working in a repository with many | ||
files, but only a few are important to the current user. | ||
|
||
The `$GIT_DIR/info/sparse-checkout` file is used to define the | ||
skip-worktree reference bitmap. When Git updates the working | ||
directory, it resets the skip-worktree bit in the index based on this | ||
file. If an entry | ||
matches a pattern in this file, skip-worktree will not be set on | ||
that entry. Otherwise, skip-worktree will be set. | ||
|
||
Then it compares the new skip-worktree value with the previous one. If | ||
skip-worktree turns from set to unset, it will add the corresponding | ||
file back. If it turns from unset to set, that file will be removed. | ||
|
||
## FULL PATTERN SET | ||
|
||
By default, the sparse-checkout file uses the same syntax as `.gitignore` | ||
files. | ||
|
||
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 the file `unwanted`: | ||
|
||
---------------- | ||
/* | ||
!unwanted | ||
---------------- | ||
|
||
Another tricky thing is fully repopulating the working directory when you | ||
no longer want sparse checkout. You cannot just disable "sparse | ||
checkout" because skip-worktree bits are still in the index and your working | ||
directory is still sparsely populated. You should re-populate the working | ||
directory with the `$GIT_DIR/info/sparse-checkout` file content as | ||
follows: | ||
|
||
---------------- | ||
/* | ||
---------------- | ||
|
||
Then you can disable sparse checkout. Sparse checkout support in 'git | ||
read-tree' and similar commands is disabled by default. You need to | ||
set `core.sparseCheckout` to `true` in order to have sparse checkout | ||
support. | ||
|
||
SEE ALSO | ||
-------- | ||
|
||
linkgit:git-read-tree[1] | ||
linkgit:gitignore[1] | ||
|
||
GIT | ||
--- | ||
Part of the linkgit:git[1] suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "builtin.h" | ||
#include "config.h" | ||
#include "dir.h" | ||
#include "parse-options.h" | ||
#include "pathspec.h" | ||
#include "repository.h" | ||
#include "run-command.h" | ||
#include "strbuf.h" | ||
|
||
static char const * const builtin_sparse_checkout_usage[] = { | ||
N_("git sparse-checkout [list]"), | ||
NULL | ||
}; | ||
|
||
struct opts_sparse_checkout { | ||
const char *subcommand; | ||
int read_stdin; | ||
} opts; | ||
|
||
static char *get_sparse_checkout_filename(void) | ||
{ | ||
return git_pathdup("info/sparse-checkout"); | ||
} | ||
|
||
static void write_excludes_to_file(FILE *fp, struct exclude_list *el) | ||
{ | ||
int i; | ||
|
||
for (i = 0; i < el->nr; i++) { | ||
struct exclude *x = el->excludes[i]; | ||
|
||
if (x->flags & EXC_FLAG_NEGATIVE) | ||
fprintf(fp, "!"); | ||
|
||
fprintf(fp, "%s", x->pattern); | ||
|
||
if (x->flags & EXC_FLAG_MUSTBEDIR) | ||
fprintf(fp, "/"); | ||
|
||
fprintf(fp, "\n"); | ||
} | ||
} | ||
|
||
static int sparse_checkout_list(int argc, const char **argv) | ||
{ | ||
struct exclude_list el; | ||
char *sparse_filename; | ||
int res; | ||
|
||
memset(&el, 0, sizeof(el)); | ||
|
||
sparse_filename = get_sparse_checkout_filename(); | ||
res = add_excludes_from_file_to_list(sparse_filename, "", 0, &el, NULL); | ||
free(sparse_filename); | ||
|
||
if (res < 0) { | ||
warning(_("failed to parse sparse-checkout file; it may not exist")); | ||
return 0; | ||
} | ||
|
||
write_excludes_to_file(stdout, &el); | ||
clear_exclude_list(&el); | ||
|
||
return 0; | ||
} | ||
|
||
int cmd_sparse_checkout(int argc, const char **argv, const char *prefix) | ||
{ | ||
static struct option builtin_sparse_checkout_options[] = { | ||
OPT_END(), | ||
}; | ||
|
||
if (argc == 2 && !strcmp(argv[1], "-h")) | ||
usage_with_options(builtin_sparse_checkout_usage, | ||
builtin_sparse_checkout_options); | ||
|
||
git_config(git_default_config, NULL); | ||
argc = parse_options(argc, argv, prefix, | ||
builtin_sparse_checkout_options, | ||
builtin_sparse_checkout_usage, | ||
PARSE_OPT_STOP_AT_NON_OPTION); | ||
|
||
if (argc > 0) { | ||
if (!strcmp(argv[0], "list")) | ||
return sparse_checkout_list(argc, argv); | ||
} | ||
|
||
usage_with_options(builtin_sparse_checkout_usage, | ||
builtin_sparse_checkout_options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/sh | ||
|
||
test_description='sparse checkout builtin tests' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'setup' ' | ||
git init repo && | ||
( | ||
cd repo && | ||
echo "initial" >a && | ||
mkdir folder1 folder2 deep && | ||
mkdir deep/deeper1 deep/deeper2 && | ||
mkdir deep/deeper1/deepest && | ||
cp a folder1 && | ||
cp a folder2 && | ||
cp a deep && | ||
cp a deep/deeper1 && | ||
cp a deep/deeper2 && | ||
cp a deep/deeper1/deepest && | ||
git add . && | ||
git commit -m "initial commit" | ||
) | ||
' | ||
|
||
test_expect_success 'git sparse-checkout list (empty)' ' | ||
git -C repo sparse-checkout list >list 2>err && | ||
test_line_count = 0 list && | ||
test_i18ngrep "failed to parse sparse-checkout file; it may not exist" err | ||
' | ||
|
||
test_expect_success 'git sparse-checkout list (populated)' ' | ||
test_when_finished rm -f repo/.git/info/sparse-checkout && | ||
cat >repo/.git/info/sparse-checkout <<-EOF && | ||
/folder1/* | ||
/deep/ | ||
**/a | ||
!*bin* | ||
EOF | ||
git -C repo sparse-checkout list >list && | ||
cat >expect <<-EOF && | ||
/folder1/* | ||
/deep/ | ||
**/a | ||
!*bin* | ||
EOF | ||
test_cmp expect list | ||
' | ||
|
||
test_done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 paragraphs are a bit muddy. But I don't want to bog us down wordsmith-ing right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also, many of them are copied directory from
Documentation/git-read-tree.txt
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was afraid of that....