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

Function patch_update_file

add-patch.c:1607–2006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1605}
1606
1607static size_t patch_update_file(struct add_p_state *s,
1608 size_t idx,
1609 unsigned flags)
1610{
1611 size_t hunk_index = 0;
1612 ssize_t i, undecided_previous, undecided_next, rendered_hunk_index = -1;
1613 struct hunk *hunk;
1614 char ch;
1615 int colored = !!s->colored.len, use_pager = 0;
1616 enum prompt_mode_type prompt_mode_type;
1617 int all_decided = 0;
1618 struct file_diff *file_diff = s->file_diff + idx;
1619 size_t patch_update_resp = idx;
1620
1621 /* Empty added files have no hunks */
1622 if (!file_diff->hunk_nr && !file_diff->added)
1623 return patch_update_resp + 1;
1624
1625 strbuf_reset(&s->buf);
1626 render_diff_header(s, file_diff, colored, &s->buf);
1627 fputs(s->buf.buf, stdout);
1628 for (;;) {
1629 const char *hunk_use_decision = "";
1630 enum {
1631 ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0,
1632 ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK = 1 << 1,
1633 ALLOW_GOTO_NEXT_HUNK = 1 << 2,
1634 ALLOW_GOTO_NEXT_UNDECIDED_HUNK = 1 << 3,
1635 ALLOW_SEARCH_AND_GOTO = 1 << 4,
1636 ALLOW_SPLIT = 1 << 5,
1637 ALLOW_EDIT = 1 << 6,
1638 ALLOW_GOTO_PREVIOUS_FILE = 1 << 7,
1639 ALLOW_GOTO_NEXT_FILE = 1 << 8
1640 } permitted = 0;
1641
1642 if (hunk_index >= file_diff->hunk_nr)
1643 hunk_index = 0;
1644 hunk = file_diff->hunk_nr
1645 ? file_diff->hunk + hunk_index
1646 : &file_diff->head;
1647 undecided_previous = -1;
1648 undecided_next = -1;
1649
1650 if (file_diff->hunk_nr) {
1651 for (i = dec_mod(hunk_index, file_diff->hunk_nr);
1652 i != hunk_index;
1653 i = dec_mod(i, file_diff->hunk_nr))
1654 if (file_diff->hunk[i].use == UNDECIDED_HUNK) {
1655 undecided_previous = i;
1656 break;
1657 }
1658
1659 for (i = inc_mod(hunk_index, file_diff->hunk_nr);
1660 i != hunk_index;
1661 i = inc_mod(i, file_diff->hunk_nr))
1662 if (file_diff->hunk[i].use == UNDECIDED_HUNK) {
1663 undecided_next = i;
1664 break;

Callers 1

run_add_p_commonFunction · 0.85

Calls 15

render_diff_headerFunction · 0.85
dec_modFunction · 0.85
inc_modFunction · 0.85
setup_pagerFunction · 0.85
sigchain_pushFunction · 0.85
render_hunkFunction · 0.85
sigchain_popFunction · 0.85
wait_for_pagerFunction · 0.85
strbuf_addstrFunction · 0.85
read_single_characterFunction · 0.85
errFunction · 0.85
get_first_undecidedFunction · 0.85

Tested by

no test coverage detected