Skip to content

Commit d2eb809

Browse files
peffgitster
authored andcommitted
range-diff: use a hunk callback
When we count the lines in a diff, we don't actually care about the contents of each line. By using a hunk callback, we tell xdiff that it does not need to even bother generating a hunk header line, saving a small amount of work. Arguably we could even ignore the hunk headers completely, since we're just computing a cost function between patches. But doing it this way maintains the exact same behavior before and after. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75ab763 commit d2eb809

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

range-diff.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ static void diffsize_consume(void *data, char *line, unsigned long len)
177177
(*(int *)data)++;
178178
}
179179

180+
static void diffsize_hunk(void *data, long ob, long on, long nb, long nn,
181+
const char *funcline, long funclen)
182+
{
183+
diffsize_consume(data, NULL, 0);
184+
}
185+
180186
static int diffsize(const char *a, const char *b)
181187
{
182188
xpparam_t pp = { 0 };
@@ -190,7 +196,9 @@ static int diffsize(const char *a, const char *b)
190196
mf2.size = strlen(b);
191197

192198
cfg.ctxlen = 3;
193-
if (!xdi_diff_outf(&mf1, &mf2, NULL, diffsize_consume, &count, &pp, &cfg))
199+
if (!xdi_diff_outf(&mf1, &mf2,
200+
diffsize_hunk, diffsize_consume, &count,
201+
&pp, &cfg))
194202
return count;
195203

196204
error(_("failed to generate diff"));

0 commit comments

Comments
 (0)