Skip to content

Commit bcdd297

Browse files
dschogitster
authored andcommitted
built-in add -p: implement hunk editing
Just like `git add --edit` allows the user to edit the diff before it is being applied to the index, this feature allows the user to edit the diff *hunk*. Naturally, it gets a bit more complicated here because the result has to play well with the remaining hunks of the overall diff. Therefore, we have to do a loop in which we let the user edit the hunk, then test whether the result would work, and if not, drop the edits and let the user decide whether to try editing the hunk again. Note: in contrast to the Perl version, we use the same diff "coalescing" (i.e. merging overlapping hunks into a single one) also for the check after editing, and we introduce a new flag for that purpose that asks the `reassemble_patch()` function to pretend that all hunks were selected for use. This allows us to continue to run `git apply` *without* the `--allow-overlap` option (unlike the Perl version), and it also fixes two known breakages in `t3701-add-interactive.sh` (which we cannot mark as resolved so far because the Perl script version is still the default and continues to have those breakages). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b38dd9e commit bcdd297

File tree

3 files changed

+325
-17
lines changed

3 files changed

+325
-17
lines changed

add-interactive.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
4646
init_color(r, s, "reset", s->reset_color, GIT_COLOR_RESET);
4747
init_color(r, s, "fraginfo", s->fraginfo_color,
4848
diff_get_color(s->use_color, DIFF_FRAGINFO));
49+
init_color(r, s, "context", s->context_color,
50+
diff_get_color(s->use_color, DIFF_CONTEXT));
51+
init_color(r, s, "old", s->file_old_color,
52+
diff_get_color(s->use_color, DIFF_FILE_OLD));
53+
init_color(r, s, "new", s->file_new_color,
54+
diff_get_color(s->use_color, DIFF_FILE_NEW));
4955
}
5056

5157
/*

add-interactive.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ struct add_i_state {
1212
char error_color[COLOR_MAXLEN];
1313
char reset_color[COLOR_MAXLEN];
1414
char fraginfo_color[COLOR_MAXLEN];
15+
char context_color[COLOR_MAXLEN];
16+
char file_old_color[COLOR_MAXLEN];
17+
char file_new_color[COLOR_MAXLEN];
1518
};
1619

1720
void init_add_i_state(struct add_i_state *s, struct repository *r);

0 commit comments

Comments
 (0)