summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-11-21 22:04:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-11-22 07:11:44 (GMT)
commit7bffca95ea1ca4f55663374ea9b929b9df5be04b (patch)
tree7a4895c16d6dfaf38faffce8220ecd34d0c1ac6c /builtin
parentf6039a9423d042d61fb4cfccb395bd04c4bd5322 (diff)
downloadgit-7bffca95ea1ca4f55663374ea9b929b9df5be04b.zip
git-7bffca95ea1ca4f55663374ea9b929b9df5be04b.tar.gz
git-7bffca95ea1ca4f55663374ea9b929b9df5be04b.tar.bz2
sparse-checkout: add '--stdin' option to set subcommand
The 'git sparse-checkout set' subcommand takes a list of patterns and places them in the sparse-checkout file. Then, it updates the working directory to match those patterns. For a large list of patterns, the command-line call can get very cumbersome. Add a '--stdin' option to instead read patterns over standard in. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/sparse-checkout.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 95cbd0a..82bff00 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -150,6 +150,15 @@ static int write_patterns_and_update(struct pattern_list *pl)
return update_working_directory();
}
+static char const * const builtin_sparse_checkout_set_usage[] = {
+ N_("git sparse-checkout set (--stdin | <patterns>)"),
+ NULL
+};
+
+static struct sparse_checkout_set_opts {
+ int use_stdin;
+} set_opts;
+
static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
{
static const char *empty_base = "";
@@ -157,10 +166,31 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
struct pattern_list pl;
int result;
int changed_config = 0;
+
+ static struct option builtin_sparse_checkout_set_options[] = {
+ OPT_BOOL(0, "stdin", &set_opts.use_stdin,
+ N_("read patterns from standard in")),
+ OPT_END(),
+ };
+
memset(&pl, 0, sizeof(pl));
- for (i = 1; i < argc; i++)
- add_pattern(argv[i], empty_base, 0, &pl, 0);
+ argc = parse_options(argc, argv, prefix,
+ builtin_sparse_checkout_set_options,
+ builtin_sparse_checkout_set_usage,
+ PARSE_OPT_KEEP_UNKNOWN);
+
+ if (set_opts.use_stdin) {
+ struct strbuf line = STRBUF_INIT;
+
+ while (!strbuf_getline(&line, stdin)) {
+ char *buf = strbuf_detach(&line, NULL);
+ add_pattern(buf, empty_base, 0, &pl, 0);
+ }
+ } else {
+ for (i = 0; i < argc; i++)
+ add_pattern(argv[i], empty_base, 0, &pl, 0);
+ }
if (!core_apply_sparse_checkout) {
set_config(MODE_ALL_PATTERNS);