From: "David A. Dalrymple (and Bhushan G. Lodha)" <dad-bgl@mit.edu>
To: git@vger.kernel.org
Cc: peff@peff.net, l.s.r@web.de,
"Bhushan G. Lodha & David A. Dalrymple" <dad-bgl@mit.edu>,
"David Dalrymple (on zayin)" <davidad@alum.mit.edu>
Subject: [PATCH 07/10] xdiff: add XDL_EMIT_MOREFUNCNAMES
Date: Thu, 27 Mar 2014 14:50:53 -0400 [thread overview]
Message-ID: <201aa05a9cea6d82b85b44233e7cb02df2c5623a.1395942768.git.davidad@alum.mit.edu> (raw)
In-Reply-To: <1395946256-67124-1-git-send-email-dad-bgl@mit.edu>
In-Reply-To: <a833f392bebae7a2441d0a6e81a1c6dc52fa682e.1395942768.git.davidad@alum.mit.edu>
From: "Bhushan G. Lodha & David A. Dalrymple" <dad-bgl@mit.edu>
For filtering commits by function name, it's useful to identify the
function name in cases such as adding a new function to a file (where
the default functionality will not emit a function name in the hunk
header, because it isn't part of the context).
This adds a flag asking xdiff to be more aggressive in finding function
names to emit, and turns the flag on when the --function-name option is
in use.
Signed-off-by: David Dalrymple (on zayin) <davidad@alum.mit.edu>
---
diff.c | 2 ++
diffcore-pickaxe.c | 2 +-
xdiff/xdiff.h | 1 +
xdiff/xemit.c | 39 +++++++++++++++++++++++----------------
4 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/diff.c b/diff.c
index 2f6dbc1..914b4a2 100644
--- a/diff.c
+++ b/diff.c
@@ -2380,6 +2380,8 @@ static void builtin_diff(const char *name_a,
xecfg.ctxlen = o->context;
xecfg.interhunkctxlen = o->interhunkcontext;
xecfg.flags = XDL_EMIT_FUNCNAMES;
+ if (o->funcname)
+ xecfg.flags |= XDL_EMIT_MOREFUNCNAMES;
if (DIFF_OPT_TST(o, FUNCCONTEXT))
xecfg.flags |= XDL_EMIT_FUNCCONTEXT;
if (pe)
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 259a8fa..ab31c18 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -164,7 +164,7 @@ static int diff_funcname_filter(mmfile_t *one, mmfile_t *two,
xecfg.interhunkctxlen = o->interhunkcontext;
if (!(one && two))
xecfg.flags = XDL_EMIT_FUNCCONTEXT;
- xecfg.flags |= XDL_EMIT_FUNCNAMES;
+ xecfg.flags |= XDL_EMIT_FUNCNAMES | XDL_EMIT_MOREFUNCNAMES;
xdi_diff_outf(one, two, match_funcname, &ecbdata, &xpp, &xecfg);
return ecbdata.hit;
}
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index c033991..469bded 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -44,6 +44,7 @@
#define XDL_EMIT_FUNCNAMES (1 << 0)
#define XDL_EMIT_COMMON (1 << 1)
#define XDL_EMIT_FUNCCONTEXT (1 << 2)
+#define XDL_EMIT_MOREFUNCNAMES (1 << 3)
#define XDL_MMB_READONLY (1 << 0)
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 4266ada..0ddb094 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -23,6 +23,10 @@
#include "xinclude.h"
+struct func_line {
+ long len;
+ char buf[80];
+};
static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec);
@@ -135,12 +139,7 @@ static int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
return 0;
}
-struct func_line {
- long len;
- char buf[80];
-};
-
-static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
+static long get_func_line(xdfile_t *xdf, xdemitconf_t const *xecfg,
struct func_line *func_line, long start, long limit)
{
find_func_t ff = xecfg->find_func ? xecfg->find_func : def_ff;
@@ -150,9 +149,9 @@ static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
buf = func_line ? func_line->buf : dummy;
size = func_line ? sizeof(func_line->buf) : sizeof(dummy);
- for (l = start; l != limit && 0 <= l && l < xe->xdf1.nrec; l += step) {
+ for (l = start; l != limit && 0 <= l && l < xdf->nrec; l += step) {
const char *rec;
- long reclen = xdl_get_rec(&xe->xdf1, l, &rec);
+ long reclen = xdl_get_rec(xdf, l, &rec);
long len = ff(rec, reclen, buf, size, xecfg->find_func_priv);
if (len >= 0) {
if (func_line)
@@ -167,7 +166,7 @@ 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;
- long funclineprev = -1;
+ long funclineprev1 = -1, funclineprev2 = -1;
struct func_line func_line = { 0 };
if (xecfg->flags & XDL_EMIT_COMMON)
@@ -182,7 +181,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0);
if (xecfg->flags & XDL_EMIT_FUNCCONTEXT) {
- long fs1 = get_func_line(xe, xecfg, NULL, xch->i1, -1);
+ long fs1 = get_func_line(&xe->xdf1, xecfg, NULL, xch->i1, -1);
if (fs1 < 0)
fs1 = 0;
if (fs1 < s1) {
@@ -200,7 +199,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
e2 = xche->i2 + xche->chg2 + lctx;
if (xecfg->flags & XDL_EMIT_FUNCCONTEXT) {
- long fe1 = get_func_line(xe, xecfg, NULL,
+ long fe1 = get_func_line(&xe->xdf1, xecfg, NULL,
xche->i1 + xche->chg1,
xe->xdf1.nrec);
if (fe1 < 0)
@@ -218,7 +217,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
if (xche->next) {
long l = xche->next->i1;
if (l <= e1 ||
- get_func_line(xe, xecfg, NULL, l, e1) < 0) {
+ get_func_line(&xe->xdf1, xecfg, NULL, l, e1) < 0) {
xche = xche->next;
goto again;
}
@@ -229,10 +228,18 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
* Emit current hunk header.
*/
- if (xecfg->flags & XDL_EMIT_FUNCNAMES) {
- get_func_line(xe, xecfg, &func_line,
- s1 - 1, funclineprev);
- funclineprev = s1 - 1;
+ if (xecfg->flags & XDL_EMIT_MOREFUNCNAMES) {
+ long fl_in_xch1 = get_func_line(&xe->xdf1, xecfg,
+ &func_line, xch->i1, xch->i1+xch->chg1);
+ if (fl_in_xch1 < 0) {
+ get_func_line(&xe->xdf2, xecfg, &func_line,
+ xch->i2, funclineprev2);
+ funclineprev2 = xch->i2;
+ }
+ } else if (xecfg->flags & XDL_EMIT_FUNCNAMES) {
+ get_func_line(&xe->xdf1, xecfg, &func_line,
+ s1 - 1, funclineprev1);
+ funclineprev1 = s1 - 1;
}
if (xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2,
func_line.buf, func_line.len, ecb) < 0)
--
1.7.12.4 (Apple Git-37)
next prev parent reply other threads:[~2014-03-27 18:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-27 18:50 [PATCH 00/10] [RFC] pickaxe for function names David A. Dalrymple (and Bhushan G. Lodha)
2014-03-27 18:50 ` [PATCH 01/10] .gitattributes: specify the language used David A. Dalrymple (and Bhushan G. Lodha)
2014-03-27 18:50 ` [PATCH 02/10] diffcore-pickaxe.c: refactor regex compilation David A. Dalrymple (and Bhushan G. Lodha)
2014-03-27 18:50 ` [PATCH 03/10] diffcore-pickaxe.c: Refactor pickaxe_fn signature David A. Dalrymple (and Bhushan G. Lodha)
2014-04-04 11:09 ` Jakub Narębski
2014-03-27 18:50 ` [PATCH 04/10] diff.c/diff.h: expose userdiff_funcname David A. Dalrymple (and Bhushan G. Lodha)
2014-03-27 18:50 ` [PATCH 05/10] diffcore-pickaxe.c: set up funcname pattern David A. Dalrymple (and Bhushan G. Lodha)
2014-03-27 18:50 ` [PATCH 06/10] log: --function-name pickaxe David A. Dalrymple (and Bhushan G. Lodha)
2014-04-03 21:25 ` René Scharfe
2014-04-03 21:44 ` Junio C Hamano
2014-04-04 11:15 ` Jakub Narębski
2014-04-04 18:46 ` Junio C Hamano
2014-04-28 20:04 ` Bhushan Lodha
2014-03-27 18:50 ` David A. Dalrymple (and Bhushan G. Lodha) [this message]
2014-03-27 18:50 ` [PATCH 08/10] xdiff: add XDL_EMIT_MOREHUNKHEADS David A. Dalrymple (and Bhushan G. Lodha)
2014-03-27 18:50 ` [PATCH 09/10] t4213: test --function-name option David A. Dalrymple (and Bhushan G. Lodha)
2014-03-28 7:25 ` Johannes Sixt
2014-03-28 8:21 ` Eric Sunshine
2014-03-28 11:45 ` Johannes Sixt
2014-04-04 11:21 ` Jakub Narębski
2014-03-27 18:50 ` [PATCH 10/10] Documentation: Document --function-name usage David A. Dalrymple (and Bhushan G. Lodha)
2014-03-28 0:30 ` Eric Sunshine
2014-03-27 19:03 ` [PATCH 00/10] [RFC] pickaxe for function names Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201aa05a9cea6d82b85b44233e7cb02df2c5623a.1395942768.git.davidad@alum.mit.edu \
--to=dad-bgl@mit.edu \
--cc=davidad@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).