Skip to content

Commit 5708809

Browse files
devdekunlegitster
authored andcommitted
add-patch: modify patch_update_file() signature
The function `patch_update_file()` takes the add_p_state struct pointer and the current `struct file_diff` pointer and returns an int. When using the `--no-auto-advance` flag, we want to be able to request the next or previous file from the caller. Modify the function signature to instead take the index of the current `file_diff` and the `add_p_state` struct pointer so that we can compute the `file_diff` from the index while also having access to the file index. This will help us request the next or previous file from the caller. Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 06c81a1 commit 5708809

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

add-patch.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,20 +1441,21 @@ static bool get_first_undecided(const struct file_diff *file_diff, size_t *idx)
14411441
return false;
14421442
}
14431443

1444-
static int patch_update_file(struct add_p_state *s,
1445-
struct file_diff *file_diff)
1444+
static size_t patch_update_file(struct add_p_state *s, size_t idx)
14461445
{
14471446
size_t hunk_index = 0;
14481447
ssize_t i, undecided_previous, undecided_next, rendered_hunk_index = -1;
14491448
struct hunk *hunk;
14501449
char ch;
14511450
struct child_process cp = CHILD_PROCESS_INIT;
1452-
int colored = !!s->colored.len, quit = 0, use_pager = 0;
1451+
int colored = !!s->colored.len, use_pager = 0;
14531452
enum prompt_mode_type prompt_mode_type;
1453+
struct file_diff *file_diff = s->file_diff + idx;
1454+
size_t patch_update_resp = idx;
14541455

14551456
/* Empty added files have no hunks */
14561457
if (!file_diff->hunk_nr && !file_diff->added)
1457-
return 0;
1458+
return patch_update_resp + 1;
14581459

14591460
strbuf_reset(&s->buf);
14601461
render_diff_header(s, file_diff, colored, &s->buf);
@@ -1498,9 +1499,10 @@ static int patch_update_file(struct add_p_state *s,
14981499

14991500
/* Everything decided? */
15001501
if (undecided_previous < 0 && undecided_next < 0 &&
1501-
hunk->use != UNDECIDED_HUNK)
1502-
break;
1503-
1502+
hunk->use != UNDECIDED_HUNK) {
1503+
patch_update_resp++;
1504+
break;
1505+
}
15041506
strbuf_reset(&s->buf);
15051507
if (file_diff->hunk_nr) {
15061508
if (rendered_hunk_index != hunk_index) {
@@ -1570,7 +1572,7 @@ static int patch_update_file(struct add_p_state *s,
15701572
fputs(s->s.reset_color_interactive, stdout);
15711573
fflush(stdout);
15721574
if (read_single_character(s) == EOF) {
1573-
quit = 1;
1575+
patch_update_resp = s->file_diff_nr;
15741576
break;
15751577
}
15761578

@@ -1616,7 +1618,7 @@ static int patch_update_file(struct add_p_state *s,
16161618
hunk->use = SKIP_HUNK;
16171619
}
16181620
} else if (ch == 'q') {
1619-
quit = 1;
1621+
patch_update_resp = s->file_diff_nr;
16201622
break;
16211623
} else if (s->answer.buf[0] == 'K') {
16221624
if (permitted & ALLOW_GOTO_PREVIOUS_HUNK)
@@ -1803,7 +1805,7 @@ static int patch_update_file(struct add_p_state *s,
18031805
}
18041806

18051807
putchar('\n');
1806-
return quit;
1808+
return patch_update_resp;
18071809
}
18081810

18091811
int run_add_p(struct repository *r, enum add_p_mode mode,
@@ -1852,11 +1854,15 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
18521854
return -1;
18531855
}
18541856

1855-
for (i = 0; i < s.file_diff_nr; i++)
1856-
if (s.file_diff[i].binary && !s.file_diff[i].hunk_nr)
1857+
for (i = 0; i < s.file_diff_nr;) {
1858+
if (s.file_diff[i].binary && !s.file_diff[i].hunk_nr) {
18571859
binary_count++;
1858-
else if (patch_update_file(&s, s.file_diff + i))
1860+
i++;
1861+
continue;
1862+
}
1863+
if ((i = patch_update_file(&s, i)) == s.file_diff_nr)
18591864
break;
1865+
}
18601866

18611867
if (s.file_diff_nr == 0)
18621868
err(&s, _("No changes."));

0 commit comments

Comments
 (0)