summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-02 06:39:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-05 04:14:35 (GMT)
commitd2eb80935a4e93cd775b5e8dc3f07fa1cd21d330 (patch)
tree1b0e3d7c9a93107e978c3a7a2eacfed8316612b5 /range-diff.c
parent75ab76306cb97b223b29e9460a9589cfd099213e (diff)
downloadgit-d2eb80935a4e93cd775b5e8dc3f07fa1cd21d330.zip
git-d2eb80935a4e93cd775b5e8dc3f07fa1cd21d330.tar.gz
git-d2eb80935a4e93cd775b5e8dc3f07fa1cd21d330.tar.bz2
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/range-diff.c b/range-diff.c
index 0f4ce14..2ef372b 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -177,6 +177,12 @@ static void diffsize_consume(void *data, char *line, unsigned long len)
(*(int *)data)++;
}
+static void diffsize_hunk(void *data, long ob, long on, long nb, long nn,
+ const char *funcline, long funclen)
+{
+ diffsize_consume(data, NULL, 0);
+}
+
static int diffsize(const char *a, const char *b)
{
xpparam_t pp = { 0 };
@@ -190,7 +196,9 @@ static int diffsize(const char *a, const char *b)
mf2.size = strlen(b);
cfg.ctxlen = 3;
- if (!xdi_diff_outf(&mf1, &mf2, NULL, diffsize_consume, &count, &pp, &cfg))
+ if (!xdi_diff_outf(&mf1, &mf2,
+ diffsize_hunk, diffsize_consume, &count,
+ &pp, &cfg))
return count;
error(_("failed to generate diff"));