Git fork

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

+44 -2
+13 -2
add-patch.c
··· 956 956 * sizeof(*hunk)); 957 957 hunk = file_diff->hunk + hunk_index; 958 958 hunk->splittable_into = 1; 959 + hunk->use = UNDECIDED_HUNK; 959 960 memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk)); 960 961 961 962 header = &hunk->header; ··· 1057 1058 1058 1059 hunk++; 1059 1060 hunk->splittable_into = 1; 1060 - hunk->use = hunk[-1].use; 1061 + hunk->use = UNDECIDED_HUNK; 1061 1062 header = &hunk->header; 1062 1063 1063 1064 header->old_count = header->new_count = context_line_count; ··· 1184 1185 { 1185 1186 struct hunk_header *header = &hunk->header; 1186 1187 size_t i; 1188 + char ch, marker = ' '; 1187 1189 1190 + hunk->splittable_into = 0; 1188 1191 header->old_count = header->new_count = 0; 1189 1192 for (i = hunk->start; i < hunk->end; ) { 1190 - switch(normalize_marker(&s->plain.buf[i])) { 1193 + ch = normalize_marker(&s->plain.buf[i]); 1194 + switch (ch) { 1191 1195 case '-': 1192 1196 header->old_count++; 1197 + if (marker == ' ') 1198 + hunk->splittable_into++; 1199 + marker = ch; 1193 1200 break; 1194 1201 case '+': 1195 1202 header->new_count++; 1203 + if (marker == ' ') 1204 + hunk->splittable_into++; 1205 + marker = ch; 1196 1206 break; 1197 1207 case ' ': 1198 1208 header->old_count++; 1199 1209 header->new_count++; 1210 + marker = ch; 1200 1211 break; 1201 1212 } 1202 1213
+31
t/t3701-add-interactive.sh
··· 1354 1354 ' 1355 1355 done 1356 1356 1357 + test_expect_success 'splitting previous hunk marks split hunks as undecided' ' 1358 + test_write_lines a " " b c d e f g h i j k >file && 1359 + git add file && 1360 + test_write_lines x " " b y d e f g h i j x >file && 1361 + test_write_lines n K s n y q | git add -p file && 1362 + git cat-file blob :file >actual && 1363 + test_write_lines a " " b y d e f g h i j k >expect && 1364 + test_cmp expect actual 1365 + ' 1366 + 1367 + test_expect_success 'splitting edited hunk' ' 1368 + # Before the first hunk is edited it can be split into two 1369 + # hunks, after editing it can be split into three hunks. 1370 + 1371 + write_script fake-editor.sh <<-\EOF && 1372 + sed "s/^ c/-c/" "$1" >"$1.tmp" && 1373 + mv "$1.tmp" "$1" 1374 + EOF 1375 + 1376 + test_write_lines a b c d e f g h i j k l m n >file && 1377 + git add file && 1378 + test_write_lines A b c d E f g h i j k l M n >file && 1379 + ( 1380 + test_set_editor "$(pwd)/fake-editor.sh" && 1381 + test_write_lines e K s j y n y q | git add -p file 1382 + ) && 1383 + git cat-file blob :file >actual && 1384 + test_write_lines a b d e f g h i j k l M n >expect && 1385 + test_cmp expect actual 1386 + ' 1387 + 1357 1388 test_done