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

Function run_builtin

git.c:466–527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

464}
465
466static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
467{
468 int status, help;
469 int no_repo = 1;
470 struct stat st;
471 const char *prefix;
472 int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY));
473
474 help = argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help-all"));
475 if (help && (run_setup & RUN_SETUP))
476 /* demote to GENTLY to allow 'git cmd -h' outside repo */
477 run_setup = RUN_SETUP_GENTLY;
478
479 if (run_setup & RUN_SETUP) {
480 prefix = setup_git_directory(the_repository);
481 no_repo = 0;
482 } else if (run_setup & RUN_SETUP_GENTLY) {
483 prefix = setup_git_directory_gently(the_repository, &no_repo);
484 } else {
485 prefix = NULL;
486 }
487 assert(!prefix || *prefix);
488 precompose_argv_prefix(argc, argv, NULL);
489 if (use_pager == -1 && run_setup &&
490 !(p->option & DELAY_PAGER_CONFIG))
491 use_pager = check_pager_config(repo, p->cmd);
492 if (use_pager == -1 && p->option & USE_PAGER)
493 use_pager = 1;
494 if (run_setup && startup_info->have_repository)
495 /* get_git_dir() may set up repo, avoid that */
496 trace_repo_setup(repo);
497 commit_pager_choice();
498
499 if (!help && p->option & NEED_WORK_TREE)
500 setup_work_tree(the_repository);
501
502 trace_argv_printf(argv, "trace: built-in: git");
503 trace2_cmd_name(p->cmd);
504
505 validate_cache_entries(repo->index);
506 status = p->fn(argc, argv, prefix, no_repo ? NULL : repo);
507 validate_cache_entries(repo->index);
508
509 if (status)
510 return status;
511
512 /* Somebody closed stdout? */
513 if (fstat(fileno(stdout), &st))
514 return 0;
515 /* Ignore write errors for pipes and sockets.. */
516 if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode))
517 return 0;
518
519 /* Check for ENOSPC and EIO errors.. */
520 if (fflush(stdout))
521 die_errno(_("write failure on standard output"));
522 if (ferror(stdout))
523 die(_("unknown write failure on standard output"));

Callers 1

handle_builtinFunction · 0.85

Calls 10

setup_git_directoryFunction · 0.85
check_pager_configFunction · 0.85
trace_repo_setupFunction · 0.85
commit_pager_choiceFunction · 0.85
setup_work_treeFunction · 0.85
validate_cache_entriesFunction · 0.85
die_errnoFunction · 0.85
precompose_argv_prefixFunction · 0.70
dieFunction · 0.70

Tested by

no test coverage detected