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

Function git_header_name

apply.c:1185–1328  ·  view source on GitHub ↗

* This is to extract the same name that appears on "diff --git" * line. We do not find and return anything if it is a rename * patch, and it is OK because we will find the name elsewhere. * We need to reliably find name only when it is mode-change only, * creation or deletion of an empty file. In any of these cases, * both sides are the same name under a/ and b/ respectively. */

Source from the content-addressed store, hash-verified

1183 * both sides are the same name under a/ and b/ respectively.
1184 */
1185static char *git_header_name(int p_value,
1186 const char *line,
1187 int llen)
1188{
1189 const char *name;
1190 const char *second = NULL;
1191 size_t len, line_len;
1192
1193 line += strlen("diff --git ");
1194 llen -= strlen("diff --git ");
1195
1196 if (*line == '"') {
1197 const char *cp;
1198 struct strbuf first = STRBUF_INIT;
1199 struct strbuf sp = STRBUF_INIT;
1200
1201 if (unquote_c_style(&first, line, &second))
1202 goto free_and_fail1;
1203
1204 /* strip the a/b prefix including trailing slash */
1205 cp = skip_tree_prefix(p_value, first.buf, first.len);
1206 if (!cp)
1207 goto free_and_fail1;
1208 strbuf_remove(&first, 0, cp - first.buf);
1209
1210 /*
1211 * second points at one past closing dq of name.
1212 * find the second name.
1213 */
1214 while ((second < line + llen) && isspace(*second))
1215 second++;
1216
1217 if (line + llen <= second)
1218 goto free_and_fail1;
1219 if (*second == '"') {
1220 if (unquote_c_style(&sp, second, NULL))
1221 goto free_and_fail1;
1222 cp = skip_tree_prefix(p_value, sp.buf, sp.len);
1223 if (!cp)
1224 goto free_and_fail1;
1225 /* They must match, otherwise ignore */
1226 if (strcmp(cp, first.buf))
1227 goto free_and_fail1;
1228 strbuf_release(&sp);
1229 return strbuf_detach(&first, NULL);
1230 }
1231
1232 /* unquoted second */
1233 cp = skip_tree_prefix(p_value, second, line + llen - second);
1234 if (!cp)
1235 goto free_and_fail1;
1236 if (line + llen - cp != first.len ||
1237 memcmp(first.buf, cp, first.len))
1238 goto free_and_fail1;
1239 return strbuf_detach(&first, NULL);
1240
1241 free_and_fail1:
1242 strbuf_release(&first);

Callers 1

parse_git_diff_headerFunction · 0.85

Calls 6

unquote_c_styleFunction · 0.85
skip_tree_prefixFunction · 0.85
strbuf_removeFunction · 0.85
strbuf_releaseFunction · 0.85
strbuf_detachFunction · 0.85
xmemdupzFunction · 0.85

Tested by

no test coverage detected