summaryrefslogtreecommitdiffstats
path: root/xdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-28 13:41:50 +0900
committerJunio C Hamano <gitster@pobox.com>2017-11-28 13:41:50 +0900
commitf03490164811f19c8d2222a658398d67b14e905d (patch)
tree0427ffa7fee9b19daeb2bf0c92986a27ea9724d2 /xdiff
parent3b49e1b0e900a88cab9e1b035dac83c0dd6ae2b3 (diff)
parenta5dc20b0701cee53b2c37a4aa3a339b48d5bb298 (diff)
downloadgit-f03490164811f19c8d2222a658398d67b14e905d.tar.gz
git-f03490164811f19c8d2222a658398d67b14e905d.tar.xz
Merge branch 'rs/include-comments-before-the-function-header'
"git grep -W", "git diff -W" and their friends learned a heuristic to extend a pre-context beyond the line that matches the "function pattern" (aka "diff.*.xfuncname") to include a comment block, if exists, that immediately precedes it. * rs/include-comments-before-the-function-header: grep: show non-empty lines before functions with -W grep: update boundary variable for pre-context t7810: improve check of -W with user-defined function lines xdiff: show non-empty lines before functions with -W xdiff: factor out is_func_rec() t4051: add test for comments preceding function lines
Diffstat (limited to 'xdiff')
-rw-r--r--xdiff/xemit.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 6881445e4..7778dc2b1 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -121,6 +121,12 @@ static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
}
+static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
+{
+ char dummy[1];
+ return match_func_rec(xdf, xecfg, ri, dummy, sizeof(dummy)) >= 0;
+}
+
struct func_line {
long len;
char buf[80];
@@ -178,7 +184,6 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
/* Appended chunk? */
if (i1 >= xe->xdf1.nrec) {
- char dummy[1];
long i2 = xch->i2;
/*
@@ -186,8 +191,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
* a whole function was added.
*/
while (i2 < xe->xdf2.nrec) {
- if (match_func_rec(&xe->xdf2, xecfg, i2,
- dummy, sizeof(dummy)) >= 0)
+ if (is_func_rec(&xe->xdf2, xecfg, i2))
goto post_context_calculation;
i2++;
}
@@ -200,6 +204,9 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
}
fs1 = get_func_line(xe, xecfg, NULL, i1, -1);
+ while (fs1 > 0 && !is_empty_rec(&xe->xdf1, fs1 - 1) &&
+ !is_func_rec(&xe->xdf1, xecfg, fs1 - 1))
+ fs1--;
if (fs1 < 0)
fs1 = 0;
if (fs1 < s1) {