| 2101 | } |
| 2102 | |
| 2103 | int run_add_p_index(struct repository *r, |
| 2104 | struct index_state *index, |
| 2105 | const char *index_file, |
| 2106 | struct interactive_options *opts, |
| 2107 | const char *revision, |
| 2108 | const struct pathspec *ps, |
| 2109 | unsigned flags) |
| 2110 | { |
| 2111 | struct patch_mode mode = { |
| 2112 | .apply_args = { "--cached", NULL }, |
| 2113 | .apply_check_args = { "--cached", NULL }, |
| 2114 | .prompt_mode = { |
| 2115 | N_("Stage mode change [y,n,q,a,d%s,?]? "), |
| 2116 | N_("Stage deletion [y,n,q,a,d%s,?]? "), |
| 2117 | N_("Stage addition [y,n,q,a,d%s,?]? "), |
| 2118 | N_("Stage this hunk [y,n,q,a,d%s,?]? ") |
| 2119 | }, |
| 2120 | .edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk " |
| 2121 | "will immediately be marked for staging."), |
| 2122 | .help_patch_text = |
| 2123 | N_("y - stage this hunk\n" |
| 2124 | "n - do not stage this hunk\n" |
| 2125 | "q - quit; do not stage this hunk or any of the remaining " |
| 2126 | "ones\n" |
| 2127 | "a - stage this hunk and all later hunks in the file\n" |
| 2128 | "d - do not stage this hunk or any of the later hunks in " |
| 2129 | "the file\n"), |
| 2130 | .index_only = 1, |
| 2131 | }; |
| 2132 | struct add_p_state s = { |
| 2133 | .r = r, |
| 2134 | .index = index, |
| 2135 | .index_file = index_file, |
| 2136 | .answer = STRBUF_INIT, |
| 2137 | .buf = STRBUF_INIT, |
| 2138 | .plain = STRBUF_INIT, |
| 2139 | .colored = STRBUF_INIT, |
| 2140 | .mode = &mode, |
| 2141 | .revision = revision, |
| 2142 | }; |
| 2143 | char parent_tree_oid[GIT_MAX_HEXSZ + 1]; |
| 2144 | struct commit *commit; |
| 2145 | int ret; |
| 2146 | |
| 2147 | interactive_config_init(&s.cfg, r, opts); |
| 2148 | |
| 2149 | commit = lookup_commit_reference_by_name(revision); |
| 2150 | if (!commit) { |
| 2151 | err(&s, _("Revision does not refer to a commit")); |
| 2152 | ret = -1; |
| 2153 | goto out; |
| 2154 | } |
| 2155 | |
| 2156 | if (commit->parents) |
| 2157 | oid_to_hex_r(parent_tree_oid, get_commit_tree_oid(commit->parents->item)); |
| 2158 | else |
| 2159 | oid_to_hex_r(parent_tree_oid, r->hash_algo->empty_tree); |
| 2160 |
no test coverage detected