From: "René Scharfe" <l.s.r@web.de>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH 2/5] diff: handle appended chunks better with -W
Date: Sat, 21 May 2016 20:45:43 +0200 [thread overview]
Message-ID: <5740ACD7.8010404@web.de> (raw)
In-Reply-To: <5740AC28.6010202@web.de>
If lines are added at the end of a file, diff -W shows the whole file.
That's because get_func_line() only considers the pre-image and gives up
if it sees a record index beyond its end.
Consider the post-image as well to see if the added lines already make
up a full function. If it doesn't then search for the previous function
line by starting from the bottom of the pre-image, thereby avoiding to
confuse get_func_line().
Reuse the existing label called "again", as it's exactly where we need
to jump to when we're done handling the pre-context, but rename it to
"post_context_calculation" in order to document its new purpose better.
Reported-by: Junio C Hamano <gitster@pobox.com>
Initial-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
xdiff/xemit.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 0c87637..969100d 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -171,7 +171,28 @@ 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, i1 = xch->i1;
+
+ /* Appended chunk? */
+ if (i1 >= xe->xdf1.nrec) {
+ char dummy[1];
+
+ /*
+ * We don't need additional context if
+ * a whole function was added.
+ */
+ if (match_func_rec(&xe->xdf2, xecfg, xch->i2,
+ dummy, sizeof(dummy)) >= 0)
+ goto post_context_calculation;
+
+ /*
+ * Otherwise get more context from the
+ * pre-image.
+ */
+ i1 = xe->xdf1.nrec - 1;
+ }
+
+ fs1 = get_func_line(xe, xecfg, NULL, i1, -1);
if (fs1 < 0)
fs1 = 0;
if (fs1 < s1) {
@@ -180,7 +201,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
}
}
- again:
+ post_context_calculation:
lctx = xecfg->ctxlen;
lctx = XDL_MIN(lctx, xe->xdf1.nrec - (xche->i1 + xche->chg1));
lctx = XDL_MIN(lctx, xe->xdf2.nrec - (xche->i2 + xche->chg2));
@@ -209,7 +230,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
if (l <= e1 ||
get_func_line(xe, xecfg, NULL, l, e1) < 0) {
xche = xche->next;
- goto again;
+ goto post_context_calculation;
}
}
}
--
2.8.3
next prev parent reply other threads:[~2016-05-21 18:46 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 21:51 [Bug?] log -p -W showing the whole file for a patch that adds to the end? Junio C Hamano
2016-05-10 22:51 ` Junio C Hamano
2016-05-12 22:12 ` René Scharfe
2016-05-21 18:42 ` René Scharfe
2016-05-21 18:45 ` [PATCH 1/5] diff: factor out match_func_rec() René Scharfe
2016-05-21 18:45 ` René Scharfe [this message]
2016-05-21 18:46 ` [PATCH 3/5] diff: ignore empty lines before added functions with -W René Scharfe
2016-05-21 18:46 ` [PATCH 4/5] diff: don't include common trailing empty lines " René Scharfe
2016-05-21 18:47 ` [PATCH 5/5] grep: don't extend context to " René Scharfe
2016-05-24 18:16 ` [Bug?] log -p -W showing the whole file for a patch that adds to the end? Junio C Hamano
2016-05-26 8:54 ` René Scharfe
2016-05-26 17:05 ` Junio C Hamano
2016-05-27 17:13 ` René Scharfe
2016-05-28 14:46 ` René Scharfe
2016-05-28 14:57 ` [PATCH v2 1/8] t4051: rewrite, add more tests René Scharfe
2016-05-29 23:55 ` Junio C Hamano
2016-05-30 20:55 ` René Scharfe
2016-05-31 20:00 ` [PATCH v2.5 " René Scharfe
2016-05-31 20:15 ` René Scharfe
2016-05-31 21:23 ` Junio C Hamano
2016-05-28 14:58 ` [PATCH v2 2/8] xdiff: factor out match_func_rec() René Scharfe
2016-05-28 15:00 ` [PATCH v2 3/8] xdiff: handle appended chunks better with -W René Scharfe
2016-05-28 15:02 ` [PATCH v2 4/8] xdiff: ignore empty lines before added functions " René Scharfe
2016-05-28 15:03 ` [PATCH v2 5/8] xdiff: -W: don't include common trailing empty lines in context René Scharfe
2016-05-28 15:04 ` [PATCH v2 6/8] xdiff: don't trim common tail with -W René Scharfe
2016-05-28 15:05 ` [PATCH v2 7/8] t7810: add test for grep -W and trailing empty context lines René Scharfe
2016-05-28 15:06 ` [PATCH v2 8/8] grep: -W: don't extend context to trailing empty lines René Scharfe
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=5740ACD7.8010404@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).