MCPcopy Index your code
hub / github.com/git/git / run_add_p

Function run_add_p

add-patch.c:2040–2101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2038}
2039
2040int run_add_p(struct repository *r, enum add_p_mode mode,
2041 struct interactive_options *opts, const char *revision,
2042 const struct pathspec *ps,
2043 unsigned flags)
2044{
2045 struct add_p_state s = {
2046 .r = r,
2047 .index = r->index,
2048 .index_file = r->index_file,
2049 .answer = STRBUF_INIT,
2050 .buf = STRBUF_INIT,
2051 .plain = STRBUF_INIT,
2052 .colored = STRBUF_INIT,
2053 };
2054 int ret;
2055
2056 interactive_config_init(&s.cfg, r, opts);
2057
2058 if (mode == ADD_P_STASH)
2059 s.mode = &patch_mode_stash;
2060 else if (mode == ADD_P_RESET) {
2061 if (!revision || !strcmp(revision, "HEAD"))
2062 s.mode = &patch_mode_reset_head;
2063 else
2064 s.mode = &patch_mode_reset_nothead;
2065 } else if (mode == ADD_P_CHECKOUT) {
2066 if (!revision)
2067 s.mode = &patch_mode_checkout_index;
2068 else if (!strcmp(revision, "HEAD"))
2069 s.mode = &patch_mode_checkout_head;
2070 else
2071 s.mode = &patch_mode_checkout_nothead;
2072 } else if (mode == ADD_P_WORKTREE) {
2073 if (!revision)
2074 s.mode = &patch_mode_checkout_index;
2075 else if (!strcmp(revision, "HEAD"))
2076 s.mode = &patch_mode_worktree_head;
2077 else
2078 s.mode = &patch_mode_worktree_nothead;
2079 } else
2080 s.mode = &patch_mode_add;
2081 s.revision = revision;
2082
2083 discard_index(r->index);
2084 if (repo_read_index(r) < 0 ||
2085 (!s.mode->index_only &&
2086 repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
2087 NULL, NULL, NULL) < 0)) {
2088 ret = -1;
2089 goto out;
2090 }
2091
2092 ret = run_add_p_common(&s, ps, flags);
2093 if (ret < 0)
2094 goto out;
2095
2096 ret = 0;
2097

Callers 5

run_patchFunction · 0.85
stash_patchFunction · 0.85
cmd_resetFunction · 0.85
interactive_addFunction · 0.85
checkout_pathsFunction · 0.85

Calls 6

interactive_config_initFunction · 0.85
discard_indexFunction · 0.85
repo_read_indexFunction · 0.85
run_add_p_commonFunction · 0.85
add_p_state_clearFunction · 0.85

Tested by

no test coverage detected