From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 6/9] combine-diff: use an xdiff hunk callback
Date: Fri, 2 Nov 2018 02:38:20 -0400 [thread overview]
Message-ID: <20181102063820.GF31216@sigill.intra.peff.net> (raw)
In-Reply-To: <20181102063156.GA30252@sigill.intra.peff.net>
A combined diff has to line up the hunks for all of the individual
pairwise diffs, and thus needs to know their line numbers and sizes. We
get that now by parsing the hunk header line that xdiff generates.
However, now that xdiff supports a hunk callback, we can just use the
values directly.
Signed-off-by: Jeff King <peff@peff.net>
---
I learned to love --color-moved-ws=allow-indentation-change for this
one.
combine-diff.c | 67 +++++++++++++++++++++++++++-----------------------
1 file changed, 36 insertions(+), 31 deletions(-)
diff --git a/combine-diff.c b/combine-diff.c
index 3c479cfc3e..ad7752ea6b 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -345,38 +345,43 @@ struct combine_diff_state {
struct sline *lost_bucket;
};
-static void consume_line(void *state_, char *line, unsigned long len)
+static void consume_hunk(void *state_,
+ long ob, long on,
+ long nb, long nn,
+ const char *funcline, long funclen)
{
struct combine_diff_state *state = state_;
- if (5 < len && !memcmp("@@ -", line, 4)) {
- if (parse_hunk_header(line, len,
- &state->ob, &state->on,
- &state->nb, &state->nn))
- return;
- state->lno = state->nb;
- if (state->nn == 0) {
- /* @@ -X,Y +N,0 @@ removed Y lines
- * that would have come *after* line N
- * in the result. Our lost buckets hang
- * to the line after the removed lines,
- *
- * Note that this is correct even when N == 0,
- * in which case the hunk removes the first
- * line in the file.
- */
- state->lost_bucket = &state->sline[state->nb];
- if (!state->nb)
- state->nb = 1;
- } else {
- state->lost_bucket = &state->sline[state->nb-1];
- }
- if (!state->sline[state->nb-1].p_lno)
- state->sline[state->nb-1].p_lno =
- xcalloc(state->num_parent,
- sizeof(unsigned long));
- state->sline[state->nb-1].p_lno[state->n] = state->ob;
- return;
+
+ state->ob = ob;
+ state->on = on;
+ state->nb = nb;
+ state->nn = nn;
+ state->lno = state->nb;
+ if (state->nn == 0) {
+ /* @@ -X,Y +N,0 @@ removed Y lines
+ * that would have come *after* line N
+ * in the result. Our lost buckets hang
+ * to the line after the removed lines,
+ *
+ * Note that this is correct even when N == 0,
+ * in which case the hunk removes the first
+ * line in the file.
+ */
+ state->lost_bucket = &state->sline[state->nb];
+ if (!state->nb)
+ state->nb = 1;
+ } else {
+ state->lost_bucket = &state->sline[state->nb-1];
}
+ if (!state->sline[state->nb-1].p_lno)
+ state->sline[state->nb-1].p_lno =
+ xcalloc(state->num_parent, sizeof(unsigned long));
+ state->sline[state->nb-1].p_lno[state->n] = state->ob;
+}
+
+static void consume_line(void *state_, char *line, unsigned long len)
+{
+ struct combine_diff_state *state = state_;
if (!state->lost_bucket)
return; /* not in any hunk yet */
switch (line[0]) {
@@ -421,8 +426,8 @@ static void combine_diff(struct repository *r,
state.num_parent = num_parent;
state.n = n;
- if (xdi_diff_outf(&parent_file, result_file, NULL, consume_line,
- &state, &xpp, &xecfg))
+ if (xdi_diff_outf(&parent_file, result_file, consume_hunk,
+ consume_line, &state, &xpp, &xecfg))
die("unable to generate combined diff for %s",
oid_to_hex(parent));
free(parent_file.ptr);
--
2.19.1.1336.g081079ac04
next prev parent reply other threads:[~2018-11-02 6:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-02 6:31 [PATCH 0/9] saner xdiff hunk callbacks Jeff King
2018-11-02 6:35 ` [PATCH 1/9] xdiff: provide a separate emit callback for hunks Jeff King
2018-11-02 6:35 ` [PATCH 2/9] xdiff-interface: provide a separate consume " Jeff King
2018-11-02 6:36 ` [PATCH 3/9] diff: avoid generating unused hunk header lines Jeff King
2018-11-02 19:50 ` Stefan Beller
2018-11-02 20:15 ` Jeff King
2018-11-03 0:32 ` Junio C Hamano
2018-11-02 6:36 ` [PATCH 4/9] diff: discard hunk headers for patch-ids earlier Jeff King
2018-11-02 6:37 ` [PATCH 5/9] diff: use hunk callback for word-diff Jeff King
2018-11-02 6:38 ` Jeff King [this message]
2018-11-02 6:39 ` [PATCH 7/9] diff: convert --check to use a hunk callback Jeff King
2018-11-02 6:39 ` [PATCH 8/9] range-diff: " Jeff King
2018-11-02 6:40 ` [PATCH 9/9] xdiff-interface: drop parse_hunk_header() Jeff King
2018-11-02 11:48 ` [PATCH 0/9] saner xdiff hunk callbacks Junio C Hamano
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=20181102063820.GF31216@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/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).