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>
Subject: [PATCH v4 2/4] blame: use a helper function in blame_chunk()
Date: Tue, 26 Feb 2019 12:06:46 -0500 [thread overview]
Message-ID: <20190226170648.211847-3-brho@google.com> (raw)
In-Reply-To: <20190226170648.211847-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 | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/blame.c b/blame.c
index da57233cbbd9..f30bb2430c5e 100644
--- a/blame.c
+++ b/blame.c
@@ -838,6 +838,25 @@ 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
@@ -864,14 +883,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;
@@ -918,14 +932,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.rc2.261.ga7da99ff1b-goog
next prev parent reply other threads:[~2019-02-26 17:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-26 17:06 [PATCH v4 0/4] blame: add the ability to ignore commits Barret Rhoden
2019-02-26 17:06 ` [PATCH v4 1/4] Move init_skiplist() outside of fsck Barret Rhoden
2019-02-26 17:06 ` Barret Rhoden [this message]
2019-02-26 17:06 ` [PATCH v4 3/4] blame: add the ability to ignore commits and their changes Barret Rhoden
2019-02-26 17:06 ` [PATCH v4 4/4] blame: add a config option to mark ignored lines 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=20190226170648.211847-3-brho@google.com \
--to=brho@google$(echo .)com \
--cc=Johannes.Schindelin@gmx$(echo .)de \
--cc=avarab@gmail$(echo .)com \
--cc=dak@gnu$(echo .)org \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=l.s.r@web$(echo .)de \
--cc=peff@peff$(echo .)net \
--cc=stefanbeller@gmail$(echo .)com \
--cc=whydoubt@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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