]> git.ipfire.org Git - thirdparty/git.git/blob - builtin/sparse-checkout.c
repo-settings: rename the traditional default fetch.negotiationAlgorithm
[thirdparty/git.git] / builtin / sparse-checkout.c
1 #include "builtin.h"
2 #include "config.h"
3 #include "dir.h"
4 #include "parse-options.h"
5 #include "pathspec.h"
6 #include "repository.h"
7 #include "run-command.h"
8 #include "strbuf.h"
9 #include "string-list.h"
10 #include "cache.h"
11 #include "cache-tree.h"
12 #include "lockfile.h"
13 #include "resolve-undo.h"
14 #include "unpack-trees.h"
15 #include "wt-status.h"
16 #include "quote.h"
17 #include "sparse-index.h"
18
19 static const char *empty_base = "";
20
21 static char const * const builtin_sparse_checkout_usage[] = {
22 N_("git sparse-checkout (init|list|set|add|reapply|disable) <options>"),
23 NULL
24 };
25
26 static void write_patterns_to_file(FILE *fp, struct pattern_list *pl)
27 {
28 int i;
29
30 for (i = 0; i < pl->nr; i++) {
31 struct path_pattern *p = pl->patterns[i];
32
33 if (p->flags & PATTERN_FLAG_NEGATIVE)
34 fprintf(fp, "!");
35
36 fprintf(fp, "%s", p->pattern);
37
38 if (p->flags & PATTERN_FLAG_MUSTBEDIR)
39 fprintf(fp, "/");
40
41 fprintf(fp, "\n");
42 }
43 }
44
45 static char const * const builtin_sparse_checkout_list_usage[] = {
46 N_("git sparse-checkout list"),
47 NULL
48 };
49
50 static int sparse_checkout_list(int argc, const char **argv)
51 {
52 static struct option builtin_sparse_checkout_list_options[] = {
53 OPT_END(),
54 };
55 struct pattern_list pl;
56 char *sparse_filename;
57 int res;
58
59 argc = parse_options(argc, argv, NULL,
60 builtin_sparse_checkout_list_options,
61 builtin_sparse_checkout_list_usage, 0);
62
63 memset(&pl, 0, sizeof(pl));
64
65 pl.use_cone_patterns = core_sparse_checkout_cone;
66
67 sparse_filename = get_sparse_checkout_filename();
68 res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
69 free(sparse_filename);
70
71 if (res < 0) {
72 warning(_("this worktree is not sparse (sparse-checkout file may not exist)"));
73 return 0;
74 }
75
76 if (pl.use_cone_patterns) {
77 int i;
78 struct pattern_entry *pe;
79 struct hashmap_iter iter;
80 struct string_list sl = STRING_LIST_INIT_DUP;
81
82 hashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {
83 /* pe->pattern starts with "/", skip it */
84 string_list_insert(&sl, pe->pattern + 1);
85 }
86
87 string_list_sort(&sl);
88
89 for (i = 0; i < sl.nr; i++) {
90 quote_c_style(sl.items[i].string, NULL, stdout, 0);
91 printf("\n");
92 }
93
94 return 0;
95 }
96
97 write_patterns_to_file(stdout, &pl);
98 clear_pattern_list(&pl);
99
100 return 0;
101 }
102
103 static void clean_tracked_sparse_directories(struct repository *r)
104 {
105 int i, was_full = 0;
106 struct strbuf path = STRBUF_INIT;
107 size_t pathlen;
108 struct string_list_item *item;
109 struct string_list sparse_dirs = STRING_LIST_INIT_DUP;
110
111 /*
112 * If we are not using cone mode patterns, then we cannot
113 * delete directories outside of the sparse cone.
114 */
115 if (!r || !r->index || !r->worktree)
116 return;
117 if (init_sparse_checkout_patterns(r->index) ||
118 !r->index->sparse_checkout_patterns->use_cone_patterns)
119 return;
120
121 /*
122 * Use the sparse index as a data structure to assist finding
123 * directories that are safe to delete. This conversion to a
124 * sparse index will not delete directories that contain
125 * conflicted entries or submodules.
126 */
127 if (!r->index->sparse_index) {
128 /*
129 * If something, such as a merge conflict or other concern,
130 * prevents us from converting to a sparse index, then do
131 * not try deleting files.
132 */
133 if (convert_to_sparse(r->index, SPARSE_INDEX_MEMORY_ONLY))
134 return;
135 was_full = 1;
136 }
137
138 strbuf_addstr(&path, r->worktree);
139 strbuf_complete(&path, '/');
140 pathlen = path.len;
141
142 /*
143 * Collect directories that have gone out of scope but also
144 * exist on disk, so there is some work to be done. We need to
145 * store the entries in a list before exploring, since that might
146 * expand the sparse-index again.
147 */
148 for (i = 0; i < r->index->cache_nr; i++) {
149 struct cache_entry *ce = r->index->cache[i];
150
151 if (S_ISSPARSEDIR(ce->ce_mode) &&
152 repo_file_exists(r, ce->name))
153 string_list_append(&sparse_dirs, ce->name);
154 }
155
156 for_each_string_list_item(item, &sparse_dirs) {
157 struct dir_struct dir = DIR_INIT;
158 struct pathspec p = { 0 };
159 struct strvec s = STRVEC_INIT;
160
161 strbuf_setlen(&path, pathlen);
162 strbuf_addstr(&path, item->string);
163
164 dir.flags |= DIR_SHOW_IGNORED_TOO;
165
166 setup_standard_excludes(&dir);
167 strvec_push(&s, path.buf);
168
169 parse_pathspec(&p, PATHSPEC_GLOB, 0, NULL, s.v);
170 fill_directory(&dir, r->index, &p);
171
172 if (dir.nr) {
173 warning(_("directory '%s' contains untracked files,"
174 " but is not in the sparse-checkout cone"),
175 item->string);
176 } else if (remove_dir_recursively(&path, 0)) {
177 /*
178 * Removal is "best effort". If something blocks
179 * the deletion, then continue with a warning.
180 */
181 warning(_("failed to remove directory '%s'"),
182 item->string);
183 }
184
185 dir_clear(&dir);
186 }
187
188 string_list_clear(&sparse_dirs, 0);
189 strbuf_release(&path);
190
191 if (was_full)
192 ensure_full_index(r->index);
193 }
194
195 static int update_working_directory(struct pattern_list *pl)
196 {
197 enum update_sparsity_result result;
198 struct unpack_trees_options o;
199 struct lock_file lock_file = LOCK_INIT;
200 struct repository *r = the_repository;
201
202 /* If no branch has been checked out, there are no updates to make. */
203 if (is_index_unborn(r->index))
204 return UPDATE_SPARSITY_SUCCESS;
205
206 r->index->sparse_checkout_patterns = pl;
207
208 memset(&o, 0, sizeof(o));
209 o.verbose_update = isatty(2);
210 o.update = 1;
211 o.head_idx = -1;
212 o.src_index = r->index;
213 o.dst_index = r->index;
214 o.skip_sparse_checkout = 0;
215 o.pl = pl;
216
217 setup_work_tree();
218
219 repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR);
220
221 setup_unpack_trees_porcelain(&o, "sparse-checkout");
222 result = update_sparsity(&o);
223 clear_unpack_trees_porcelain(&o);
224
225 if (result == UPDATE_SPARSITY_WARNINGS)
226 /*
227 * We don't do any special handling of warnings from untracked
228 * files in the way or dirty entries that can't be removed.
229 */
230 result = UPDATE_SPARSITY_SUCCESS;
231 if (result == UPDATE_SPARSITY_SUCCESS)
232 write_locked_index(r->index, &lock_file, COMMIT_LOCK);
233 else
234 rollback_lock_file(&lock_file);
235
236 clean_tracked_sparse_directories(r);
237
238 r->index->sparse_checkout_patterns = NULL;
239 return result;
240 }
241
242 static char *escaped_pattern(char *pattern)
243 {
244 char *p = pattern;
245 struct strbuf final = STRBUF_INIT;
246
247 while (*p) {
248 if (is_glob_special(*p))
249 strbuf_addch(&final, '\\');
250
251 strbuf_addch(&final, *p);
252 p++;
253 }
254
255 return strbuf_detach(&final, NULL);
256 }
257
258 static void write_cone_to_file(FILE *fp, struct pattern_list *pl)
259 {
260 int i;
261 struct pattern_entry *pe;
262 struct hashmap_iter iter;
263 struct string_list sl = STRING_LIST_INIT_DUP;
264 struct strbuf parent_pattern = STRBUF_INIT;
265
266 hashmap_for_each_entry(&pl->parent_hashmap, &iter, pe, ent) {
267 if (hashmap_get_entry(&pl->recursive_hashmap, pe, ent, NULL))
268 continue;
269
270 if (!hashmap_contains_parent(&pl->recursive_hashmap,
271 pe->pattern,
272 &parent_pattern))
273 string_list_insert(&sl, pe->pattern);
274 }
275
276 string_list_sort(&sl);
277 string_list_remove_duplicates(&sl, 0);
278
279 fprintf(fp, "/*\n!/*/\n");
280
281 for (i = 0; i < sl.nr; i++) {
282 char *pattern = escaped_pattern(sl.items[i].string);
283
284 if (strlen(pattern))
285 fprintf(fp, "%s/\n!%s/*/\n", pattern, pattern);
286 free(pattern);
287 }
288
289 string_list_clear(&sl, 0);
290
291 hashmap_for_each_entry(&pl->recursive_hashmap, &iter, pe, ent) {
292 if (!hashmap_contains_parent(&pl->recursive_hashmap,
293 pe->pattern,
294 &parent_pattern))
295 string_list_insert(&sl, pe->pattern);
296 }
297
298 strbuf_release(&parent_pattern);
299
300 string_list_sort(&sl);
301 string_list_remove_duplicates(&sl, 0);
302
303 for (i = 0; i < sl.nr; i++) {
304 char *pattern = escaped_pattern(sl.items[i].string);
305 fprintf(fp, "%s/\n", pattern);
306 free(pattern);
307 }
308 }
309
310 static int write_patterns_and_update(struct pattern_list *pl)
311 {
312 char *sparse_filename;
313 FILE *fp;
314 int fd;
315 struct lock_file lk = LOCK_INIT;
316 int result;
317
318 sparse_filename = get_sparse_checkout_filename();
319
320 if (safe_create_leading_directories(sparse_filename))
321 die(_("failed to create directory for sparse-checkout file"));
322
323 fd = hold_lock_file_for_update(&lk, sparse_filename,
324 LOCK_DIE_ON_ERROR);
325
326 result = update_working_directory(pl);
327 if (result) {
328 rollback_lock_file(&lk);
329 free(sparse_filename);
330 clear_pattern_list(pl);
331 update_working_directory(NULL);
332 return result;
333 }
334
335 fp = xfdopen(fd, "w");
336
337 if (core_sparse_checkout_cone)
338 write_cone_to_file(fp, pl);
339 else
340 write_patterns_to_file(fp, pl);
341
342 fflush(fp);
343 commit_lock_file(&lk);
344
345 free(sparse_filename);
346 clear_pattern_list(pl);
347
348 return 0;
349 }
350
351 enum sparse_checkout_mode {
352 MODE_NO_PATTERNS = 0,
353 MODE_ALL_PATTERNS = 1,
354 MODE_CONE_PATTERNS = 2,
355 };
356
357 static int set_config(enum sparse_checkout_mode mode)
358 {
359 const char *config_path;
360
361 if (upgrade_repository_format(1) < 0)
362 die(_("unable to upgrade repository format to enable worktreeConfig"));
363 if (git_config_set_gently("extensions.worktreeConfig", "true")) {
364 error(_("failed to set extensions.worktreeConfig setting"));
365 return 1;
366 }
367
368 config_path = git_path("config.worktree");
369 git_config_set_in_file_gently(config_path,
370 "core.sparseCheckout",
371 mode ? "true" : NULL);
372
373 git_config_set_in_file_gently(config_path,
374 "core.sparseCheckoutCone",
375 mode == MODE_CONE_PATTERNS ? "true" : NULL);
376
377 if (mode == MODE_NO_PATTERNS)
378 set_sparse_index_config(the_repository, 0);
379
380 return 0;
381 }
382
383 static char const * const builtin_sparse_checkout_init_usage[] = {
384 N_("git sparse-checkout init [--cone] [--[no-]sparse-index]"),
385 NULL
386 };
387
388 static struct sparse_checkout_init_opts {
389 int cone_mode;
390 int sparse_index;
391 } init_opts;
392
393 static int sparse_checkout_init(int argc, const char **argv)
394 {
395 struct pattern_list pl;
396 char *sparse_filename;
397 int res;
398 struct object_id oid;
399 int mode;
400 struct strbuf pattern = STRBUF_INIT;
401
402 static struct option builtin_sparse_checkout_init_options[] = {
403 OPT_BOOL(0, "cone", &init_opts.cone_mode,
404 N_("initialize the sparse-checkout in cone mode")),
405 OPT_BOOL(0, "sparse-index", &init_opts.sparse_index,
406 N_("toggle the use of a sparse index")),
407 OPT_END(),
408 };
409
410 repo_read_index(the_repository);
411
412 init_opts.sparse_index = -1;
413
414 argc = parse_options(argc, argv, NULL,
415 builtin_sparse_checkout_init_options,
416 builtin_sparse_checkout_init_usage, 0);
417
418 if (init_opts.cone_mode) {
419 mode = MODE_CONE_PATTERNS;
420 core_sparse_checkout_cone = 1;
421 } else
422 mode = MODE_ALL_PATTERNS;
423
424 if (set_config(mode))
425 return 1;
426
427 memset(&pl, 0, sizeof(pl));
428
429 sparse_filename = get_sparse_checkout_filename();
430 res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
431
432 if (init_opts.sparse_index >= 0) {
433 if (set_sparse_index_config(the_repository, init_opts.sparse_index) < 0)
434 die(_("failed to modify sparse-index config"));
435
436 /* force an index rewrite */
437 repo_read_index(the_repository);
438 the_repository->index->updated_workdir = 1;
439 }
440
441 core_apply_sparse_checkout = 1;
442
443 /* If we already have a sparse-checkout file, use it. */
444 if (res >= 0) {
445 free(sparse_filename);
446 return update_working_directory(NULL);
447 }
448
449 if (get_oid("HEAD", &oid)) {
450 FILE *fp;
451
452 /* assume we are in a fresh repo, but update the sparse-checkout file */
453 fp = xfopen(sparse_filename, "w");
454 if (!fp)
455 die(_("failed to open '%s'"), sparse_filename);
456
457 free(sparse_filename);
458 fprintf(fp, "/*\n!/*/\n");
459 fclose(fp);
460 return 0;
461 }
462
463 strbuf_addstr(&pattern, "/*");
464 add_pattern(strbuf_detach(&pattern, NULL), empty_base, 0, &pl, 0);
465 strbuf_addstr(&pattern, "!/*/");
466 add_pattern(strbuf_detach(&pattern, NULL), empty_base, 0, &pl, 0);
467 pl.use_cone_patterns = init_opts.cone_mode;
468
469 return write_patterns_and_update(&pl);
470 }
471
472 static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *path)
473 {
474 struct pattern_entry *e = xmalloc(sizeof(*e));
475 e->patternlen = path->len;
476 e->pattern = strbuf_detach(path, NULL);
477 hashmap_entry_init(&e->ent, fspathhash(e->pattern));
478
479 hashmap_add(&pl->recursive_hashmap, &e->ent);
480
481 while (e->patternlen) {
482 char *slash = strrchr(e->pattern, '/');
483 char *oldpattern = e->pattern;
484 size_t newlen;
485
486 if (slash == e->pattern)
487 break;
488
489 newlen = slash - e->pattern;
490 e = xmalloc(sizeof(struct pattern_entry));
491 e->patternlen = newlen;
492 e->pattern = xstrndup(oldpattern, newlen);
493 hashmap_entry_init(&e->ent, fspathhash(e->pattern));
494
495 if (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL))
496 hashmap_add(&pl->parent_hashmap, &e->ent);
497 }
498 }
499
500 static void strbuf_to_cone_pattern(struct strbuf *line, struct pattern_list *pl)
501 {
502 strbuf_trim(line);
503
504 strbuf_trim_trailing_dir_sep(line);
505
506 if (strbuf_normalize_path(line))
507 die(_("could not normalize path %s"), line->buf);
508
509 if (!line->len)
510 return;
511
512 if (line->buf[0] != '/')
513 strbuf_insertstr(line, 0, "/");
514
515 insert_recursive_pattern(pl, line);
516 }
517
518 static char const * const builtin_sparse_checkout_set_usage[] = {
519 N_("git sparse-checkout (set|add) (--stdin | <patterns>)"),
520 NULL
521 };
522
523 static struct sparse_checkout_set_opts {
524 int use_stdin;
525 } set_opts;
526
527 static void add_patterns_from_input(struct pattern_list *pl,
528 int argc, const char **argv)
529 {
530 int i;
531 if (core_sparse_checkout_cone) {
532 struct strbuf line = STRBUF_INIT;
533
534 hashmap_init(&pl->recursive_hashmap, pl_hashmap_cmp, NULL, 0);
535 hashmap_init(&pl->parent_hashmap, pl_hashmap_cmp, NULL, 0);
536 pl->use_cone_patterns = 1;
537
538 if (set_opts.use_stdin) {
539 struct strbuf unquoted = STRBUF_INIT;
540 while (!strbuf_getline(&line, stdin)) {
541 if (line.buf[0] == '"') {
542 strbuf_reset(&unquoted);
543 if (unquote_c_style(&unquoted, line.buf, NULL))
544 die(_("unable to unquote C-style string '%s'"),
545 line.buf);
546
547 strbuf_swap(&unquoted, &line);
548 }
549
550 strbuf_to_cone_pattern(&line, pl);
551 }
552
553 strbuf_release(&unquoted);
554 } else {
555 for (i = 0; i < argc; i++) {
556 strbuf_setlen(&line, 0);
557 strbuf_addstr(&line, argv[i]);
558 strbuf_to_cone_pattern(&line, pl);
559 }
560 }
561 } else {
562 if (set_opts.use_stdin) {
563 struct strbuf line = STRBUF_INIT;
564
565 while (!strbuf_getline(&line, stdin)) {
566 size_t len;
567 char *buf = strbuf_detach(&line, &len);
568 add_pattern(buf, empty_base, 0, pl, 0);
569 }
570 } else {
571 for (i = 0; i < argc; i++)
572 add_pattern(argv[i], empty_base, 0, pl, 0);
573 }
574 }
575 }
576
577 enum modify_type {
578 REPLACE,
579 ADD,
580 };
581
582 static void add_patterns_cone_mode(int argc, const char **argv,
583 struct pattern_list *pl)
584 {
585 struct strbuf buffer = STRBUF_INIT;
586 struct pattern_entry *pe;
587 struct hashmap_iter iter;
588 struct pattern_list existing;
589 char *sparse_filename = get_sparse_checkout_filename();
590
591 add_patterns_from_input(pl, argc, argv);
592
593 memset(&existing, 0, sizeof(existing));
594 existing.use_cone_patterns = core_sparse_checkout_cone;
595
596 if (add_patterns_from_file_to_list(sparse_filename, "", 0,
597 &existing, NULL, 0))
598 die(_("unable to load existing sparse-checkout patterns"));
599 free(sparse_filename);
600
601 hashmap_for_each_entry(&existing.recursive_hashmap, &iter, pe, ent) {
602 if (!hashmap_contains_parent(&pl->recursive_hashmap,
603 pe->pattern, &buffer) ||
604 !hashmap_contains_parent(&pl->parent_hashmap,
605 pe->pattern, &buffer)) {
606 strbuf_reset(&buffer);
607 strbuf_addstr(&buffer, pe->pattern);
608 insert_recursive_pattern(pl, &buffer);
609 }
610 }
611
612 clear_pattern_list(&existing);
613 strbuf_release(&buffer);
614 }
615
616 static void add_patterns_literal(int argc, const char **argv,
617 struct pattern_list *pl)
618 {
619 char *sparse_filename = get_sparse_checkout_filename();
620 if (add_patterns_from_file_to_list(sparse_filename, "", 0,
621 pl, NULL, 0))
622 die(_("unable to load existing sparse-checkout patterns"));
623 free(sparse_filename);
624 add_patterns_from_input(pl, argc, argv);
625 }
626
627 static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
628 {
629 int result;
630 int changed_config = 0;
631 struct pattern_list *pl = xcalloc(1, sizeof(*pl));
632
633 switch (m) {
634 case ADD:
635 if (core_sparse_checkout_cone)
636 add_patterns_cone_mode(argc, argv, pl);
637 else
638 add_patterns_literal(argc, argv, pl);
639 break;
640
641 case REPLACE:
642 add_patterns_from_input(pl, argc, argv);
643 break;
644 }
645
646 if (!core_apply_sparse_checkout) {
647 set_config(MODE_ALL_PATTERNS);
648 core_apply_sparse_checkout = 1;
649 changed_config = 1;
650 }
651
652 result = write_patterns_and_update(pl);
653
654 if (result && changed_config)
655 set_config(MODE_NO_PATTERNS);
656
657 clear_pattern_list(pl);
658 free(pl);
659 return result;
660 }
661
662 static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
663 enum modify_type m)
664 {
665 static struct option builtin_sparse_checkout_set_options[] = {
666 OPT_BOOL(0, "stdin", &set_opts.use_stdin,
667 N_("read patterns from standard in")),
668 OPT_END(),
669 };
670
671 repo_read_index(the_repository);
672
673 argc = parse_options(argc, argv, prefix,
674 builtin_sparse_checkout_set_options,
675 builtin_sparse_checkout_set_usage,
676 PARSE_OPT_KEEP_UNKNOWN);
677
678 return modify_pattern_list(argc, argv, m);
679 }
680
681 static char const * const builtin_sparse_checkout_reapply_usage[] = {
682 N_("git sparse-checkout reapply"),
683 NULL
684 };
685
686 static int sparse_checkout_reapply(int argc, const char **argv)
687 {
688 static struct option builtin_sparse_checkout_reapply_options[] = {
689 OPT_END(),
690 };
691
692 argc = parse_options(argc, argv, NULL,
693 builtin_sparse_checkout_reapply_options,
694 builtin_sparse_checkout_reapply_usage, 0);
695
696 repo_read_index(the_repository);
697 return update_working_directory(NULL);
698 }
699
700 static char const * const builtin_sparse_checkout_disable_usage[] = {
701 N_("git sparse-checkout disable"),
702 NULL
703 };
704
705 static int sparse_checkout_disable(int argc, const char **argv)
706 {
707 static struct option builtin_sparse_checkout_disable_options[] = {
708 OPT_END(),
709 };
710 struct pattern_list pl;
711 struct strbuf match_all = STRBUF_INIT;
712
713 argc = parse_options(argc, argv, NULL,
714 builtin_sparse_checkout_disable_options,
715 builtin_sparse_checkout_disable_usage, 0);
716
717 repo_read_index(the_repository);
718
719 memset(&pl, 0, sizeof(pl));
720 hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
721 hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
722 pl.use_cone_patterns = 0;
723 core_apply_sparse_checkout = 1;
724
725 strbuf_addstr(&match_all, "/*");
726 add_pattern(strbuf_detach(&match_all, NULL), empty_base, 0, &pl, 0);
727
728 prepare_repo_settings(the_repository);
729 the_repository->settings.sparse_index = 0;
730
731 if (update_working_directory(&pl))
732 die(_("error while refreshing working directory"));
733
734 clear_pattern_list(&pl);
735 return set_config(MODE_NO_PATTERNS);
736 }
737
738 int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
739 {
740 static struct option builtin_sparse_checkout_options[] = {
741 OPT_END(),
742 };
743
744 if (argc == 2 && !strcmp(argv[1], "-h"))
745 usage_with_options(builtin_sparse_checkout_usage,
746 builtin_sparse_checkout_options);
747
748 argc = parse_options(argc, argv, prefix,
749 builtin_sparse_checkout_options,
750 builtin_sparse_checkout_usage,
751 PARSE_OPT_STOP_AT_NON_OPTION);
752
753 git_config(git_default_config, NULL);
754
755 if (argc > 0) {
756 if (!strcmp(argv[0], "list"))
757 return sparse_checkout_list(argc, argv);
758 if (!strcmp(argv[0], "init"))
759 return sparse_checkout_init(argc, argv);
760 if (!strcmp(argv[0], "set"))
761 return sparse_checkout_set(argc, argv, prefix, REPLACE);
762 if (!strcmp(argv[0], "add"))
763 return sparse_checkout_set(argc, argv, prefix, ADD);
764 if (!strcmp(argv[0], "reapply"))
765 return sparse_checkout_reapply(argc, argv);
766 if (!strcmp(argv[0], "disable"))
767 return sparse_checkout_disable(argc, argv);
768 }
769
770 usage_with_options(builtin_sparse_checkout_usage,
771 builtin_sparse_checkout_options);
772 }