Skip to content

Commit 5e3bd5a

Browse files
committed
fixup??? built-in add -i: start implementing the patch functionality in C
Needed by `tg/stash-refresh-index`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f1111dc commit 5e3bd5a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

add-patch.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,7 @@ static int patch_update_file(struct add_p_state *s,
15451545
strbuf_reset(&s->buf);
15461546
reassemble_patch(s, file_diff, 0, &s->buf);
15471547

1548+
discard_index(s->s.r->index);
15481549
if (s->mode->apply_for_checkout)
15491550
apply_for_checkout(s, &s->buf,
15501551
s->mode->is_reverse);
@@ -1555,11 +1556,9 @@ static int patch_update_file(struct add_p_state *s,
15551556
NULL, 0, NULL, 0))
15561557
error(_("'git apply' failed"));
15571558
}
1558-
if (discard_index(s->s.r->index) < 0 ||
1559-
repo_read_index_preload(s->s.r, NULL, 0) < 0)
1560-
return error(_("could not read index"));
1561-
repo_refresh_and_write_index(s->s.r, REFRESH_QUIET, 0, 1,
1562-
NULL, NULL, NULL);
1559+
if (!repo_read_index(s->s.r))
1560+
repo_refresh_and_write_index(s->s.r, REFRESH_QUIET, 0,
1561+
1, NULL, NULL, NULL);
15631562
}
15641563

15651564
putchar('\n');
@@ -1602,9 +1601,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
16021601
s.mode = &patch_mode_stage;
16031602
s.revision = revision;
16041603

1605-
if (repo_read_index_preload(r, NULL, 0) < 0)
1606-
return error(_("could not read index"));
1607-
if (repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
1604+
if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||
1605+
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
16081606
NULL, NULL, NULL) < 0 ||
16091607
parse_diff(&s, ps) < 0) {
16101608
strbuf_release(&s.plain);

0 commit comments

Comments
 (0)