Skip to content

Commit e1db263

Browse files
tgummerergitster
authored andcommitted
range-diff: don't remove funcname from inner diff
When postprocessing the inner diff in range-diff, we currently replace the whole hunk header line with just "@@". This matches how 'git tbdiff' used to handle hunk headers as well. Most likely this is being done because line numbers in the hunk header are not relevant without other changes. They can for example easily change if a range is rebased, and lines are added/removed before a change that we actually care about in our ranges. However it can still be useful to have the function name that 'git diff' extracts as additional context for the change. Note that it is not guaranteed that the hunk header actually shows up in the range-diff, and this change only aims to improve the case where a hunk header would already be included in the final output. Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44b67cb commit e1db263

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

range-diff.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ static int read_patches(const char *range, struct string_list *list)
119119
strbuf_addch(&buf, '\n');
120120
}
121121
continue;
122-
} else if (starts_with(line, "@@ "))
123-
strbuf_addstr(&buf, "@@");
124-
else if (!line[0] || starts_with(line, "index "))
122+
} else if (skip_prefix(line, "@@ ", &p)) {
123+
p = strstr(p, "@@");
124+
strbuf_addstr(&buf, p ? p : "@@");
125+
} else if (!line[0] || starts_with(line, "index "))
125126
/*
126127
* A completely blank (not ' \n', which is context)
127128
* line is not valid in a diff. We skip it

t/t3206-range-diff.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ test_expect_success 'changed commit' '
110110
14
111111
4: a63e992 ! 4: d966c5c s/12/B/
112112
@@ -8,7 +8,7 @@
113-
@@
113+
@@ A
114114
9
115115
10
116116
- B
@@ -169,7 +169,7 @@ test_expect_success 'changed commit with sm config' '
169169
14
170170
4: a63e992 ! 4: d966c5c s/12/B/
171171
@@ -8,7 +8,7 @@
172-
@@
172+
@@ A
173173
9
174174
10
175175
- B
@@ -231,7 +231,7 @@ test_expect_success 'dual-coloring' '
231231
: 14<RESET>
232232
:<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
233233
: <REVERSE><CYAN>@@ -8,7 +8,7 @@<RESET>
234-
: <CYAN> @@<RESET>
234+
: <CYAN> @@ A<RESET>
235235
: 9<RESET>
236236
: 10<RESET>
237237
: <REVERSE><RED>-<RESET><FAINT> BB<RESET>

0 commit comments

Comments
 (0)