MCPcopy Create free account
hub / github.com/git/git / sparse_checkout_init

Function sparse_checkout_init

builtin/sparse-checkout.c:456–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454} init_opts;
455
456static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
457 struct repository *repo)
458{
459 struct pattern_list pl;
460 char *sparse_filename;
461 int res;
462 struct object_id oid;
463
464 static struct option builtin_sparse_checkout_init_options[] = {
465 OPT_BOOL(0, "cone", &init_opts.cone_mode,
466 N_("initialize the sparse-checkout in cone mode")),
467 OPT_BOOL(0, "sparse-index", &init_opts.sparse_index,
468 N_("toggle the use of a sparse index")),
469 OPT_END(),
470 };
471
472 setup_work_tree(the_repository);
473 repo_read_index(repo);
474
475 init_opts.cone_mode = -1;
476 init_opts.sparse_index = -1;
477
478 argc = parse_options(argc, argv, prefix,
479 builtin_sparse_checkout_init_options,
480 builtin_sparse_checkout_init_usage, 0);
481
482 if (update_modes(repo, &init_opts.cone_mode, &init_opts.sparse_index))
483 return 1;
484
485 memset(&pl, 0, sizeof(pl));
486
487 sparse_filename = get_sparse_checkout_filename();
488 res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
489
490 /* If we already have a sparse-checkout file, use it. */
491 if (res >= 0) {
492 free(sparse_filename);
493 clear_pattern_list(&pl);
494 return update_working_directory(repo, NULL);
495 }
496
497 if (repo_get_oid(repo, "HEAD", &oid)) {
498 FILE *fp;
499
500 /* assume we are in a fresh repo, but update the sparse-checkout file */
501 if (safe_create_leading_directories(repo, sparse_filename))
502 die(_("unable to create leading directories of %s"),
503 sparse_filename);
504 fp = xfopen(sparse_filename, "w");
505 if (!fp)
506 die(_("failed to open '%s'"), sparse_filename);
507
508 free(sparse_filename);
509 fprintf(fp, "/*\n!/*/\n");
510 fclose(fp);
511 return 0;
512 }
513

Callers

nothing calls this directly

Calls 14

setup_work_treeFunction · 0.85
repo_read_indexFunction · 0.85
parse_optionsFunction · 0.85
update_modesFunction · 0.85
clear_pattern_listFunction · 0.85
update_working_directoryFunction · 0.85
repo_get_oidFunction · 0.85
xfopenFunction · 0.85
add_patternFunction · 0.85

Tested by

no test coverage detected