Skip to content

Commit 60cf761

Browse files
phillipwoodgitster
authored andcommitted
add-patch: use normalize_marker() when recounting edited hunk
After the user has edited a hunk the number of lines in the pre- and post- image lines is recounted the hunk header can be updated before passing the hunk to "git apply". The recounting code correctly handles empty context lines where the leading ' ' is omitted by treating '\n' and '\r' as context lines. Update this code to use normalize_marker() so that the handling of empty context lines is consistent with the rest of the hunk parsing code. There is a small change in behavior as normalize_marker() only treats "\r\n" as an empty context line rather than any line starting with '\r'. This should not matter in practice as Macs have used Unix line endings since MacOs 10 was released in 2001 and if it transpires that someone is still using an earlier version of MacOs where lines end with '\r' then we will need to change the handling of '\r' in normalize_marker() anyway. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39bdd84 commit 60cf761

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

add-patch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,14 +1178,14 @@ static ssize_t recount_edited_hunk(struct add_p_state *s, struct hunk *hunk,
11781178

11791179
header->old_count = header->new_count = 0;
11801180
for (i = hunk->start; i < hunk->end; ) {
1181-
switch (s->plain.buf[i]) {
1181+
switch(normalize_marker(&s->plain.buf[i])) {
11821182
case '-':
11831183
header->old_count++;
11841184
break;
11851185
case '+':
11861186
header->new_count++;
11871187
break;
1188-
case ' ': case '\r': case '\n':
1188+
case ' ':
11891189
header->old_count++;
11901190
header->new_count++;
11911191
break;

0 commit comments

Comments
 (0)