From: Barret Rhoden <brho@google.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"David Kastrup" <dak@gnu.org>, "Jeff King" <peff@peff.net>,
"Jeff Smith" <whydoubt@gmail.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Junio C Hamano" <gitster@pobox.com>,
"René Scharfe" <l.s.r@web.de>,
"Stefan Beller" <stefanbeller@gmail.com>,
"Michael Platings" <michael@platin.gs>
Subject: [PATCH v7 3/8] blame: use a helper function in blame_chunk()
Date: Wed, 15 May 2019 17:44:58 -0400 [thread overview]
Message-ID: <20190515214503.77162-4-brho@google.com> (raw)
In-Reply-To: <20190515214503.77162-1-brho@google.com>
The same code for splitting a blame_entry at a particular line was used
twice in blame_chunk(), and I'll use the helper again in an upcoming
patch.
Signed-off-by: Barret Rhoden <brho@google.com>
---
blame.c | 44 ++++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 16 deletions(-)
diff --git a/blame.c b/blame.c
index 145eaf2faf9c..5369be9a2233 100644
--- a/blame.c
+++ b/blame.c
@@ -839,6 +839,27 @@ static struct blame_entry *reverse_blame(struct blame_entry *head,
return tail;
}
+/*
+ * Splits a blame entry into two entries at 'len' lines. The original 'e'
+ * consists of len lines, i.e. [e->lno, e->lno + len), and the second part,
+ * which is returned, consists of the remainder: [e->lno + len, e->lno +
+ * e->num_lines). The caller needs to sort out the reference counting for the
+ * new entry's suspect.
+ */
+static struct blame_entry *split_blame_at(struct blame_entry *e, int len,
+ struct blame_origin *new_suspect)
+{
+ struct blame_entry *n = xcalloc(1, sizeof(struct blame_entry));
+
+ n->suspect = new_suspect;
+ n->lno = e->lno + len;
+ n->s_lno = e->s_lno + len;
+ n->num_lines = e->num_lines - len;
+ e->num_lines = len;
+ e->score = 0;
+ return n;
+}
+
/*
* Process one hunk from the patch between the current suspect for
* blame_entry e and its parent. This first blames any unfinished
@@ -865,14 +886,9 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
*/
if (e->s_lno + e->num_lines > tlno) {
/* Move second half to a new record */
- int len = tlno - e->s_lno;
- struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry));
- n->suspect = e->suspect;
- n->lno = e->lno + len;
- n->s_lno = e->s_lno + len;
- n->num_lines = e->num_lines - len;
- e->num_lines = len;
- e->score = 0;
+ struct blame_entry *n;
+
+ n = split_blame_at(e, tlno - e->s_lno, e->suspect);
/* Push new record to diffp */
n->next = diffp;
diffp = n;
@@ -919,14 +935,10 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
* Move second half to a new record to be
* processed by later chunks
*/
- int len = same - e->s_lno;
- struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry));
- n->suspect = blame_origin_incref(e->suspect);
- n->lno = e->lno + len;
- n->s_lno = e->s_lno + len;
- n->num_lines = e->num_lines - len;
- e->num_lines = len;
- e->score = 0;
+ struct blame_entry *n;
+
+ n = split_blame_at(e, same - e->s_lno,
+ blame_origin_incref(e->suspect));
/* Push new record to samep */
n->next = samep;
samep = n;
--
2.21.0.1020.gf2820cf01a-goog
next prev parent reply other threads:[~2019-05-15 21:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 21:44 [PATCH v7 0/8] blame: add the ability to ignore commits Barret Rhoden
2019-05-15 21:44 ` [PATCH v7 1/8] fsck: rename and touch up init_skiplist() Barret Rhoden
2019-05-15 21:44 ` [PATCH v7 2/8] Move oidset_parse_file() to oidset.c Barret Rhoden
2019-05-15 21:44 ` Barret Rhoden [this message]
2019-05-15 21:44 ` [PATCH v7 4/8] blame: add the ability to ignore commits and their changes Barret Rhoden
2019-05-15 21:45 ` [PATCH v7 5/8] blame: add config options for the output of ignored or unblamable lines Barret Rhoden
2019-05-15 21:45 ` [PATCH v7 6/8] blame: optionally track line fingerprints during fill_blame_origin() Barret Rhoden
2019-05-15 21:45 ` [PATCH v7 7/8] blame: add a fingerprint heuristic to match ignored lines Barret Rhoden
2019-05-16 7:49 ` Junio C Hamano
2019-05-16 21:57 ` [PATCH v7 7/8 (edit)] " Barret Rhoden
2019-05-17 5:12 ` Junio C Hamano
2019-05-20 20:32 ` Michael Platings
2019-05-20 20:34 ` Barret Rhoden
2019-05-28 16:39 ` Junio C Hamano
2019-05-15 21:45 ` [PATCH v7 8/8] blame: use the " Barret Rhoden
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=20190515214503.77162-4-brho@google.com \
--to=brho@google.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=michael@platin.gs \
--cc=peff@peff.net \
--cc=stefanbeller@gmail.com \
--cc=whydoubt@gmail.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).