summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9c48666)
raw | patch | inline | side by side (parent: 9c48666)
author | Mark Wooding <mdw@distorted.org.uk> | |
Tue, 28 Mar 2006 02:23:31 +0000 (03:23 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 28 Mar 2006 02:43:51 +0000 (18:43 -0800) |
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 <mdw@distorted.org.uk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
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 <mdw@distorted.org.uk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
diff.c | patch | blob | history | |
t/t4001-diff-rename.sh | patch | blob | history | |
xdiff/xdiff.h | patch | blob | history | |
xdiff/xemit.c | patch | blob | history | |
xdiff/xinclude.h | patch | blob | history | |
xdiff/xutils.c | patch | blob | history | |
xdiff/xutils.h | patch | blob | history |
index 5eae0947f35606eab6ff3421fe64fa5cb236f2ad..8b37477afc3bf8555f0b6c9f0d6f116a39784817 100644 (file)
--- a/diff.c
+++ b/diff.c
ecbdata.label_path = lbl;
xpp.flags = XDF_NEED_MINIMAL;
xecfg.ctxlen = 3;
+ xecfg.flags = XDL_EMIT_FUNCNAMES;
if (!diffopts)
;
else if (!strncmp(diffopts, "--unified=", 10))
diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh
index 08c11319a70be6dfbcc530d9462c36254a3acd8e..2e3c20d6b9468bf413e97d422e7dbe13ac4238cd 100755 (executable)
--- a/t/t4001-diff-rename.sh
+++ b/t/t4001-diff-rename.sh
rename to path1
--- a/path0
+++ b/path1
-@@ -8,7 +8,7 @@
+@@ -8,7 +8,7 @@ Line 7
Line 8
Line 9
Line 10
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index 71cb9391af84a6b9640e25c80c8706b3b58e377e..2540e8a2ccc6781d23a42c03dadc050a3e233c39 100644 (file)
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
#define XDL_PATCH_MODEMASK ((1 << 8) - 1)
#define XDL_PATCH_IGNOREBSPACE (1 << 8)
+#define XDL_EMIT_FUNCNAMES (1 << 0)
+
#define XDL_MMB_READONLY (1 << 0)
#define XDL_MMF_ATOMIC (1 << 0)
typedef struct s_xdemitconf {
long ctxlen;
+ unsigned long flags;
} xdemitconf_t;
typedef struct s_bdiffparam {
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 2e5d54cfcf6dae715e500df26d1b6dab418fdefc..ad5bfb191003f14cd71b2ec7f39fd72ac86eda9b 100644 (file)
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
}
+static void xdl_find_func(xdfile_t *xf, long i, char *buf, long sz, long *ll) {
+
+ /*
+ * Be quite stupid about this for now. Find a line in the old file
+ * before the start of the hunk (and context) which starts with a
+ * plausible character.
+ */
+
+ const char *rec;
+ long len;
+
+ *ll = 0;
+ while (i-- > 0) {
+ len = xdl_get_rec(xf, i, &rec);
+ if (len > 0 &&
+ (isalpha((unsigned char)*rec) || /* identifier? */
+ *rec == '_' || /* also identifier? */
+ *rec == '(' || /* lisp defun? */
+ *rec == '#')) { /* #define? */
+ if (len > sz)
+ len = sz;
+ if (len && rec[len - 1] == '\n')
+ len--;
+ memcpy(buf, rec, len);
+ *ll = len;
+ return;
+ }
+ }
+}
+
+
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg) {
long s1, s2, e1, e2, lctx;
xdchange_t *xch, *xche;
+ char funcbuf[40];
+ long funclen = 0;
for (xch = xche = xscr; xch; xch = xche->next) {
xche = xdl_get_hunk(xch, xecfg);
/*
* Emit current hunk header.
*/
- if (xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2, ecb) < 0)
+
+ if (xecfg->flags & XDL_EMIT_FUNCNAMES) {
+ xdl_find_func(&xe->xdf1, s1, funcbuf,
+ sizeof(funcbuf), &funclen);
+ }
+ if (xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2,
+ funcbuf, funclen, ecb) < 0)
return -1;
/*
diff --git a/xdiff/xinclude.h b/xdiff/xinclude.h
index 9490fc56ca7523120ad315c2f64149c61ca4c269..04a9da82c9cb7a2ab24d86efb0e6c6aafdd55f3b 100644 (file)
--- a/xdiff/xinclude.h
+++ b/xdiff/xinclude.h
#if !defined(XINCLUDE_H)
#define XINCLUDE_H
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 8221806f78bab437e8863c3fb2ea6229ddae9bca..afaada1edf72c8797d3d7bbd24303638accd6c24 100644 (file)
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
}
-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];
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;
diff --git a/xdiff/xutils.h b/xdiff/xutils.h
index 428a4bb1ef761fa0a61c9e46310c6b5c184b48ab..55b0d39f49d656576f83ccee8961ce5ea05e950e 100644 (file)
--- a/xdiff/xutils.h
+++ b/xdiff/xutils.h
unsigned int xdl_hashbits(unsigned int size);
int xdl_num_out(char *out, long val);
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);