| 1340 | } |
| 1341 | |
| 1342 | int parse_git_diff_header(struct strbuf *root, |
| 1343 | const char *patch_input_file, |
| 1344 | int *linenr, |
| 1345 | int p_value, |
| 1346 | const char *line, |
| 1347 | int len, |
| 1348 | unsigned int size, |
| 1349 | struct patch *patch) |
| 1350 | { |
| 1351 | unsigned long offset; |
| 1352 | struct gitdiff_data parse_hdr_state; |
| 1353 | |
| 1354 | /* A git diff has explicit new/delete information, so we don't guess */ |
| 1355 | patch->is_new = 0; |
| 1356 | patch->is_delete = 0; |
| 1357 | |
| 1358 | /* |
| 1359 | * Some things may not have the old name in the |
| 1360 | * rest of the headers anywhere (pure mode changes, |
| 1361 | * or removing or adding empty files), so we get |
| 1362 | * the default name from the header. |
| 1363 | */ |
| 1364 | patch->def_name = git_header_name(p_value, line, len); |
| 1365 | if (patch->def_name && root->len) { |
| 1366 | char *s = xstrfmt("%s%s", root->buf, patch->def_name); |
| 1367 | free(patch->def_name); |
| 1368 | patch->def_name = s; |
| 1369 | } |
| 1370 | |
| 1371 | line += len; |
| 1372 | size -= len; |
| 1373 | (*linenr)++; |
| 1374 | parse_hdr_state.root = root; |
| 1375 | parse_hdr_state.patch_input_file = patch_input_file; |
| 1376 | parse_hdr_state.linenr = *linenr; |
| 1377 | parse_hdr_state.p_value = p_value; |
| 1378 | |
| 1379 | for (offset = len ; size > 0 ; offset += len, size -= len, line += len, (*linenr)++) { |
| 1380 | static const struct opentry { |
| 1381 | const char *str; |
| 1382 | int (*fn)(struct gitdiff_data *, const char *, struct patch *); |
| 1383 | } optable[] = { |
| 1384 | { "@@ -", gitdiff_hdrend }, |
| 1385 | { "--- ", gitdiff_oldname }, |
| 1386 | { "+++ ", gitdiff_newname }, |
| 1387 | { "old mode ", gitdiff_oldmode }, |
| 1388 | { "new mode ", gitdiff_newmode }, |
| 1389 | { "deleted file mode ", gitdiff_delete }, |
| 1390 | { "new file mode ", gitdiff_newfile }, |
| 1391 | { "copy from ", gitdiff_copysrc }, |
| 1392 | { "copy to ", gitdiff_copydst }, |
| 1393 | { "rename old ", gitdiff_renamesrc }, |
| 1394 | { "rename new ", gitdiff_renamedst }, |
| 1395 | { "rename from ", gitdiff_renamesrc }, |
| 1396 | { "rename to ", gitdiff_renamedst }, |
| 1397 | { "similarity index ", gitdiff_similarity }, |
| 1398 | { "dissimilarity index ", gitdiff_dissimilarity }, |
| 1399 | { "index ", gitdiff_index }, |
no test coverage detected