{"thread":{"id":"52478","subject":"Git Test Coverage Report (Dec. 18)","startedAt":"2019-12-18T10:36:27Z","lastAt":"2019-12-18T10:36:27Z","messageCount":1,"participants":["Derrick Stolee"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"388419","messageId":"10fc3a91-5a34-7e47-1b4a-3460f8f9c1a6@gmail.com","threadId":"52478","inReplyTo":null,"subject":"Git Test Coverage Report (Dec. 18)","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-12-18T10:36:18Z","receivedAt":"2019-12-18T10:36:27Z","isPatch":false,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"Here is today's test-coverage report.\n\nThanks,\n-Stolee\n\n[1] https://derrickstolee.github.io/git-test-coverage/reports/2019-12-18-commits.txt\n[2] https://derrickstolee.github.io/git-test-coverage/reports/2019-12-18.txt\n[2] https://derrickstolee.github.io/git-test-coverage/reports/2019-12-18.htm\n\n---\n\npu\tbca46e3060e7375827de0056eab64cad9e556b76\njch\t0c7f8a73bddc98b1aeac27d2e8bf3e3109eab9b4\nnext\t64cd5c46229f533beb7b49a8dfd1c5104da25b00\nmaster\tb02fd2accad4d48078671adf38fe5b5976d77304\nmaster@{1}\t083378cc35c4dbcc607e4cdd24a5fca440163d17\n\n\nUncovered code in 'pu' not in 'jch'\n--------------------------------------------------------\n\nCommits introducing uncovered code:\nJohannes Schindelin\t25ea47af built-in add -p: adjust hunk headers as needed\nadd-interactive.c\n25ea47af 29) void init_add_i_state(struct add_i_state *s, struct repository *r)\n25ea47af 47) init_color(r, s, \"fraginfo\", s->fraginfo_color,\n\nadd-patch.c\n25ea47af 282)  INDEX_ENVIRONMENT \"=%s\", s->s.r->index_file);\n25ea47af 283) }\n25ea47af 285) static int parse_range(const char **p,\n25ea47af 290) *offset = strtoul(*p, &pend, 10);\n25ea47af 291) if (pend == *p)\n25ea47af 292) return -1;\n25ea47af 293) if (*pend != ',') {\n25ea47af 294) *count = 1;\n25ea47af 295) *p = pend;\n25ea47af 296) return 0;\n25ea47af 298) *count = strtoul(pend + 1, (char **)p, 10);\n25ea47af 299) return *p == pend + 1 ? -1 : 0;\n25ea47af 302) static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk)\n25ea47af 304) struct hunk_header *header = &hunk->header;\n25ea47af 305) const char *line = s->plain.buf + hunk->start, *p = line;\n25ea47af 306) char *eol = memchr(p, '\\n', s->plain.len - hunk->start);\n25ea47af 308) if (!eol)\n25ea47af 309) eol = s->plain.buf + s->plain.len;\n25ea47af 311) if (!skip_prefix(p, \"@@ -\", &p) ||\n25ea47af 312)     parse_range(&p, &header->old_offset, &header->old_count) < 0 ||\n25ea47af 313)     !skip_prefix(p, \" +\", &p) ||\n25ea47af 314)     parse_range(&p, &header->new_offset, &header->new_count) < 0 ||\n25ea47af 315)     !skip_prefix(p, \" @@\", &p))\n25ea47af 319) hunk->start = eol - s->plain.buf + (*eol == '\\n');\n25ea47af 320) header->extra_start = p - s->plain.buf;\n25ea47af 321) header->extra_end = hunk->start;\n25ea47af 323) if (!s->colored.len) {\n25ea47af 324) header->colored_extra_start = header->colored_extra_end = 0;\n25ea47af 325) return 0;\n25ea47af 329) line = s->colored.buf + hunk->colored_start;\n25ea47af 330) eol = memchr(line, '\\n', s->colored.len - hunk->colored_start);\n25ea47af 331) if (!eol)\n25ea47af 332) eol = s->colored.buf + s->colored.len;\n25ea47af 333) p = memmem(line, eol - line, \"@@ -\", 4);\n25ea47af 334) if (!p)\n25ea47af 337) p = memmem(p + 4, eol - p - 4, \" @@\", 3);\n25ea47af 338) if (!p)\n25ea47af 341) hunk->colored_start = eol - s->colored.buf + (*eol == '\\n');\n25ea47af 342) header->colored_extra_start = p + 3 - s->colored.buf;\n25ea47af 343) header->colored_extra_end = hunk->colored_start;\n25ea47af 345) return 0;\n25ea47af 464) return -1;\n25ea47af 577) struct hunk_header *header = &hunk->header;\n25ea47af 579) if (hunk->header.old_offset != 0 || hunk->header.new_offset != 0) {\n25ea47af 586) unsigned long old_offset = header->old_offset;\n25ea47af 587) unsigned long new_offset = header->new_offset;\n25ea47af 589) if (!colored) {\n25ea47af 590) p = s->plain.buf + header->extra_start;\n25ea47af 591) len = header->extra_end - header->extra_start;\n25ea47af 593) strbuf_addstr(out, s->s.fraginfo_color);\n25ea47af 594) p = s->colored.buf + header->colored_extra_start;\n25ea47af 595) len = header->colored_extra_end\n25ea47af 596) - header->colored_extra_start;\n25ea47af 604) strbuf_addf(out, \"@@ -%lu,%lu +%lu,%lu @@\",\n25ea47af 607) if (len)\n25ea47af 608) strbuf_add(out, p, len);\n25ea47af 609) else if (colored)\n25ea47af 610) strbuf_addf(out, \"%s\\n\", GIT_COLOR_RESET);\n25ea47af 612) strbuf_addch(out, '\\n');\n25ea47af 790) ssize_t delta = 0;\n25ea47af 799) delta += hunk->header.old_count\n25ea47af 800) - hunk->header.new_count;\n25ea47af 806) render_hunk(s, hunk, delta, 0, out);\n25ea47af 1329) render_hunk(s, hunk, 0, colored, &s->buf);\n25ea47af 1552) discard_index(s->s.r->index);\n25ea47af 1563) if (!repo_read_index(s->s.r))\n25ea47af 1564) repo_refresh_and_write_index(s->s.r, REFRESH_QUIET, 0,\n25ea47af 1575) struct add_p_state s = {\n25ea47af 1580) init_add_i_state(&s.s, r);\n\nJohannes Schindelin\tc1f1a9b0 built-in stash: use the built-in `git add -p` if so configured\nbuiltin/stash.c\nc1f1a9b0 1026) setenv(INDEX_ENVIRONMENT, old_index_env, 1);\n\nJohannes Schindelin\t09032028 legacy stash -p: respect the add.interactive.usebuiltin setting\nbuiltin/add.c\n09032028 450) parse_pathspec(&pathspec, 0,\n09032028 456) return run_add_interactive(NULL, \"--patch=stash\", &pathspec);\n\nJohannes Schindelin\t1c6d07b9 built-in add -p: implement the \"worktree\" patch modes\nadd-patch.c\n1c6d07b9 1596) } else if (mode == ADD_P_WORKTREE) {\n1c6d07b9 1597) if (!revision)\n1c6d07b9 1598) s.mode = &patch_mode_checkout_index;\n1c6d07b9 1599) else if (!strcmp(revision, \"HEAD\"))\n1c6d07b9 1600) s.mode = &patch_mode_worktree_head;\n1c6d07b9 1602) s.mode = &patch_mode_worktree_nothead;\n\nbuiltin/add.c\n1c6d07b9 213) else if (!strcmp(patch_mode, \"--patch=worktree\"))\n1c6d07b9 214) mode = ADD_P_WORKTREE;\n\nJohannes Schindelin\t169205be built-in add -p: implement the \"stash\" and \"reset\" patch modes\nadd-patch.c\n169205be 1582) if (mode == ADD_P_STASH)\n169205be 1583) s.mode = &patch_mode_stash;\n169205be 1584) else if (mode == ADD_P_RESET) {\n169205be 1585) if (!revision || !strcmp(revision, \"HEAD\"))\n169205be 1586) s.mode = &patch_mode_reset_head;\n169205be 1588) s.mode = &patch_mode_reset_nothead;\n169205be 1604) s.mode = &patch_mode_stage;\n169205be 1608)     (!s.mode->index_only &&\n169205be 1609)      repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,\n169205be 1610)   NULL, NULL, NULL) < 0) ||\n\nbuiltin/add.c\n169205be 207) else if (!strcmp(patch_mode, \"--patch=stash\"))\n169205be 208) mode = ADD_P_STASH;\n169205be 209) else if (!strcmp(patch_mode, \"--patch=reset\"))\n169205be 210) mode = ADD_P_RESET;\n\nJohannes Schindelin\t54d9d9b2 built-in add -p: only show the applicable parts of the help text\nadd-patch.c\n54d9d9b2 1516) const char *p = _(help_patch_remainder), *eol = p;\n54d9d9b2 1518) color_fprintf(stdout, s->s.help_color, \"%s\",\n54d9d9b2 1525) for (; *p; p = eol + (*eol == '\\n')) {\n54d9d9b2 1526) eol = strchrnul(p, '\\n');\n54d9d9b2 1533) if (*p != '?' && !strchr(s->buf.buf, *p))\n54d9d9b2 1534) continue;\n54d9d9b2 1536) color_fprintf_ln(stdout, s->s.help_color,\n54d9d9b2 1537)  \"%.*s\", (int)(eol - p), p);\n\nJohannes Schindelin\t12c24cf8 built-in add -p: color the prompt and the help text\nadd-patch.c\n12c24cf8 1356) color_fprintf(stdout, s->s.prompt_color,\n12c24cf8 1360) color_fprintf(stdout, s->s.prompt_color,\n\nJohannes Schindelin\t0ecd9d27 built-in add -p: show different prompts for mode changes and deletions\nadd-patch.c\n0ecd9d27 1349) if (file_diff->deleted)\n0ecd9d27 1350) prompt_mode_type = PROMPT_DELETION;\n0ecd9d27 1351) else if (file_diff->mode_change && !hunk_index)\n0ecd9d27 1352) prompt_mode_type = PROMPT_MODE_CHANGE;\n0ecd9d27 1354) prompt_mode_type = PROMPT_HUNK;\n\nJohannes Schindelin\td6cf8733 built-in add -p: implement the '/' (\"search regex\") command\nadd-patch.c\nd6cf8733 1342) strbuf_addstr(&s->buf, \",g,/\");\nd6cf8733 1452) } else if (s->answer.buf[0] == '/') {\nd6cf8733 1456) if (file_diff->hunk_nr < 2) {\nd6cf8733 1457) err(s, _(\"No other hunks to search\"));\nd6cf8733 1458) continue;\nd6cf8733 1460) strbuf_remove(&s->answer, 0, 1);\nd6cf8733 1461) strbuf_trim_trailing_newline(&s->answer);\nd6cf8733 1462) if (s->answer.len == 0) {\nd6cf8733 1463) printf(\"%s\", _(\"search for regex? \"));\nd6cf8733 1464) fflush(stdout);\nd6cf8733 1465) if (strbuf_getline(&s->answer,\nd6cf8733 1467) break;\nd6cf8733 1468) strbuf_trim_trailing_newline(&s->answer);\nd6cf8733 1469) if (s->answer.len == 0)\nd6cf8733 1470) continue;\nd6cf8733 1472) ret = regcomp(&regex, s->answer.buf,\nd6cf8733 1474) if (ret) {\nd6cf8733 1478) err(s, _(\"Malformed search regexp %s: %s\"),\nd6cf8733 1480) continue;\nd6cf8733 1482) i = hunk_index;\nd6cf8733 1485) render_hunk(s, file_diff->hunk + i, 0, 0,\nd6cf8733 1487) if (regexec(&regex, s->buf.buf, 0, NULL, 0)\nd6cf8733 1489) break;\nd6cf8733 1490) i++;\nd6cf8733 1491) if (i == file_diff->hunk_nr)\nd6cf8733 1492) i = 0;\nd6cf8733 1493) if (i != hunk_index)\nd6cf8733 1494) continue;\nd6cf8733 1495) err(s, _(\"No hunk matches the given pattern\"));\nd6cf8733 1496) break;\nd6cf8733 1497) }\nd6cf8733 1498) hunk_index = i;\n\nJohannes Schindelin\tb38dd9e7 strbuf: add a helper function to call the editor \"on an strbuf\"\nstrbuf.c\nb38dd9e7 1129) int strbuf_edit_interactively(struct strbuf *buffer, const char *path,\nb38dd9e7 1132) char *path2 = NULL;\nb38dd9e7 1133) int fd, res = 0;\nb38dd9e7 1135) if (!is_absolute_path(path))\nb38dd9e7 1136) path = path2 = xstrdup(git_path(\"%s\", path));\nb38dd9e7 1138) fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666);\nb38dd9e7 1139) if (fd < 0)\nb38dd9e7 1140) res = error_errno(_(\"could not open '%s' for writing\"), path);\nb38dd9e7 1141) else if (write_in_full(fd, buffer->buf, buffer->len) < 0) {\nb38dd9e7 1142) res = error_errno(_(\"could not write to '%s'\"), path);\nb38dd9e7 1143) close(fd);\nb38dd9e7 1144) } else if (close(fd) < 0)\nb38dd9e7 1145) res = error_errno(_(\"could not close '%s'\"), path);\nb38dd9e7 1147) strbuf_reset(buffer);\nb38dd9e7 1148) if (launch_editor(path, buffer, env) < 0)\nb38dd9e7 1149) res = error_errno(_(\"could not edit '%s'\"), path);\nb38dd9e7 1150) unlink(path);\nb38dd9e7 1153) free(path2);\nb38dd9e7 1154) return res;\n\nJohannes Schindelin\t9254bdfb built-in add -p: implement the 'g' (\"goto\") command\nadd-patch.c\n9254bdfb 1230) static void summarize_hunk(struct add_p_state *s, struct hunk *hunk,\n9254bdfb 1233) struct hunk_header *header = &hunk->header;\n9254bdfb 1234) struct strbuf *plain = &s->plain;\n9254bdfb 1235) size_t len = out->len, i;\n9254bdfb 1237) strbuf_addf(out, \" -%lu,%lu +%lu,%lu \",\n9254bdfb 1240) if (out->len - len < SUMMARY_HEADER_WIDTH)\n9254bdfb 1241) strbuf_addchars(out, ' ',\n9254bdfb 1242) SUMMARY_HEADER_WIDTH + len - out->len);\n9254bdfb 1243) for (i = hunk->start; i < hunk->end; i = find_next_line(plain, i))\n9254bdfb 1244) if (plain->buf[i] != ' ')\n9254bdfb 1245) break;\n9254bdfb 1246) if (i < hunk->end)\n9254bdfb 1247) strbuf_add(out, plain->buf + i, find_next_line(plain, i) - i);\n9254bdfb 1248) if (out->len - len > SUMMARY_LINE_WIDTH)\n9254bdfb 1249) strbuf_setlen(out, len + SUMMARY_LINE_WIDTH);\n9254bdfb 1250) strbuf_complete_line(out);\n9254bdfb 1251) }\n9254bdfb 1254) static size_t display_hunks(struct add_p_state *s,\n9254bdfb 1257) size_t end_index = start_index + DISPLAY_HUNKS_LINES;\n9254bdfb 1259) if (end_index > file_diff->hunk_nr)\n9254bdfb 1260) end_index = file_diff->hunk_nr;\n9254bdfb 1262) while (start_index < end_index) {\n9254bdfb 1263) struct hunk *hunk = file_diff->hunk + start_index++;\n9254bdfb 1265) strbuf_reset(&s->buf);\n9254bdfb 1266) strbuf_addf(&s->buf, \"%c%2d: \", hunk->use == USE_HUNK ? '+'\n9254bdfb 1267)     : hunk->use == SKIP_HUNK ? '-' : ' ',\n9254bdfb 1269) summarize_hunk(s, hunk, &s->buf);\n9254bdfb 1270) fputs(s->buf.buf, stdout);\n9254bdfb 1273) return end_index;\n9254bdfb 1341) if (file_diff->hunk_nr > 1)\n9254bdfb 1415) } else if (s->answer.buf[0] == 'g') {\n9254bdfb 1419) if (file_diff->hunk_nr < 2) {\n9254bdfb 1420) err(s, _(\"No other hunks to goto\"));\n9254bdfb 1421) continue;\n9254bdfb 1423) strbuf_remove(&s->answer, 0, 1);\n9254bdfb 1424) strbuf_trim(&s->answer);\n9254bdfb 1425) i = hunk_index - DISPLAY_HUNKS_LINES / 2;\n9254bdfb 1426) if (i < file_diff->mode_change)\n9254bdfb 1427) i = file_diff->mode_change;\n9254bdfb 1428) while (s->answer.len == 0) {\n9254bdfb 1429) i = display_hunks(s, file_diff, i);\n9254bdfb 1430) printf(\"%s\", i < file_diff->hunk_nr ?\n9254bdfb 1433) fflush(stdout);\n9254bdfb 1434) if (strbuf_getline(&s->answer,\n9254bdfb 1436) break;\n9254bdfb 1437) strbuf_trim_trailing_newline(&s->answer);\n9254bdfb 1440) strbuf_trim(&s->answer);\n9254bdfb 1441) response = strtoul(s->answer.buf, &pend, 10);\n9254bdfb 1442) if (*pend || pend == s->answer.buf)\n9254bdfb 1443) err(s, _(\"Invalid number: '%s'\"),\n9254bdfb 1445) else if (0 < response && response <= file_diff->hunk_nr)\n9254bdfb 1446) hunk_index = response - 1;\n9254bdfb 1448) err(s, Q_(\"Sorry, only %d hunk available.\",\n9254bdfb 1451)     (int)file_diff->hunk_nr);\n\nJohannes Schindelin\tae4780e8 built-in add -p: implement the \"checkout\" patch modes\nadd-patch.c\nae4780e8 1177) static int apply_for_checkout(struct add_p_state *s, struct strbuf *diff,\nae4780e8 1180) const char *reverse = is_reverse ? \"-R\" : NULL;\nae4780e8 1181) struct child_process check_index = CHILD_PROCESS_INIT;\nae4780e8 1182) struct child_process check_worktree = CHILD_PROCESS_INIT;\nae4780e8 1183) struct child_process apply_index = CHILD_PROCESS_INIT;\nae4780e8 1184) struct child_process apply_worktree = CHILD_PROCESS_INIT;\nae4780e8 1187) setup_child_process(s, &check_index,\nae4780e8 1189) applies_index = !pipe_command(&check_index, diff->buf, diff->len,\nae4780e8 1192) setup_child_process(s, &check_worktree,\nae4780e8 1194) applies_worktree = !pipe_command(&check_worktree, diff->buf, diff->len,\nae4780e8 1197) if (applies_worktree && applies_index) {\nae4780e8 1198) setup_child_process(s, &apply_index,\nae4780e8 1200) pipe_command(&apply_index, diff->buf, diff->len,\nae4780e8 1203) setup_child_process(s, &apply_worktree,\nae4780e8 1205) pipe_command(&apply_worktree, diff->buf, diff->len,\nae4780e8 1208) return 1;\nae4780e8 1211) if (!applies_index) {\nae4780e8 1212) err(s, _(\"The selected hunks do not apply to the index!\"));\nae4780e8 1213) if (prompt_yesno(s, _(\"Apply them to the worktree \"\nae4780e8 1215) setup_child_process(s, &apply_worktree,\nae4780e8 1217) return pipe_command(&apply_worktree, diff->buf,\nae4780e8 1220) err(s, _(\"Nothing was applied.\\n\"));\nae4780e8 1223) fwrite(diff->buf, diff->len, 1, stderr);\nae4780e8 1225) return 0;\nae4780e8 1553) if (s->mode->apply_for_checkout)\nae4780e8 1554) apply_for_checkout(s, &s->buf,\nae4780e8 1555)    s->mode->is_reverse);\nae4780e8 1557) setup_child_process(s, &cp, \"apply\", NULL);\nae4780e8 1558) argv_array_pushv(&cp.args, s->mode->apply);\nae4780e8 1559) if (pipe_command(&cp, s->buf.buf, s->buf.len,\nae4780e8 1589) } else if (mode == ADD_P_CHECKOUT) {\nae4780e8 1590) if (!revision)\nae4780e8 1591) s.mode = &patch_mode_checkout_index;\nae4780e8 1592) else if (!strcmp(revision, \"HEAD\"))\nae4780e8 1593) s.mode = &patch_mode_checkout_head;\nae4780e8 1595) s.mode = &patch_mode_checkout_nothead;\n\nbuiltin/add.c\nae4780e8 211) else if (!strcmp(patch_mode, \"--patch=checkout\"))\nae4780e8 212) mode = ADD_P_CHECKOUT;\n\nJohannes Schindelin\tade246ef built-in add -p: implement the 'q' (\"quit\") command\nadd-patch.c\nade246ef 1295) int colored = !!s->colored.len, quit = 0;\nade246ef 1385) } else if (ch == 'd' || ch == 'q') {\nade246ef 1391) if (ch == 'q') {\nade246ef 1392) quit = 1;\nade246ef 1393) break;\nade246ef 1569) return quit;\n\nJohannes Schindelin\t2e408319 built-in add -p: show helpful hint when nothing can be staged\nadd-patch.c\n2e408319 511) } else if (hunk == &file_diff->head &&\n2e408319 512)    starts_with(p, \"Binary files \"))\n2e408319 513) file_diff->binary = 1;\n2e408319 1578) size_t i, binary_count = 0;\n2e408319 1618) if (s.file_diff[i].binary && !s.file_diff[i].hunk_nr)\n2e408319 1619) binary_count++;\n2e408319 1620) else if (patch_update_file(&s, s.file_diff + i))\n2e408319 1623) if (s.file_diff_nr == 0)\n2e408319 1624) fprintf(stderr, _(\"No changes.\\n\"));\n2e408319 1625) else if (binary_count == s.file_diff_nr)\n2e408319 1626) fprintf(stderr, _(\"Only binary files changed.\\n\"));\n\nJohannes Schindelin\tbcdd297b built-in add -p: implement hunk editing\nadd-interactive.c\nbcdd297b 49) init_color(r, s, \"context\", s->context_color,\nbcdd297b 51) init_color(r, s, \"old\", s->file_old_color,\nbcdd297b 53) init_color(r, s, \"new\", s->file_new_color,\n\nadd-patch.c\nbcdd297b 660) size_t i = *hunk_index, delta;\nbcdd297b 665) if (!use_all && hunk->use != USE_HUNK)\nbcdd297b 682) if ((!use_all && hunk->use != USE_HUNK) ||\nbcdd297b 683)     header->new_offset >= next->new_offset + merged->delta ||\nbcdd297b 684)     header->new_offset + header->new_count\nbcdd297b 685)     < next->new_offset + merged->delta)\nbcdd297b 692) if (merged->start < hunk->start && merged->end > hunk->start) {\nbcdd297b 693) merged->end = hunk->end;\nbcdd297b 694) merged->colored_end = hunk->colored_end;\nbcdd297b 695) delta = 0;\nbcdd297b 697) const char *plain = s->plain.buf;\nbcdd297b 698) size_t  overlapping_line_count = header->new_offset\nbcdd297b 699) + header->new_count - merged->delta\nbcdd297b 700) - next->new_offset;\nbcdd297b 701) size_t overlap_end = hunk->start;\nbcdd297b 702) size_t overlap_start = overlap_end;\nbcdd297b 713) for (j = 0; j < overlapping_line_count; j++) {\nbcdd297b 714) overlap_next = find_next_line(&s->plain,\nbcdd297b 717) if (overlap_next > hunk->end)\nbcdd297b 724) if (plain[overlap_end] != ' ')\nbcdd297b 732) overlap_start = overlap_end;\nbcdd297b 733) overlap_end = overlap_next;\nbcdd297b 735) len = overlap_end - overlap_start;\nbcdd297b 737) if (len > merged->end - merged->start ||\nbcdd297b 738)     memcmp(plain + merged->end - len,\nbcdd297b 752) if (merged->end != s->plain.len) {\nbcdd297b 753) size_t start = s->plain.len;\nbcdd297b 755) strbuf_add(&s->plain, plain + merged->start,\nbcdd297b 756)    merged->end - merged->start);\nbcdd297b 757) plain = s->plain.buf;\nbcdd297b 758) merged->start = start;\nbcdd297b 759) merged->end = s->plain.len;\nbcdd297b 762) strbuf_add(&s->plain,\nbcdd297b 764)    hunk->end - overlap_end);\nbcdd297b 765) merged->end = s->plain.len;\nbcdd297b 766) merged->splittable_into += hunk->splittable_into;\nbcdd297b 767) delta = merged->delta;\nbcdd297b 768) merged->delta += hunk->delta;\nbcdd297b 773) header->new_count = next->new_offset + delta\nbcdd297b 774) + next->new_count - header->new_offset;\nbcdd297b 789) size_t save_len = s->plain.len, i;\nbcdd297b 798) if (!use_all && hunk->use != USE_HUNK)\nbcdd297b 803) if (merge_hunks(s, file_diff, &i, use_all, &merged))\nbcdd297b 813) strbuf_setlen(&s->plain, save_len);\nbcdd297b 815) delta += hunk->delta;\nbcdd297b 979) static void recolor_hunk(struct add_p_state *s, struct hunk *hunk)\nbcdd297b 981) const char *plain = s->plain.buf;\nbcdd297b 984) if (!s->colored.len)\nbcdd297b 985) return;\nbcdd297b 987) hunk->colored_start = s->colored.len;\nbcdd297b 988) for (current = hunk->start; current < hunk->end; ) {\nbcdd297b 989) for (eol = current; eol < hunk->end; eol++)\nbcdd297b 990) if (plain[eol] == '\\n')\nbcdd297b 991) break;\nbcdd297b 992) next = eol + (eol < hunk->end);\nbcdd297b 993) if (eol > current && plain[eol - 1] == '\\r')\nbcdd297b 994) eol--;\nbcdd297b 996) strbuf_addstr(&s->colored,\nbcdd297b 997)       plain[current] == '-' ?\nbcdd297b 999)       plain[current] == '+' ?\nbcdd297b 1002) strbuf_add(&s->colored, plain + current, eol - current);\nbcdd297b 1003) strbuf_addstr(&s->colored, GIT_COLOR_RESET);\nbcdd297b 1004) if (next > eol)\nbcdd297b 1005) strbuf_add(&s->colored, plain + eol, next - eol);\nbcdd297b 1006) current = next;\nbcdd297b 1008) hunk->colored_end = s->colored.len;\nbcdd297b 1011) static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)\nbcdd297b 1015) strbuf_reset(&s->buf);\nbcdd297b 1016) strbuf_commented_addf(&s->buf, _(\"Manual hunk edit mode -- see bottom for \"\nbcdd297b 1018) render_hunk(s, hunk, 0, 0, &s->buf);\nbcdd297b 1019) strbuf_commented_addf(&s->buf,\nbcdd297b 1033) strbuf_commented_addf(&s->buf,\nbcdd297b 1040) if (strbuf_edit_interactively(&s->buf, \"addp-hunk-edit.diff\", NULL) < 0)\nbcdd297b 1041) return -1;\nbcdd297b 1044) hunk->start = s->plain.len;\nbcdd297b 1045) for (i = 0; i < s->buf.len; ) {\nbcdd297b 1046) size_t next = find_next_line(&s->buf, i);\nbcdd297b 1048) if (s->buf.buf[i] != comment_line_char)\nbcdd297b 1049) strbuf_add(&s->plain, s->buf.buf + i, next - i);\nbcdd297b 1050) i = next;\nbcdd297b 1053) hunk->end = s->plain.len;\nbcdd297b 1054) if (hunk->end == hunk->start)\nbcdd297b 1056) return 0;\nbcdd297b 1058) recolor_hunk(s, hunk);\nbcdd297b 1065) if (s->plain.buf[hunk->start] == '@' &&\nbcdd297b 1066)     parse_hunk_header(s, hunk) < 0)\nbcdd297b 1069) return 1;\nbcdd297b 1072) static ssize_t recount_edited_hunk(struct add_p_state *s, struct hunk *hunk,\nbcdd297b 1075) struct hunk_header *header = &hunk->header;\nbcdd297b 1078) header->old_count = header->new_count = 0;\nbcdd297b 1079) for (i = hunk->start; i < hunk->end; ) {\nbcdd297b 1080) switch (s->plain.buf[i]) {\nbcdd297b 1082) header->old_count++;\nbcdd297b 1083) break;\nbcdd297b 1085) header->new_count++;\nbcdd297b 1086) break;\nbcdd297b 1088) header->old_count++;\nbcdd297b 1089) header->new_count++;\nbcdd297b 1090) break;\nbcdd297b 1093) i = find_next_line(&s->plain, i);\nbcdd297b 1096) return orig_old_count - orig_new_count\nbcdd297b 1097) - header->old_count + header->new_count;\nbcdd297b 1100) static int run_apply_check(struct add_p_state *s,\nbcdd297b 1103) struct child_process cp = CHILD_PROCESS_INIT;\nbcdd297b 1105) strbuf_reset(&s->buf);\nbcdd297b 1106) reassemble_patch(s, file_diff, 1, &s->buf);\nbcdd297b 1108) setup_child_process(s, &cp,\nbcdd297b 1111) if (pipe_command(&cp, s->buf.buf, s->buf.len, NULL, 0, NULL, 0))\nbcdd297b 1114) return 0;\nbcdd297b 1117) static int prompt_yesno(struct add_p_state *s, const char *prompt)\nbcdd297b 1120) color_fprintf(stdout, s->s.prompt_color, \"%s\", _(prompt));\nbcdd297b 1121) fflush(stdout);\nbcdd297b 1122) if (strbuf_getline(&s->answer, stdin) == EOF)\nbcdd297b 1123) return -1;\nbcdd297b 1124) strbuf_trim_trailing_newline(&s->answer);\nbcdd297b 1125) switch (tolower(s->answer.buf[0])) {\nbcdd297b 1126) case 'n': return 0;\nbcdd297b 1127) case 'y': return 1;\nbcdd297b 1129) }\nbcdd297b 1132) static int edit_hunk_loop(struct add_p_state *s,\nbcdd297b 1135) size_t plain_len = s->plain.len, colored_len = s->colored.len;\nbcdd297b 1138) backup = *hunk;\nbcdd297b 1141) int res = edit_hunk_manually(s, hunk);\nbcdd297b 1142) if (res == 0) {\nbcdd297b 1144) *hunk = backup;\nbcdd297b 1145) return -1;\nbcdd297b 1148) if (res > 0) {\nbcdd297b 1149) hunk->delta +=\nbcdd297b 1150) recount_edited_hunk(s, hunk,\nbcdd297b 1153) if (!run_apply_check(s, file_diff))\nbcdd297b 1154) return 0;\nbcdd297b 1158) strbuf_setlen(&s->plain, plain_len);\nbcdd297b 1159) strbuf_setlen(&s->colored, colored_len);\nbcdd297b 1160) *hunk = backup;\nbcdd297b 1169) res = prompt_yesno(s, _(\"Your edited hunk does not apply. \"\nbcdd297b 1172) if (res < 1)\nbcdd297b 1173) return -1;\nbcdd297b 1174) }\nbcdd297b 1345) if (hunk_index + 1 > file_diff->mode_change &&\nbcdd297b 1346)     !file_diff->deleted)\nbcdd297b 1347) strbuf_addstr(&s->buf, \",e\");\nbcdd297b 1508) } else if (s->answer.buf[0] == 'e') {\nbcdd297b 1509) if (hunk_index + 1 == file_diff->mode_change)\nbcdd297b 1510) err(s, _(\"Sorry, cannot edit this hunk\"));\nbcdd297b 1511) else if (edit_hunk_loop(s, file_diff, hunk) >= 0) {\nbcdd297b 1512) hunk->use = USE_HUNK;\nbcdd297b 1513) goto soft_increment;\nbcdd297b 1550) reassemble_patch(s, file_diff, 0, &s->buf);\n\nJohannes Schindelin\t1942ee44 built-in add -i: wire up the new C code for the `patch` command\nadd-interactive.c\n1942ee44 918) struct pathspec ps_selected = { 0 };\n1942ee44 924) parse_pathspec(&ps_selected,\n1942ee44 929) clear_pathspec(&ps_selected);\n\nJohannes Schindelin\t11f2c0da built-in add -p: coalesce hunks after splitting them\nadd-patch.c\n11f2c0da 657) static int merge_hunks(struct add_p_state *s, struct file_diff *file_diff,\n11f2c0da 661) struct hunk *hunk = file_diff->hunk + i;\n11f2c0da 663) struct hunk_header *header = &merged->header, *next;\n11f2c0da 666) return 0;\n11f2c0da 668) *merged = *hunk;\n11f2c0da 670) merged->colored_start = merged->colored_end = 0;\n11f2c0da 672) for (; i + 1 < file_diff->hunk_nr; i++) {\n11f2c0da 673) hunk++;\n11f2c0da 674) next = &hunk->header;\n11f2c0da 771) header->old_count = next->old_offset + next->old_count\n11f2c0da 772) - header->old_offset;\n11f2c0da 777) if (i == *hunk_index)\n11f2c0da 778) return 0;\n11f2c0da 780) *hunk_index = i;\n11f2c0da 781) return 1;\n11f2c0da 795) struct hunk merged = { 0 };\n11f2c0da 804) hunk = &merged;\n\nJohannes Schindelin\t7584dd3c built-in add -p: offer a helpful error message when hunk navigation failed\nadd-patch.c\n7584dd3c 257) static void err(struct add_p_state *s, const char *fmt, ...)\n7584dd3c 261) va_start(args, fmt);\n7584dd3c 262) fputs(s->s.error_color, stderr);\n7584dd3c 263) vfprintf(stderr, fmt, args);\n7584dd3c 264) fputs(s->s.reset_color, stderr);\n7584dd3c 265) fputc('\\n', stderr);\n7584dd3c 266) va_end(args);\n7584dd3c 267) }\n7584dd3c 1395) } else if (s->answer.buf[0] == 'K') {\n7584dd3c 1396) if (hunk_index)\n7584dd3c 1397) hunk_index--;\n7584dd3c 1399) err(s, _(\"No previous hunk\"));\n7584dd3c 1400) } else if (s->answer.buf[0] == 'J') {\n7584dd3c 1402) hunk_index++;\n7584dd3c 1404) err(s, _(\"No next hunk\"));\n7584dd3c 1405) } else if (s->answer.buf[0] == 'k') {\n7584dd3c 1406) if (undecided_previous >= 0)\n7584dd3c 1407) hunk_index = undecided_previous;\n7584dd3c 1409) err(s, _(\"No previous hunk\"));\n7584dd3c 1410) } else if (s->answer.buf[0] == 'j') {\n7584dd3c 1411) if (undecided_next >= 0)\n7584dd3c 1412) hunk_index = undecided_next;\n7584dd3c 1414) err(s, _(\"No next hunk\"));\n\nJohannes Schindelin\tf6aa7ecc built-in add -i: start implementing the `patch` functionality in C\nadd-patch.c\nf6aa7ecc 269) static void setup_child_process(struct add_p_state *s,\nf6aa7ecc 275) va_start(ap, cp);\nf6aa7ecc 276) while ((arg = va_arg(ap, const char *)))\nf6aa7ecc 277) argv_array_push(&cp->args, arg);\nf6aa7ecc 278) va_end(ap);\nf6aa7ecc 280) cp->git_cmd = 1;\nf6aa7ecc 281) argv_array_pushf(&cp->env_array,\nf6aa7ecc 359) static int parse_diff(struct add_p_state *s, const struct pathspec *ps)\nf6aa7ecc 363) struct child_process cp = CHILD_PROCESS_INIT;\nf6aa7ecc 367) struct hunk *hunk = NULL;\nf6aa7ecc 382) for (i = 0; i < ps->nr; i++)\nf6aa7ecc 387) res = capture_command(&cp, plain, 0);\nf6aa7ecc 394) return 0;\nf6aa7ecc 396) strbuf_complete_line(plain);\nf6aa7ecc 416) p = plain->buf;\nf6aa7ecc 417) pend = p + plain->len;\nf6aa7ecc 418) while (p != pend) {\nf6aa7ecc 419) char *eol = memchr(p, '\\n', pend - p);\nf6aa7ecc 422) if (!eol)\nf6aa7ecc 423) eol = pend;\nf6aa7ecc 425) if (starts_with(p, \"diff \")) {\nf6aa7ecc 436) } else if (p == plain->buf)\nf6aa7ecc 455) memset(hunk, 0, sizeof(*hunk));\nf6aa7ecc 457) hunk->start = p - plain->buf;\nf6aa7ecc 525) p = eol == pend ? pend : eol + 1;\nf6aa7ecc 526) hunk->end = p - plain->buf;\nf6aa7ecc 557) return 0;\nf6aa7ecc 574) static void render_hunk(struct add_p_state *s, struct hunk *hunk,\nf6aa7ecc 621) }\nf6aa7ecc 818) }\nf6aa7ecc 1290) size_t hunk_index = 0;\nf6aa7ecc 1294) struct child_process cp = CHILD_PROCESS_INIT;\nf6aa7ecc 1299) return 0;\nf6aa7ecc 1301) strbuf_reset(&s->buf);\nf6aa7ecc 1303) fputs(s->buf.buf, stdout);\nf6aa7ecc 1306) hunk_index = 0;\nf6aa7ecc 1309) undecided_previous = -1;\nf6aa7ecc 1310) for (i = hunk_index - 1; i >= 0; i--)\nf6aa7ecc 1312) undecided_previous = i;\nf6aa7ecc 1313) break;\nf6aa7ecc 1316) undecided_next = -1;\nf6aa7ecc 1319) undecided_next = i;\nf6aa7ecc 1320) break;\nf6aa7ecc 1324) if (undecided_previous < 0 && undecided_next < 0 &&\nf6aa7ecc 1325)     hunk->use != UNDECIDED_HUNK)\nf6aa7ecc 1326) break;\nf6aa7ecc 1328) strbuf_reset(&s->buf);\nf6aa7ecc 1330) fputs(s->buf.buf, stdout);\nf6aa7ecc 1332) strbuf_reset(&s->buf);\nf6aa7ecc 1333) if (undecided_previous >= 0)\nf6aa7ecc 1334) strbuf_addstr(&s->buf, \",k\");\nf6aa7ecc 1335) if (hunk_index)\nf6aa7ecc 1336) strbuf_addstr(&s->buf, \",K\");\nf6aa7ecc 1337) if (undecided_next >= 0)\nf6aa7ecc 1338) strbuf_addstr(&s->buf, \",j\");\nf6aa7ecc 1340) strbuf_addstr(&s->buf, \",J\");\nf6aa7ecc 1363) fflush(stdout);\nf6aa7ecc 1364) if (strbuf_getline(&s->answer, stdin) == EOF)\nf6aa7ecc 1365) break;\nf6aa7ecc 1366) strbuf_trim_trailing_newline(&s->answer);\nf6aa7ecc 1368) if (!s->answer.len)\nf6aa7ecc 1369) continue;\nf6aa7ecc 1370) ch = tolower(s->answer.buf[0]);\nf6aa7ecc 1371) if (ch == 'y') {\nf6aa7ecc 1372) hunk->use = USE_HUNK;\nf6aa7ecc 1374) hunk_index = undecided_next < 0 ?\nf6aa7ecc 1376) } else if (ch == 'n') {\nf6aa7ecc 1377) hunk->use = SKIP_HUNK;\nf6aa7ecc 1378) goto soft_increment;\nf6aa7ecc 1379) } else if (ch == 'a') {\nf6aa7ecc 1382) if (hunk->use == UNDECIDED_HUNK)\nf6aa7ecc 1383) hunk->use = USE_HUNK;\nf6aa7ecc 1388) if (hunk->use == UNDECIDED_HUNK)\nf6aa7ecc 1389) hunk->use = SKIP_HUNK;\nf6aa7ecc 1540) }\nf6aa7ecc 1545) break;\nf6aa7ecc 1549) strbuf_reset(&s->buf);\nf6aa7ecc 1568) putchar('\\n');\nf6aa7ecc 1607) if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||\nf6aa7ecc 1611)     parse_diff(&s, ps) < 0) {\nf6aa7ecc 1612) strbuf_release(&s.plain);\nf6aa7ecc 1614) return -1;\nf6aa7ecc 1628) strbuf_release(&s.answer);\nf6aa7ecc 1629) strbuf_release(&s.buf);\nf6aa7ecc 1630) strbuf_release(&s.plain);\nf6aa7ecc 1632) return 0;\n\nbuiltin/add.c\nf6aa7ecc 202) if (!patch_mode)\n\nJohannes Schindelin\t572bdc3a built-in add -p: prepare for patch modes other than \"stage\"\nadd-interactive.c\n572bdc3a 927) res = run_add_p(s->r, ADD_P_STAGE, NULL, &ps_selected);\n\nadd-patch.c\n572bdc3a 370) argv_array_pushv(&args, s->mode->diff);\n572bdc3a 371) if (s->revision) {\n572bdc3a 373) argv_array_push(&args,\n572bdc3a 375) !strcmp(\"HEAD\", s->revision) &&\n572bdc3a 376) get_oid(\"HEAD\", &oid) ?\n572bdc3a 379) color_arg_index = args.argc;\n572bdc3a 381) argv_array_pushl(&args, \"--no-color\", \"-p\", \"--\", NULL);\n572bdc3a 599) if (s->mode->is_reverse)\n572bdc3a 600) old_offset -= delta;\n572bdc3a 602) new_offset += delta;\n572bdc3a 1025)       s->mode->is_reverse ? '+' : '-',\n572bdc3a 1026)       s->mode->is_reverse ? '-' : '+',\n572bdc3a 1028) strbuf_commented_addf(&s->buf, \"%s\", _(s->mode->edit_hunk_hint));\n572bdc3a 1110) argv_array_pushv(&cp.args, s->mode->apply_check);\n572bdc3a 1361)       _(s->mode->prompt_mode[prompt_mode_type]),\n572bdc3a 1519)       _(s->mode->help_patch_text));\n572bdc3a 1572) int run_add_p(struct repository *r, enum add_p_mode mode,\n572bdc3a 1605) s.revision = revision;\n\nbuiltin/add.c\n572bdc3a 205) if (!strcmp(patch_mode, \"--patch\"))\n572bdc3a 206) mode = ADD_P_STAGE;\n572bdc3a 218) return !!run_add_p(the_repository, mode, revision, pathspec);\n\nJohannes Schindelin\te3bd11b4 built-in add -p: show colored hunks by default\nadd-patch.c\ne3bd11b4 361) struct argv_array args = ARGV_ARRAY_INIT;\ne3bd11b4 362) struct strbuf *plain = &s->plain, *colored = NULL;\ne3bd11b4 383) argv_array_push(&args, ps->items[i].original);\ne3bd11b4 385) setup_child_process(s, &cp, NULL);\ne3bd11b4 386) cp.argv = args.argv;\ne3bd11b4 388) if (res) {\ne3bd11b4 389) argv_array_clear(&args);\ne3bd11b4 392) if (!plain->len) {\ne3bd11b4 393) argv_array_clear(&args);\ne3bd11b4 398) if (want_color_fd(1, -1)) {\ne3bd11b4 399) struct child_process colored_cp = CHILD_PROCESS_INIT;\ne3bd11b4 401) setup_child_process(s, &colored_cp, NULL);\ne3bd11b4 402) xsnprintf((char *)args.argv[color_arg_index], 8, \"--color\");\ne3bd11b4 403) colored_cp.argv = args.argv;\ne3bd11b4 404) colored = &s->colored;\ne3bd11b4 405) res = capture_command(&colored_cp, colored, 0);\ne3bd11b4 406) argv_array_clear(&args);\ne3bd11b4 407) if (res)\ne3bd11b4 409) strbuf_complete_line(colored);\ne3bd11b4 410) colored_p = colored->buf;\ne3bd11b4 411) colored_pend = colored_p + colored->len;\ne3bd11b4 413) argv_array_clear(&args);\ne3bd11b4 458) if (colored)\ne3bd11b4 459) hunk->colored_start = colored_p - colored->buf;\ne3bd11b4 528) if (colored) {\ne3bd11b4 529) char *colored_eol = memchr(colored_p, '\\n',\ne3bd11b4 530)    colored_pend - colored_p);\ne3bd11b4 531) if (colored_eol)\ne3bd11b4 532) colored_p = colored_eol + 1;\ne3bd11b4 534) colored_p = colored_pend;\ne3bd11b4 536) hunk->colored_end = colored_p - colored->buf;\ne3bd11b4 615) if (colored)\ne3bd11b4 616) strbuf_add(out, s->colored.buf + hunk->colored_start,\ne3bd11b4 617)    hunk->colored_end - hunk->colored_start);\ne3bd11b4 619) strbuf_add(out, s->plain.buf + hunk->start,\ne3bd11b4 620)    hunk->end - hunk->start);\ne3bd11b4 1613) strbuf_release(&s.colored);\ne3bd11b4 1631) strbuf_release(&s.colored);\n\nJohannes Schindelin\t510aeca1 built-in add -p: implement the hunk splitting feature\nadd-patch.c\n510aeca1 364) char *p, *pend, *colored_p = NULL, *colored_pend = NULL, marker = '\\0';\n510aeca1 435) marker = '\\0';\n510aeca1 444) if (marker == '-' || marker == '+')\n510aeca1 449) hunk->splittable_into++;\n510aeca1 470) marker = *p;\n510aeca1 520) if ((marker == '-' || marker == '+') && *p == ' ')\n510aeca1 521) hunk->splittable_into++;\n510aeca1 522) if (marker && *p != '\\\\')\n510aeca1 523) marker = *p;\n510aeca1 550) if (marker == '-' || marker == '+')\n510aeca1 555) hunk->splittable_into++;\n510aeca1 560) static size_t find_next_line(struct strbuf *sb, size_t offset)\n510aeca1 564) if (offset >= sb->len)\n510aeca1 568) eol = memchr(sb->buf + offset, '\\n', sb->len - offset);\n510aeca1 569) if (!eol)\n510aeca1 570) return sb->len;\n510aeca1 571) return eol - sb->buf + 1;\n510aeca1 820) static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,\n510aeca1 823) int colored = !!s->colored.len, first = 1;\n510aeca1 824) struct hunk *hunk = file_diff->hunk + hunk_index;\n510aeca1 826) size_t end, colored_end, current, colored_current = 0, context_line_count;\n510aeca1 830) if (hunk_index >= file_diff->hunk_nr)\n510aeca1 834) if (hunk->splittable_into < 2)\n510aeca1 835) return 0;\n510aeca1 836) splittable_into = hunk->splittable_into;\n510aeca1 838) end = hunk->end;\n510aeca1 839) colored_end = hunk->colored_end;\n510aeca1 841) remaining = hunk->header;\n510aeca1 843) file_diff->hunk_nr += splittable_into - 1;\n510aeca1 844) ALLOC_GROW(file_diff->hunk, file_diff->hunk_nr, file_diff->hunk_alloc);\n510aeca1 845) if (hunk_index + splittable_into < file_diff->hunk_nr)\n510aeca1 846) memmove(file_diff->hunk + hunk_index + splittable_into,\n510aeca1 847) file_diff->hunk + hunk_index + 1,\n510aeca1 848) (file_diff->hunk_nr - hunk_index - splittable_into)\n510aeca1 850) hunk = file_diff->hunk + hunk_index;\n510aeca1 851) hunk->splittable_into = 1;\n510aeca1 852) memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk));\n510aeca1 854) header = &hunk->header;\n510aeca1 855) header->old_count = header->new_count = 0;\n510aeca1 857) current = hunk->start;\n510aeca1 858) if (colored)\n510aeca1 859) colored_current = hunk->colored_start;\n510aeca1 860) marker = '\\0';\n510aeca1 861) context_line_count = 0;\n510aeca1 863) while (splittable_into > 1) {\n510aeca1 864) ch = s->plain.buf[current];\n510aeca1 866) if (!ch)\n510aeca1 873) if ((marker == '-' || marker == '+') && ch == ' ') {\n510aeca1 874) first = 0;\n510aeca1 875) hunk[1].start = current;\n510aeca1 876) if (colored)\n510aeca1 877) hunk[1].colored_start = colored_current;\n510aeca1 878) context_line_count = 0;\n510aeca1 888) if (marker != ' ' || (ch != '-' && ch != '+')) {\n510aeca1 891) if (ch == '\\\\')\n510aeca1 892) ch = marker ? marker : ' ';\n510aeca1 895) if (ch == ' ')\n510aeca1 896) context_line_count++;\n510aeca1 897) else if (ch == '-')\n510aeca1 898) header->old_count++;\n510aeca1 899) else if (ch == '+')\n510aeca1 900) header->new_count++;\n510aeca1 903) marker = ch;\n510aeca1 904) current = find_next_line(&s->plain, current);\n510aeca1 905) if (colored)\n510aeca1 906) colored_current =\n510aeca1 907) find_next_line(&s->colored,\n510aeca1 909) continue;\n510aeca1 919) if (first) {\n510aeca1 920) if (header->old_count || header->new_count)\n510aeca1 925) header->old_count = context_line_count;\n510aeca1 926) header->new_count = context_line_count;\n510aeca1 927) context_line_count = 0;\n510aeca1 928) first = 0;\n510aeca1 929) goto next_hunk_line;\n510aeca1 932) remaining.old_offset += header->old_count;\n510aeca1 933) remaining.old_count -= header->old_count;\n510aeca1 934) remaining.new_offset += header->new_count;\n510aeca1 935) remaining.new_count -= header->new_count;\n510aeca1 938) hunk[1].header.old_offset =\n510aeca1 939) header->old_offset + header->old_count;\n510aeca1 940) hunk[1].header.new_offset =\n510aeca1 941) header->new_offset + header->new_count;\n510aeca1 944) header->old_count += context_line_count;\n510aeca1 945) header->new_count += context_line_count;\n510aeca1 947) hunk->end = current;\n510aeca1 948) if (colored)\n510aeca1 949) hunk->colored_end = colored_current;\n510aeca1 951) hunk++;\n510aeca1 952) hunk->splittable_into = 1;\n510aeca1 953) hunk->use = hunk[-1].use;\n510aeca1 954) header = &hunk->header;\n510aeca1 956) header->old_count = header->new_count = context_line_count;\n510aeca1 957) context_line_count = 0;\n510aeca1 959) splittable_into--;\n510aeca1 960) marker = ch;\n510aeca1 964) if (header->old_offset != remaining.old_offset)\n510aeca1 967) if (header->new_offset != remaining.new_offset)\n510aeca1 970) header->old_count = remaining.old_count;\n510aeca1 971) header->new_count = remaining.new_count;\n510aeca1 972) hunk->end = end;\n510aeca1 973) if (colored)\n510aeca1 974) hunk->colored_end = colored_end;\n510aeca1 976) return 0;\n510aeca1 1343) if (hunk->splittable_into > 1)\n510aeca1 1344) strbuf_addstr(&s->buf, \",s\");\n510aeca1 1499) } else if (s->answer.buf[0] == 's') {\n510aeca1 1500) size_t splittable_into = hunk->splittable_into;\n510aeca1 1501) if (splittable_into < 2)\n510aeca1 1502) err(s, _(\"Sorry, cannot split this hunk\"));\n510aeca1 1503) else if (!split_hunk(s, file_diff,\n510aeca1 1504)      hunk - file_diff->hunk))\n510aeca1 1505) color_fprintf_ln(stdout, s->s.header_color,\n\nJohannes Schindelin\t80399aec built-in add -p: support multi-file diffs\nadd-patch.c\n80399aec 365) size_t file_diff_alloc = 0, i, color_arg_index;\n80399aec 366) struct file_diff *file_diff = NULL;\n80399aec 426) s->file_diff_nr++;\n80399aec 427) ALLOC_GROW(s->file_diff, s->file_diff_nr,\n80399aec 429) file_diff = s->file_diff + s->file_diff_nr - 1;\n80399aec 430) memset(file_diff, 0, sizeof(*file_diff));\n80399aec 431) hunk = &file_diff->head;\n80399aec 432) hunk->start = p - plain->buf;\n80399aec 433) if (colored_p)\n80399aec 434) hunk->colored_start = colored_p - colored->buf;\n80399aec 451) file_diff->hunk_nr++;\n80399aec 452) ALLOC_GROW(file_diff->hunk, file_diff->hunk_nr,\n80399aec 454) hunk = file_diff->hunk + file_diff->hunk_nr - 1;\n80399aec 784) static void reassemble_patch(struct add_p_state *s,\n80399aec 797) hunk = file_diff->hunk + i;\n80399aec 1287) static int patch_update_file(struct add_p_state *s,\n80399aec 1298) if (!file_diff->hunk_nr)\n80399aec 1305) if (hunk_index >= file_diff->hunk_nr)\n80399aec 1307) hunk = file_diff->hunk + hunk_index;\n80399aec 1311) if (file_diff->hunk[i].use == UNDECIDED_HUNK) {\n80399aec 1317) for (i = hunk_index + 1; i < file_diff->hunk_nr; i++)\n80399aec 1318) if (file_diff->hunk[i].use == UNDECIDED_HUNK) {\n80399aec 1339) if (hunk_index + 1 < file_diff->hunk_nr)\n80399aec 1359)       (uintmax_t)file_diff->hunk_nr);\n80399aec 1375) file_diff->hunk_nr : undecided_next;\n80399aec 1380) for (; hunk_index < file_diff->hunk_nr; hunk_index++) {\n80399aec 1381) hunk = file_diff->hunk + hunk_index;\n80399aec 1386) for (; hunk_index < file_diff->hunk_nr; hunk_index++) {\n80399aec 1387) hunk = file_diff->hunk + hunk_index;\n80399aec 1401) if (hunk_index + 1 < file_diff->hunk_nr)\n80399aec 1543) for (i = 0; i < file_diff->hunk_nr; i++)\n80399aec 1544) if (file_diff->hunk[i].use == USE_HUNK)\n80399aec 1547) if (i < file_diff->hunk_nr) {\n80399aec 1617) for (i = 0; i < s.file_diff_nr; i++)\n80399aec 1621) break;\n\nJohannes Schindelin\t47dc4fd5 built-in add -p: handle deleted empty files\nadd-patch.c\n47dc4fd5 439) else if (file_diff->deleted)\n47dc4fd5 441) else if (starts_with(p, \"@@ \") ||\n47dc4fd5 442)  (hunk == &file_diff->head &&\n47dc4fd5 443)   skip_prefix(p, \"deleted file\", &deleted))) {\n47dc4fd5 461) if (deleted)\n47dc4fd5 462) file_diff->deleted = 1;\n47dc4fd5 463) else if (parse_hunk_header(s, hunk) < 0)\n\nJohannes Schindelin\t5906d5de built-in app -p: allow selecting a mode change as a \"hunk\"\nadd-patch.c\n5906d5de 348) static int is_octal(const char *p, size_t len)\n5906d5de 350) if (!len)\n5906d5de 351) return 0;\n5906d5de 353) while (len--)\n5906d5de 354) if (*p < '0' || *(p++) > '7')\n5906d5de 355) return 0;\n5906d5de 356) return 1;\n5906d5de 420) const char *deleted = NULL, *mode_change = NULL;\n5906d5de 471) } else if (hunk == &file_diff->head &&\n5906d5de 472)    skip_prefix(p, \"old mode \", &mode_change) &&\n5906d5de 473)    is_octal(mode_change, eol - mode_change)) {\n5906d5de 474) if (file_diff->mode_change)\n5906d5de 477) if (file_diff->hunk_nr++)\n5906d5de 485) file_diff->mode_change = 1;\n5906d5de 486) ALLOC_GROW(file_diff->hunk, file_diff->hunk_nr,\n5906d5de 488) memset(file_diff->hunk, 0, sizeof(struct hunk));\n5906d5de 489) file_diff->hunk->start = p - plain->buf;\n5906d5de 490) if (colored_p)\n5906d5de 491) file_diff->hunk->colored_start =\n5906d5de 492) colored_p - colored->buf;\n5906d5de 493) } else if (hunk == &file_diff->head &&\n5906d5de 494)    skip_prefix(p, \"new mode \", &mode_change) &&\n5906d5de 495)    is_octal(mode_change, eol - mode_change)) {\n5906d5de 501) if (!file_diff->mode_change)\n5906d5de 504) if (file_diff->hunk_nr != 1)\n5906d5de 507) if (p - plain->buf != file_diff->hunk->end)\n5906d5de 515) if (file_diff->deleted && file_diff->mode_change)\n5906d5de 539) if (mode_change) {\n5906d5de 540) if (file_diff->hunk_nr != 1)\n5906d5de 544) file_diff->hunk->end = hunk->end;\n5906d5de 545) if (colored)\n5906d5de 546) file_diff->hunk->colored_end = hunk->colored_end;\n5906d5de 623) static void render_diff_header(struct add_p_state *s,\n5906d5de 632) int skip_mode_change =\n5906d5de 633) file_diff->mode_change && file_diff->hunk->use != USE_HUNK;\n5906d5de 634) struct hunk *head = &file_diff->head, *first = file_diff->hunk;\n5906d5de 636) if (!skip_mode_change) {\n5906d5de 637) render_hunk(s, head, 0, colored, out);\n5906d5de 638) return;\n5906d5de 641) if (colored) {\n5906d5de 642) const char *p = s->colored.buf;\n5906d5de 644) strbuf_add(out, p + head->colored_start,\n5906d5de 645)     first->colored_start - head->colored_start);\n5906d5de 646) strbuf_add(out, p + first->colored_end,\n5906d5de 647)     head->colored_end - first->colored_end);\n5906d5de 649) const char *p = s->plain.buf;\n5906d5de 651) strbuf_add(out, p + head->start, first->start - head->start);\n5906d5de 652) strbuf_add(out, p + first->end, head->end - first->end);\n5906d5de 792) render_diff_header(s, file_diff, 0, out);\n5906d5de 794) for (i = file_diff->mode_change; i < file_diff->hunk_nr; i++) {\n5906d5de 1302) render_diff_header(s, file_diff, colored, &s->buf);\n\nJonathan Nieder\tee70c128 index: offer advice for unknown index extensions\nread-cache.c\nee70c128 1756) if (advice_unknown_index_extension) {\n\nJosh Steadmon\t6da1f1a9 protocol: advertise multiple supported versions\nremote-curl.c\n6da1f1a9 354) return 0;\n\nMatheus Tavares\tbeebb9d2 object-store: allow threaded access to object reading\npackfile.c\nbeebb9d2 1465) return;\n\nsha1-file.c\nbeebb9d2 1431) return;\nbeebb9d2 1440) return;\n\nPhillip Wood\t430b75f7 commit: give correct advice for empty commit during a rebase\nsequencer.c\n430b75f7 1583)     return -1;\n\n\n\nUncovered code in 'jch' not in 'next'\n--------------------------------------------------------\n\nCommits introducing uncovered code:\nAlban Gruin\t0d50cf5e sequencer: move check_todo_list_from_file() to rebase-interactive.c\nrebase-interactive.c\n0d50cf5e 210) goto out;\n0d50cf5e 215) goto out;\n0d50cf5e 224) fprintf(stderr, _(edit_todo_list_advice));\n\nAlex Torok\tfed842f0 rebase: fix --fork-point with short refname\nbuiltin/merge-base.c\nfed842f0 128) return 1;\n\nMartin Ågren\t3bf986d6 builtin/config: collect \"value_regexp\" data in a struct\nbuiltin/config.c\n3bf986d6 329) FREE_AND_NULL(cmd_line_value.regexp);\n\nMartin Ågren\t3bcdd852 builtin/config: extract `handle_value_regex()` from `get_value()`\nbuiltin/config.c\n3bcdd852 330) return CONFIG_INVALID_PATTERN;\n3bcdd852 375) goto free_strings;\n\n\n\nUncovered code in 'next' not in 'master'\n--------------------------------------------------------\n\nCommits introducing uncovered code:\nDerrick Stolee\td89f09c8 clone: add --sparse mode\nbuiltin/clone.c\nd89f09c8 753) result = 1;\nd89f09c8 1132) return 1;\n\nDerrick Stolee\te091228e sparse-checkout: update working directory in-process\nbuiltin/sparse-checkout.c\ne091228e 85) return 0;\n\nDerrick Stolee\tbab3c359 sparse-checkout: create 'init' subcommand\nbuiltin/sparse-checkout.c\nbab3c359 221) return 1;\nbab3c359 275) return 1;\n\nDerrick Stolee\t190a65f9 sparse-checkout: respect core.ignoreCase in cone mode\nbuiltin/sparse-checkout.c\n190a65f9 337)    strihash(e->pattern) :\n\ndir.c\n190a65f9 669)    strihash(translated->pattern) :\n190a65f9 700)    strihash(translated->pattern) :\n\nDerrick Stolee\taf09ce24 sparse-checkout: init and set in cone mode\nbuiltin/sparse-checkout.c\naf09ce24 352) return;\n\nDerrick Stolee\t96cc8ab5 sparse-checkout: use hashmaps for cone patterns\ndir.c\n96cc8ab5 656) pl->use_cone_patterns = 0;\n96cc8ab5 658) goto clear_hashmaps;\n96cc8ab5 682) hashmap_add(&pl->parent_hashmap, &translated->ent);\n96cc8ab5 683) hashmap_remove(&pl->recursive_hashmap, &translated->ent, &data);\n96cc8ab5 684) free(data);\n96cc8ab5 685) return;\n96cc8ab5 691) goto clear_hashmaps;\n96cc8ab5 709) hashmap_remove(&pl->parent_hashmap, &translated->ent, &data);\n96cc8ab5 710) free(data);\n96cc8ab5 711) free(translated);\n96cc8ab5 1273) return MATCHED;\n\nJeff King\t4f0bd8b9 pack-objects: improve partial packfile reuse\nbuiltin/pack-objects.c\n4f0bd8b9 1124) return 1;\n4f0bd8b9 2681) (reuse_packfile_bitmap &&\n4f0bd8b9 2682)  bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid));\n\npack-bitmap.c\n4f0bd8b9 808) return;\n4f0bd8b9 811) return;\n4f0bd8b9 823) return;\n4f0bd8b9 861) i = bitmap_git->pack->num_objects / BITS_IN_EWORD;\n\nJeff King\t7cb9754e pack-objects: introduce pack.allowPackReuse\nbuiltin/pack-objects.c\n7cb9754e 2834) allow_pack_reuse = git_config_bool(k, v);\n7cb9754e 2835) return 0;\n\nJeff King\t7b143c16 pack-bitmap: introduce bitmap_walk_contains()\npack-bitmap.c\n7b143c16 903) return 0;\n\nTanushree Tumane\t51a0a4ed bisect--helper: avoid use-after-free\nbuiltin/bisect--helper.c\n51a0a4ed 177) return -1;\n\n\n\nUncovered code in 'master' not in 'master@{1}'\n--------------------------------------------------------\n\nCommits introducing uncovered code:\nAlban Gruin\t393adf7a sequencer: directly call pick_commits() from complete_action()\nsequencer.c\n393adf7a 5272) goto cleanup;\n\nDaniel Ferreira\t5e82b9e4 built-in add -i: implement the `status` command\nadd-interactive.c\n5e82b9e4 629) return -1;\n5e82b9e4 632) putchar('\\n');\n5e82b9e4 634) return 0;\n\nDerrick Stolee\t44a4693b progress: create GIT_PROGRESS_DELAY\nprogress.c\n44a4693b 308) return start_progress_delay(title, total, get_default_delay(), 1);\n\nGarima Singh\ta62f9d1a test-path-utils: offer to run a protectNTFS/protectHFS benchmark\nt/helper/test-path-utils.c\na62f9d1a 194) static uint64_t my_random(void)\na62f9d1a 196) my_random_value = my_random_value * 1103515245 + 12345;\na62f9d1a 197) return my_random_value;\na62f9d1a 205) static double my_sqrt(double value)\na62f9d1a 207) const double epsilon = 1e-6;\na62f9d1a 208) double x = value;\na62f9d1a 210) if (value == 0)\na62f9d1a 211) return 0;\na62f9d1a 214) double delta = (value / x - x) / 2;\na62f9d1a 215) if (delta < epsilon && delta > -epsilon)\na62f9d1a 216) return x + delta;\na62f9d1a 217) x += delta;\na62f9d1a 218) }\na62f9d1a 221) static int protect_ntfs_hfs_benchmark(int argc, const char **argv)\na62f9d1a 223) size_t i, j, nr, min_len = 3, max_len = 20;\na62f9d1a 225) int repetitions = 15, file_mode = 0100644;\na62f9d1a 231) if (argc > 1 && !strcmp(argv[1], \"--with-symlink-mode\")) {\na62f9d1a 232) file_mode = 0120000;\na62f9d1a 233) argc--;\na62f9d1a 234) argv++;\na62f9d1a 237) nr = argc > 1 ? strtoul(argv[1], NULL, 0) : 1000000;\na62f9d1a 238) ALLOC_ARRAY(names, nr);\na62f9d1a 240) if (argc > 2) {\na62f9d1a 241) min_len = strtoul(argv[2], NULL, 0);\na62f9d1a 242) if (argc > 3)\na62f9d1a 243) max_len = strtoul(argv[3], NULL, 0);\na62f9d1a 244) if (min_len > max_len)\na62f9d1a 248) for (i = 0; i < nr; i++) {\na62f9d1a 249) size_t len = min_len + (my_random() % (max_len + 1 - min_len));\na62f9d1a 251) names[i] = xmallocz(len);\na62f9d1a 252) while (len > 0)\na62f9d1a 253) names[i][--len] = (char)(' ' + (my_random() % ('\\x7f' - ' ')));\na62f9d1a 256) for (protect_ntfs = 0; protect_ntfs < 2; protect_ntfs++)\na62f9d1a 257) for (protect_hfs = 0; protect_hfs < 2; protect_hfs++) {\na62f9d1a 258) cumul = 0;\na62f9d1a 259) cumul2 = 0;\na62f9d1a 260) for (i = 0; i < repetitions; i++) {\na62f9d1a 261) begin = getnanotime();\na62f9d1a 262) for (j = 0; j < nr; j++)\na62f9d1a 263) verify_path(names[j], file_mode);\na62f9d1a 264) end = getnanotime();\na62f9d1a 265) printf(\"protect_ntfs = %d, protect_hfs = %d: %lfms\\n\", protect_ntfs, protect_hfs, (end-begin) / (double)1e6);\na62f9d1a 266) cumul += end - begin;\na62f9d1a 267) cumul2 += (end - begin) * (end - begin);\na62f9d1a 269) m[protect_ntfs][protect_hfs] = cumul / (double)repetitions;\na62f9d1a 270) v[protect_ntfs][protect_hfs] = my_sqrt(cumul2 / (double)repetitions - m[protect_ntfs][protect_hfs] * m[protect_ntfs][protect_hfs]);\na62f9d1a 271) printf(\"mean: %lfms, stddev: %lfms\\n\", m[protect_ntfs][protect_hfs] / (double)1e6, v[protect_ntfs][protect_hfs] / (double)1e6);\na62f9d1a 274) for (protect_ntfs = 0; protect_ntfs < 2; protect_ntfs++)\na62f9d1a 275) for (protect_hfs = 0; protect_hfs < 2; protect_hfs++)\na62f9d1a 276) printf(\"ntfs=%d/hfs=%d: %lf%% slower\\n\", protect_ntfs, protect_hfs, (m[protect_ntfs][protect_hfs] - m[0][0]) * 100 / m[0][0]);\na62f9d1a 278) return 0;\na62f9d1a 451) if (argc > 1 && !strcmp(argv[1], \"protect_ntfs_hfs\"))\na62f9d1a 452) return !!protect_ntfs_hfs_benchmark(argc - 1, argv + 1);\n\nGarima Singh\tad155925 tests: add a helper to stress test argument quoting\nt/helper/test-run-command.c\nad155925 205) static uint64_t my_random(void)\nad155925 207) uint64_t res = my_random_next;\nad155925 208) my_random_next = my_random_next * 1103515245 + 12345;\nad155925 209) return res;\nad155925 212) static int quote_stress_test(int argc, const char **argv)\nad155925 220) char special[] = \".?*\\\\^_\\\"'`{}()[]<>@~&+:;$%\"; // \\t\\r\\n\\a\";\nad155925 222) struct strbuf out = STRBUF_INIT;\nad155925 223) struct argv_array args = ARGV_ARRAY_INIT;\nad155925 224) struct option options[] = {\nad155925 230) const char * const usage[] = {\nad155925 235) argc = parse_options(argc, argv, NULL, options, usage, 0);\nad155925 239) for (i = 0; i < trials; i++) {\nad155925 240) struct child_process cp = CHILD_PROCESS_INIT;\nad155925 242) int ret = 0;\nad155925 244) argv_array_clear(&args);\nad155925 251) arg_offset = args.argc;\nad155925 278) cp.argv = args.argv;\nad155925 279) strbuf_reset(&out);\nad155925 280) if (pipe_command(&cp, NULL, 0, &out, 0, NULL, 0) < 0)\nad155925 283) for (j = 0, k = 0; j < arg_count; j++) {\nad155925 284) const char *arg = args.argv[j + arg_offset];\nad155925 286) if (strcmp(arg, out.buf + k))\nad155925 290) k += strlen(out.buf + k) + 1;\nad155925 293) if (k != out.len)\nad155925 297) if (ret) {\nad155925 298) fprintf(stderr, \"Trial #%d failed. Arguments:\\n\", i);\nad155925 299) for (j = 0; j < arg_count; j++)\nad155925 300) fprintf(stderr, \"arg #%d: '%s'\\n\",\nad155925 301) (int)j, args.argv[j + arg_offset]);\nad155925 303) strbuf_release(&out);\nad155925 304) argv_array_clear(&args);\nad155925 306) return ret;\nad155925 309) if (i && (i % 100) == 0)\nad155925 310) fprintf(stderr, \"Trials completed: %d\\n\", (int)i);\nad155925 313) strbuf_release(&out);\nad155925 314) argv_array_clear(&args);\nad155925 316) return 0;\nad155925 319) static int quote_echo(int argc, const char **argv)\nad155925 321) while (argc > 1) {\nad155925 322) fwrite(argv[1], strlen(argv[1]), 1, stdout);\nad155925 323) fputc('\\0', stdout);\nad155925 324) argv++;\nad155925 325) argc--;\nad155925 328) return 0;\nad155925 384) return !!quote_stress_test(argc - 1, argv + 1);\nad155925 387) return !!quote_echo(argc - 1, argv + 1);\n\nHans Jerry Illikainen\t72b006f4 gpg-interface: prefer check_signature() for GPG verification\nbuiltin/fmt-merge-msg.c\n72b006f4 511) strbuf_addstr(&sig, \"gpg verification failed.\\n\");\n\ngpg-interface.c\n72b006f4 223) return error_errno(_(\"could not create temporary file\"));\n72b006f4 226) error_errno(_(\"failed writing detached signature to '%s'\"),\n72b006f4 228) delete_tempfile(&temp);\n72b006f4 229) return -1;\n72b006f4 244) gpg_status = &buf;\n\nlog-tree.c\n72b006f4 461) show_sig_lines(opt, status, \"No signature\\n\");\n72b006f4 535) } else if (verify_message.len <= gpg_message_offset)\n\nJeff King\t01968302 fast-import: delay creating leading directories for export-marks\nfast-import.c\n01968302 1687) failure |= error_errno(\"unable to create leading directories of %s\",\n01968302 1689) return;\n\nJohannes Schindelin\t55953c77 quote-stress-test: accept arguments to test via the command-line\nt/helper/test-run-command.c\n55953c77 253) if (argc > 0) {\n55953c77 254) trials = 1;\n55953c77 255) arg_count = argc;\n55953c77 256) for (j = 0; j < arg_count; j++)\n55953c77 257) argv_array_push(&args, argv[j]);\n55953c77 259) arg_count = 1 + (my_random() % 5);\n55953c77 260) for (j = 0; j < arg_count; j++) {\n55953c77 262) size_t min_len = 1;\n55953c77 263) size_t arg_len = min_len +\n55953c77 264) (my_random() % (ARRAY_SIZE(buf) - min_len));\n55953c77 266) for (k = 0; k < arg_len; k++)\n55953c77 267) buf[k] = special[my_random() %\n55953c77 269) buf[arg_len] = '\\0';\n55953c77 271) argv_array_push(&args, buf);\n\nJohannes Schindelin\t14af7ed5 Sync with 2.17.3\nt/helper/test-run-command.c\n14af7ed5 249) argv_array_pushl(&args, \"test-tool\", \"run-command\",\n\nJohannes Schindelin\t379e51d1 quote-stress-test: offer to test quoting arguments for MSYS2 sh\nt/helper/test-run-command.c\n379e51d1 221) int i, j, k, trials = 100, skip = 0, msys2 = 0;\n379e51d1 237) setenv(\"MSYS_NO_PATHCONV\", \"1\", 0);\n379e51d1 245) if (msys2)\n379e51d1 246) argv_array_pushl(&args, \"sh\", \"-c\",\n\nJohannes Schindelin\td2c84dad mingw: refuse to access paths with trailing spaces or periods\nt/helper/test-path-utils.c\nd2c84dad 454) if (argc > 1 && !strcmp(argv[1], \"is_valid_path\")) {\nd2c84dad 455) int res = 0, expect = 1, i;\nd2c84dad 457) for (i = 2; i < argc; i++)\nd2c84dad 458) if (!strcmp(\"--not\", argv[i]))\nd2c84dad 459) expect = 0;\nd2c84dad 460) else if (expect != is_valid_path(argv[i]))\nd2c84dad 464) fprintf(stderr,\nd2c84dad 466) argv[i], expect ? \"\" : \" not\");\nd2c84dad 468) return !!res;\n\nJohannes Schindelin\teea4a7f4 mingw: demonstrate that all file handles are inherited by child processes\nt/helper/test-run-command.c\neea4a7f4 331) static int inherit_handle(const char *argv0)\neea4a7f4 333) struct child_process cp = CHILD_PROCESS_INIT;\neea4a7f4 338) xsnprintf(path, sizeof(path), \"out-XXXXXX\");\neea4a7f4 339) tmp = xmkstemp(path);\neea4a7f4 341) argv_array_pushl(&cp.args,\neea4a7f4 343) cp.in = -1;\neea4a7f4 344) cp.no_stdout = cp.no_stderr = 1;\neea4a7f4 345) if (start_command(&cp) < 0)\neea4a7f4 349) close(tmp);\neea4a7f4 350) if (unlink(path))\neea4a7f4 353) if (close(cp.in) < 0 || finish_command(&cp) < 0)\neea4a7f4 356) return 0;\neea4a7f4 359) static int inherit_handle_child(void)\neea4a7f4 361) struct strbuf buf = STRBUF_INIT;\neea4a7f4 363) if (strbuf_read(&buf, 0, 0) < 0)\neea4a7f4 365) printf(\"Received %s\\n\", buf.buf);\neea4a7f4 366) strbuf_release(&buf);\neea4a7f4 368) return 0;\neea4a7f4 379) exit(inherit_handle(argv[0]));\neea4a7f4 381) exit(inherit_handle_child());\n\nJohannes Schindelin\tcc756edd unpack-trees: let merged_entry() pass through do_add_entry()'s errors\nunpack-trees.c\ncc756edd 2067) return -1;\n\nJohannes Schindelin\t288a74bc is_ntfs_dotgit(): only verify the leading segment\nread-cache.c\n288a74bc 1001) if (is_ntfs_dotgitmodules(path))\n288a74bc 1002) return 0;\n\nJohannes Schindelin\t7530a628 quote-stress-test: allow skipping some trials\nt/helper/test-run-command.c\n7530a628 275) if (i < skip)\n7530a628 276) continue;\n\nJohannes Schindelin\tf37c2264 built-in add -i: prepare for multi-selection commands\nadd-interactive.c\nf37c2264 88) FREE_AND_NULL(list->selected);\nf37c2264 195) static void list(struct add_i_state *s, struct string_list *list, int *selected,\nf37c2264 208) opts->print_item(i, selected ? selected[i] : 0, list->items + i,\nf37c2264 249) int singleton = opts->flags & SINGLETON;\nf37c2264 250) int immediate = opts->flags & IMMEDIATE;\nf37c2264 253) ssize_t res = singleton ? LIST_AND_CHOOSE_ERROR : 0;\nf37c2264 255) if (!singleton) {\nf37c2264 256) free(items->selected);\nf37c2264 257) CALLOC_ARRAY(items->selected, items->items.nr);\nf37c2264 260) if (singleton && !immediate)\nf37c2264 270) list(s, &items->items, items->selected, &opts->list_opts);\nf37c2264 273) fputs(singleton ? \"> \" : \">> \", stdout);\nf37c2264 278) if (immediate)\nf37c2264 279) res = LIST_AND_CHOOSE_QUIT;\nf37c2264 295) int choose = 1;\nf37c2264 297) ssize_t from = -1, to = -1;\nf37c2264 307) if (*p == '-') {\nf37c2264 308) choose = 0;\nf37c2264 309) p++;\nf37c2264 310) sep--;\nf37c2264 313) if (sep == 1 && *p == '*') {\nf37c2264 314) from = 0;\nf37c2264 315) to = items->items.nr;\nf37c2264 316) } else if (isdigit(*p)) {\nf37c2264 327) from = strtoul(p, &endp, 10) - 1;\nf37c2264 328) if (endp == p + sep)\nf37c2264 329) to = from + 1;\nf37c2264 330) else if (*endp == '-') {\nf37c2264 331) to = strtoul(++endp, &endp, 10);\nf37c2264 333) if (endp != p + sep)\nf37c2264 334) from = -1;\nf37c2264 340) if (from < 0) {\nf37c2264 341) from = find_unique(p, items);\nf37c2264 342) if (from >= 0)\nf37c2264 343) to = from + 1;\nf37c2264 346) if (from < 0 || from >= items->items.nr ||\nf37c2264 347)     (singleton && from + 1 != to)) {\nf37c2264 350) break;\nf37c2264 351) } else if (singleton) {\nf37c2264 352) res = from;\nf37c2264 356) if (to > items->items.nr)\nf37c2264 357) to = items->items.nr;\nf37c2264 359) for (; from < to; from++)\nf37c2264 360) if (items->selected[from] != choose) {\nf37c2264 361) items->selected[from] = choose;\nf37c2264 362) res += choose ? +1 : -1;\nf37c2264 368) if ((immediate && res != LIST_AND_CHOOSE_ERROR) ||\nf37c2264 369)     !strcmp(input.buf, \"*\"))\nf37c2264 588) static void print_file_item(int i, int selected, struct string_list_item *item,\nf37c2264 621) printf(\"%c%2d: %s\", selected ? '*' : ' ', i + 1, d->buf.buf);\nf37c2264 1028) static void print_command_item(int i, int selected,\n\nJohannes Schindelin\tbdfef049 Sync with 2.16.6\nfsck.c\nbdfef049 627) if (!S_ISLNK(mode))\nbdfef049 628) oidset_insert(&gitmodules_found, oid);\n\nJohannes Schindelin\tc08171d1 built-in add -i: allow filtering the modified files list\nadd-interactive.c\nc08171d1 447) if (s->skip_unseen)\nc08171d1 448) continue;\nc08171d1 460) adddel = s->mode == FROM_INDEX ?\nc08171d1 487) static int get_modified_files(struct repository *r,\nc08171d1 497) struct collection_status s = { 0 };\nc08171d1 508) for (i = 0; i < 2; i++) {\nc08171d1 512) if (filter == INDEX_ONLY)\nc08171d1 513) s.mode = (i == 0) ? FROM_INDEX : FROM_WORKTREE;\nc08171d1 515) s.mode = (i == 0) ? FROM_WORKTREE : FROM_INDEX;\nc08171d1 516) s.skip_unseen = filter && i;\nc08171d1 531) if (s.mode == FROM_INDEX)\n\nJohannes Schindelin\t8746e072 built-in add -i: implement the `patch` command\nadd-interactive.c\n8746e072 462) other_adddel = s->mode == FROM_INDEX ?\n8746e072 463) &file_item->worktree : &file_item->index;\n8746e072 467) if (stat.files[i]->is_binary) {\n8746e072 468) if (!other_adddel->binary)\n8746e072 469) s->binary_count++;\n8746e072 472) if (stat.files[i]->is_unmerged) {\n8746e072 473) if (!other_adddel->unmerged)\n8746e072 474) s->unmerged_count++;\n8746e072 475) adddel->unmerged = 1;\n8746e072 542) if (unmerged_count)\n8746e072 543) *unmerged_count = s.unmerged_count;\n8746e072 544) if (binary_count)\n8746e072 545) *binary_count = s.binary_count;\n8746e072 628) if (get_modified_files(s->r, NO_FILTER, files, ps, NULL, NULL) < 0)\n8746e072 645) if (get_modified_files(s->r, WORKTREE_ONLY, files, ps, NULL, NULL) < 0)\n8746e072 724) if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0)\n8746e072 876) static int run_patch(struct add_i_state *s, const struct pathspec *ps,\n8746e072 880) int res = 0;\n8746e072 882) size_t unmerged_count = 0, binary_count = 0;\n8746e072 884) if (get_modified_files(s->r, WORKTREE_ONLY, files, ps,\n8746e072 886) return -1;\n8746e072 888) if (unmerged_count || binary_count) {\n8746e072 889) for (i = j = 0; i < files->items.nr; i++) {\n8746e072 890) struct file_item *item = files->items.items[i].util;\n8746e072 892) if (item->index.binary || item->worktree.binary) {\n8746e072 893) free(item);\n8746e072 894) free(files->items.items[i].string);\n8746e072 895) } else if (item->index.unmerged ||\n8746e072 897) color_fprintf_ln(stderr, s->error_color,\n8746e072 899)  files->items.items[i].string);\n8746e072 900) free(item);\n8746e072 901) free(files->items.items[i].string);\n8746e072 903) files->items.items[j++] = files->items.items[i];\n8746e072 905) files->items.nr = j;\n8746e072 908) if (!files->items.nr) {\n8746e072 909) if (binary_count)\n8746e072 910) fprintf(stderr, _(\"Only binary files changed.\\n\"));\n8746e072 912) fprintf(stderr, _(\"No changes.\\n\"));\n8746e072 913) return 0;\n8746e072 916) opts->prompt = N_(\"Patch update\");\n8746e072 917) count = list_and_choose(s, files, opts);\n8746e072 918) if (count >= 0) {\n8746e072 919) struct argv_array args = ARGV_ARRAY_INIT;\n8746e072 921) argv_array_pushl(&args, \"git\", \"add--interactive\", \"--patch\",\n8746e072 923) for (i = 0; i < files->items.nr; i++)\n8746e072 924) if (files->selected[i])\n8746e072 925) argv_array_push(&args,\n8746e072 926) files->items.items[i].string);\n8746e072 927) res = run_command_v_opt(args.argv, 0);\n8746e072 928) argv_array_clear(&args);\n8746e072 931) return res;\n\nJohannes Schindelin\ta8c45be9 built-in add -i: implement the `update` command\nadd-interactive.c\na8c45be9 504) prefix_item_list_clear(files);\na8c45be9 505) s.files = &files->items;\na8c45be9 548) string_list_sort(&files->items);\na8c45be9 593) const char *highlighted = NULL;\na8c45be9 600) if (c->prefix_length > 0 &&\na8c45be9 601)     is_valid_prefix(item->string, c->prefix_length)) {\na8c45be9 602) strbuf_reset(&d->name);\na8c45be9 603) strbuf_addf(&d->name, \"%s%.*s%s%s\", d->color,\na8c45be9 604)     (int)c->prefix_length, item->string, d->reset,\na8c45be9 605)     item->string + c->prefix_length);\na8c45be9 606) highlighted = d->name.buf;\na8c45be9 618) strbuf_addf(&d->buf, d->modified_fmt, d->index.buf, d->worktree.buf,\na8c45be9 631) list(s, &files->items, NULL, &opts->list_opts);\na8c45be9 637) static int run_update(struct add_i_state *s, const struct pathspec *ps,\na8c45be9 641) int res = 0, fd;\na8c45be9 648) if (!files->items.nr) {\na8c45be9 649) putchar('\\n');\na8c45be9 650) return 0;\na8c45be9 653) opts->prompt = N_(\"Update\");\na8c45be9 654) count = list_and_choose(s, files, opts);\na8c45be9 655) if (count <= 0) {\na8c45be9 656) putchar('\\n');\na8c45be9 657) return 0;\na8c45be9 660) fd = repo_hold_locked_index(s->r, &index_lock, LOCK_REPORT_ON_ERROR);\na8c45be9 661) if (fd < 0) {\na8c45be9 662) putchar('\\n');\na8c45be9 663) return -1;\na8c45be9 666) for (i = 0; i < files->items.nr; i++) {\na8c45be9 667) const char *name = files->items.items[i].string;\na8c45be9 668) if (files->selected[i] &&\na8c45be9 669)     add_file_to_index(s->r->index, name, 0) < 0) {\na8c45be9 671) break;\na8c45be9 675) if (!res && write_locked_index(s->r->index, &index_lock, COMMIT_LOCK) < 0)\na8c45be9 678) if (!res)\na8c45be9 679) printf(Q_(\"updated %d path\\n\",\na8c45be9 682) putchar('\\n');\na8c45be9 683) return res;\na8c45be9 995) static void choose_prompt_help(struct add_i_state *s)\na8c45be9 997) color_fprintf_ln(stdout, s->help_color, \"%s\",\na8c45be9 999) color_fprintf_ln(stdout, s->help_color, \"1          - %s\",\na8c45be9 1001) color_fprintf_ln(stdout, s->help_color, \"3-5        - %s\",\na8c45be9 1003) color_fprintf_ln(stdout, s->help_color, \"2-3,6-9    - %s\",\na8c45be9 1005) color_fprintf_ln(stdout, s->help_color, \"foo        - %s\",\na8c45be9 1007) color_fprintf_ln(stdout, s->help_color, \"-...       - %s\",\na8c45be9 1009) color_fprintf_ln(stdout, s->help_color, \"*          - %s\",\na8c45be9 1011) color_fprintf_ln(stdout, s->help_color, \"           - %s\",\na8c45be9 1013) }\na8c45be9 1083) struct list_and_choose_options opts = {\na8c45be9 1088) struct prefix_item_list files = PREFIX_ITEM_LIST_INIT;\na8c45be9 1109) print_file_item_data.color = data.color;\na8c45be9 1110) print_file_item_data.reset = data.reset;\na8c45be9 1115) opts.list_opts.header = header.buf;\na8c45be9 1144) prefix_item_list_clear(&files);\na8c45be9 1146) strbuf_release(&print_file_item_data.name);\n\nJohannes Schindelin\t0c3944a6 add-interactive: make sure to release `rev.prune_data`\nadd-interactive.c\n0c3944a6 538) if (ps)\n0c3944a6 539) clear_pathspec(&rev.prune_data);\n\nJohannes Schindelin\tab1e1ccc built-in add -i: re-implement `add-untracked` in C\nadd-interactive.c\nab1e1ccc 609) if (d->only_names) {\nab1e1ccc 610) printf(\"%c%2d: %s\", selected ? '*' : ' ', i + 1,\nab1e1ccc 612) return;\nab1e1ccc 794) static int get_untracked_files(struct repository *r,\nab1e1ccc 798) struct dir_struct dir = { 0 };\nab1e1ccc 800) struct strbuf buf = STRBUF_INIT;\nab1e1ccc 802) if (repo_read_index(r) < 0)\nab1e1ccc 805) prefix_item_list_clear(files);\nab1e1ccc 806) setup_standard_excludes(&dir);\nab1e1ccc 807) add_pattern_list(&dir, EXC_CMDL, \"--exclude option\");\nab1e1ccc 808) fill_directory(&dir, r->index, ps);\nab1e1ccc 810) for (i = 0; i < dir.nr; i++) {\nab1e1ccc 811) struct dir_entry *ent = dir.entries[i];\nab1e1ccc 813) if (index_name_is_other(r->index, ent->name, ent->len)) {\nab1e1ccc 814) strbuf_reset(&buf);\nab1e1ccc 815) strbuf_add(&buf, ent->name, ent->len);\nab1e1ccc 816) add_file_item(&files->items, buf.buf);\nab1e1ccc 820) strbuf_release(&buf);\nab1e1ccc 824) static int run_add_untracked(struct add_i_state *s, const struct pathspec *ps,\nab1e1ccc 828) struct print_file_item_data *d = opts->list_opts.print_item_data;\nab1e1ccc 829) int res = 0, fd;\nab1e1ccc 833) if (get_untracked_files(s->r, files, ps) < 0)\nab1e1ccc 834) return -1;\nab1e1ccc 836) if (!files->items.nr) {\nab1e1ccc 837) printf(_(\"No untracked files.\\n\"));\nab1e1ccc 838) goto finish_add_untracked;\nab1e1ccc 841) opts->prompt = N_(\"Add untracked\");\nab1e1ccc 842) d->only_names = 1;\nab1e1ccc 843) count = list_and_choose(s, files, opts);\nab1e1ccc 844) d->only_names = 0;\nab1e1ccc 845) if (count <= 0)\nab1e1ccc 846) goto finish_add_untracked;\nab1e1ccc 848) fd = repo_hold_locked_index(s->r, &index_lock, LOCK_REPORT_ON_ERROR);\nab1e1ccc 849) if (fd < 0) {\nab1e1ccc 850) res = -1;\nab1e1ccc 851) goto finish_add_untracked;\nab1e1ccc 854) for (i = 0; i < files->items.nr; i++) {\nab1e1ccc 855) const char *name = files->items.items[i].string;\nab1e1ccc 856) if (files->selected[i] &&\nab1e1ccc 857)     add_file_to_index(s->r->index, name, 0) < 0) {\nab1e1ccc 859) break;\nab1e1ccc 863) if (!res &&\nab1e1ccc 864)     write_locked_index(s->r->index, &index_lock, COMMIT_LOCK) < 0)\nab1e1ccc 867) if (!res)\nab1e1ccc 868) printf(Q_(\"added %d path\\n\",\nab1e1ccc 872) putchar('\\n');\nab1e1ccc 873) return res;\n\nJohannes Schindelin\tc54ef5e4 built-in add -i: re-implement `revert` in C\nadd-interactive.c\nc54ef5e4 686) static void revert_from_diff(struct diff_queue_struct *q,\nc54ef5e4 689) int i, add_flags = ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE;\nc54ef5e4 691) for (i = 0; i < q->nr; i++) {\nc54ef5e4 692) struct diff_filespec *one = q->queue[i]->one;\nc54ef5e4 695) if (!(one->mode && !is_null_oid(&one->oid))) {\nc54ef5e4 696) remove_file_from_index(opt->repo->index, one->path);\nc54ef5e4 697) printf(_(\"note: %s is untracked now.\\n\"), one->path);\nc54ef5e4 699) ce = make_cache_entry(opt->repo->index, one->mode,\nc54ef5e4 700)       &one->oid, one->path, 0, 0);\nc54ef5e4 701) if (!ce)\nc54ef5e4 704) add_index_entry(opt->repo->index, ce, add_flags);\nc54ef5e4 707) }\nc54ef5e4 709) static int run_revert(struct add_i_state *s, const struct pathspec *ps,\nc54ef5e4 713) int res = 0, fd;\nc54ef5e4 717) int is_initial = !resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &oid,\nc54ef5e4 722) struct diff_options diffopt = { NULL };\nc54ef5e4 725) return -1;\nc54ef5e4 727) if (!files->items.nr) {\nc54ef5e4 728) putchar('\\n');\nc54ef5e4 729) return 0;\nc54ef5e4 732) opts->prompt = N_(\"Revert\");\nc54ef5e4 733) count = list_and_choose(s, files, opts);\nc54ef5e4 734) if (count <= 0)\nc54ef5e4 735) goto finish_revert;\nc54ef5e4 737) fd = repo_hold_locked_index(s->r, &index_lock, LOCK_REPORT_ON_ERROR);\nc54ef5e4 738) if (fd < 0) {\nc54ef5e4 739) res = -1;\nc54ef5e4 740) goto finish_revert;\nc54ef5e4 743) if (is_initial)\nc54ef5e4 744) oidcpy(&oid, s->r->hash_algo->empty_tree);\nc54ef5e4 746) tree = parse_tree_indirect(&oid);\nc54ef5e4 747) if (!tree) {\nc54ef5e4 749) goto finish_revert;\nc54ef5e4 751) oidcpy(&oid, &tree->object.oid);\nc54ef5e4 754) ALLOC_ARRAY(paths, count + 1);\nc54ef5e4 755) for (i = j = 0; i < files->items.nr; i++)\nc54ef5e4 756) if (files->selected[i])\nc54ef5e4 757) paths[j++] = files->items.items[i].string;\nc54ef5e4 758) paths[j] = NULL;\nc54ef5e4 760) parse_pathspec(&diffopt.pathspec, 0,\nc54ef5e4 764) diffopt.output_format = DIFF_FORMAT_CALLBACK;\nc54ef5e4 765) diffopt.format_callback = revert_from_diff;\nc54ef5e4 766) diffopt.flags.override_submodule_config = 1;\nc54ef5e4 767) diffopt.repo = s->r;\nc54ef5e4 769) if (do_diff_cache(&oid, &diffopt))\nc54ef5e4 770) res = -1;\nc54ef5e4 772) diffcore_std(&diffopt);\nc54ef5e4 773) diff_flush(&diffopt);\nc54ef5e4 775) free(paths);\nc54ef5e4 776) clear_pathspec(&diffopt.pathspec);\nc54ef5e4 778) if (!res && write_locked_index(s->r->index, &index_lock,\nc54ef5e4 780) res = -1;\nc54ef5e4 782) res = repo_refresh_and_write_index(s->r, REFRESH_QUIET, 0, 1,\nc54ef5e4 785) if (!res)\nc54ef5e4 786) printf(Q_(\"reverted %d path\\n\",\nc54ef5e4 791) return res;\n\nJohannes Schindelin\td7633578 built-in add -i: re-implement the `diff` command\nadd-interactive.c\nd7633578 934) static int run_diff(struct add_i_state *s, const struct pathspec *ps,\nd7633578 938) int res = 0;\nd7633578 942) int is_initial = !resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &oid,\nd7633578 944) if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0)\nd7633578 945) return -1;\nd7633578 947) if (!files->items.nr) {\nd7633578 948) putchar('\\n');\nd7633578 949) return 0;\nd7633578 952) opts->prompt = N_(\"Review diff\");\nd7633578 953) opts->flags = IMMEDIATE;\nd7633578 954) count = list_and_choose(s, files, opts);\nd7633578 955) opts->flags = 0;\nd7633578 956) if (count >= 0) {\nd7633578 957) struct argv_array args = ARGV_ARRAY_INIT;\nd7633578 959) argv_array_pushl(&args, \"git\", \"diff\", \"-p\", \"--cached\",\nd7633578 961)     s->r->hash_algo->empty_tree),\nd7633578 963) for (i = 0; i < files->items.nr; i++)\nd7633578 964) if (files->selected[i])\nd7633578 965) argv_array_push(&args,\nd7633578 966) files->items.items[i].string);\nd7633578 967) res = run_command_v_opt(args.argv, 0);\nd7633578 968) argv_array_clear(&args);\nd7633578 971) putchar('\\n');\nd7633578 972) return res;\n\nJohannes Schindelin\tb4bbbbd5 apply --allow-overlap: fix a corner case\napply.c\nb4bbbbd5 2672) match_beginning = 0;\n\nJohannes Schindelin\t2e697ced built-in add -i: offer the `quit` command\nadd-interactive.c\n2e697ced 1129) if (i < 0 || i >= commands.items.nr)\n2e697ced 1130) util = NULL;\n2e697ced 1132) util = commands.items.items[i].util;\n2e697ced 1134) if (i == LIST_AND_CHOOSE_QUIT || (util && !util->command)) {\n2e697ced 1140) if (util)\n\nJonathan Nieder\tc1547450 submodule: defend against submodule.update = !command in .gitmodules\nbuiltin/submodule--helper.c\nc1547450 1501) if (sub->update_strategy.type == SM_UPDATE_COMMAND)\n\nJunio C Hamano\t7034cd09 Sync with Git 2.24.1\nfsck.c\n7034cd09 630) retval += report(options, oid, OBJ_TREE,\n\nRené Scharfe\t0bb313a5 xdiff: unignore changes in function context\nxdiff/xemit.c\n0bb313a5 223)        xchp->i1 + xchp->chg1 <= s1 &&\n0bb313a5 224)        xchp->i2 + xchp->chg2 <= s2)\n0bb313a5 225) xchp = xchp->next;\n\nRohit Ashiwal\t08187b4c rebase -i: support --ignore-date\nsequencer.c\n08187b4c 903) return NULL;\n08187b4c 920) argv_array_pushf(&child->env_array, \"GIT_COMMITTER_DATE=%s\", date.buf);\n08187b4c 1508) res = -1;\n08187b4c 1509) goto out;\n08187b4c 2608) opts->allow_ff = 0;\n08187b4c 2609) opts->ignore_date = 1;\n08187b4c 3639) push_dates(&cmd, opts->committer_date_is_author_date);\n\nRohit Ashiwal\tcbd8db17 rebase -i: support --committer-date-is-author-date\nsequencer.c\ncbd8db17 890) return NULL;\ncbd8db17 989) return -1;\ncbd8db17 1428) goto out;\ncbd8db17 1432) goto out;\ncbd8db17 2603) opts->allow_ff = 0;\ncbd8db17 2604) opts->committer_date_is_author_date = 1;\n\nRohit Ashiwal\tc068bcc5 sequencer: allow callers of read_author_script() to ignore fields\nsequencer.c\nc068bcc5 840) free(kv.items[date_i].util);\n\n\n"}]}