From acb725772964ee11656543a28c303e9aa6d092c5 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 28 Mar 2006 03:23:31 +0100 Subject: xdiff: Show function names in hunk headers. The speed of the built-in diff generator is nice; but the function names shown by `diff -p' are /really/ nice. And I hate having to choose. So, we hack xdiff to find the function names and print them. xdiff has grown a flag to say whether to dig up the function names. The builtin_diff function passes this flag unconditionally. I suppose it could parse GIT_DIFF_OPTS, but it doesn't at the moment. I've also reintroduced the `function name' into the test suite, from which it was removed in commit 3ce8f089. The function names are parsed by a particularly stupid algorithm at the moment: it just tries to find a line in the `old' file, from before the start of the hunk, whose first character looks plausible. Still, it's most definitely a start. Signed-off-by: Mark Wooding Signed-off-by: Junio C Hamano --- xdiff/xutils.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'xdiff/xutils.c') diff --git a/xdiff/xutils.c b/xdiff/xutils.c index 8221806f78..afaada1edf 100644 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@ -235,7 +235,8 @@ long xdl_atol(char const *str, char const **next) { } -int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, xdemitcb_t *ecb) { +int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, + const char *func, long funclen, xdemitcb_t *ecb) { int nb = 0; mmbuffer_t mb; char buf[128]; @@ -264,8 +265,16 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, xdemitcb_t *ecb) { nb += xdl_num_out(buf + nb, c2); } - memcpy(buf + nb, " @@\n", 4); - nb += 4; + memcpy(buf + nb, " @@", 3); + nb += 3; + if (func && funclen) { + buf[nb++] = ' '; + if (funclen > sizeof(buf) - nb - 1) + funclen = sizeof(buf) - nb - 1; + memcpy(buf + nb, func, funclen); + nb += funclen; + } + buf[nb++] = '\n'; mb.ptr = buf; mb.size = nb; -- cgit v1.2.1