mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'pw/add-p-hunk-splitting-fix'
Marking a hunk 'selected' in "git add -p" and then splitting made all the split pieces 'selected'; this has been changed to make them all 'undecided', which gives better end-user experience. * pw/add-p-hunk-splitting-fix: add-patch: update hunk splitability after editing add -p: mark split hunks as undecided
This commit is contained in:
15
add-patch.c
15
add-patch.c
@@ -956,6 +956,7 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
|
||||
* sizeof(*hunk));
|
||||
hunk = file_diff->hunk + hunk_index;
|
||||
hunk->splittable_into = 1;
|
||||
hunk->use = UNDECIDED_HUNK;
|
||||
memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk));
|
||||
|
||||
header = &hunk->header;
|
||||
@@ -1057,7 +1058,7 @@ next_hunk_line:
|
||||
|
||||
hunk++;
|
||||
hunk->splittable_into = 1;
|
||||
hunk->use = hunk[-1].use;
|
||||
hunk->use = UNDECIDED_HUNK;
|
||||
header = &hunk->header;
|
||||
|
||||
header->old_count = header->new_count = context_line_count;
|
||||
@@ -1184,19 +1185,29 @@ static ssize_t recount_edited_hunk(struct add_p_state *s, struct hunk *hunk,
|
||||
{
|
||||
struct hunk_header *header = &hunk->header;
|
||||
size_t i;
|
||||
char ch, marker = ' ';
|
||||
|
||||
hunk->splittable_into = 0;
|
||||
header->old_count = header->new_count = 0;
|
||||
for (i = hunk->start; i < hunk->end; ) {
|
||||
switch(normalize_marker(&s->plain.buf[i])) {
|
||||
ch = normalize_marker(&s->plain.buf[i]);
|
||||
switch (ch) {
|
||||
case '-':
|
||||
header->old_count++;
|
||||
if (marker == ' ')
|
||||
hunk->splittable_into++;
|
||||
marker = ch;
|
||||
break;
|
||||
case '+':
|
||||
header->new_count++;
|
||||
if (marker == ' ')
|
||||
hunk->splittable_into++;
|
||||
marker = ch;
|
||||
break;
|
||||
case ' ':
|
||||
header->old_count++;
|
||||
header->new_count++;
|
||||
marker = ch;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user