blame: use a helper function in blame_chunk()
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f93895f8fc
commit
55f808fbc5
44
blame.c
44
blame.c
@ -838,6 +838,27 @@ static struct blame_entry *reverse_blame(struct blame_entry *head,
|
|||||||
return tail;
|
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
|
* Process one hunk from the patch between the current suspect for
|
||||||
* blame_entry e and its parent. This first blames any unfinished
|
* blame_entry e and its parent. This first blames any unfinished
|
||||||
@ -864,14 +885,9 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
|
|||||||
*/
|
*/
|
||||||
if (e->s_lno + e->num_lines > tlno) {
|
if (e->s_lno + e->num_lines > tlno) {
|
||||||
/* Move second half to a new record */
|
/* Move second half to a new record */
|
||||||
int len = tlno - e->s_lno;
|
struct blame_entry *n;
|
||||||
struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry));
|
|
||||||
n->suspect = e->suspect;
|
n = split_blame_at(e, tlno - e->s_lno, 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;
|
|
||||||
/* Push new record to diffp */
|
/* Push new record to diffp */
|
||||||
n->next = diffp;
|
n->next = diffp;
|
||||||
diffp = n;
|
diffp = n;
|
||||||
@ -918,14 +934,10 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
|
|||||||
* Move second half to a new record to be
|
* Move second half to a new record to be
|
||||||
* processed by later chunks
|
* processed by later chunks
|
||||||
*/
|
*/
|
||||||
int len = same - e->s_lno;
|
struct blame_entry *n;
|
||||||
struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry));
|
|
||||||
n->suspect = blame_origin_incref(e->suspect);
|
n = split_blame_at(e, same - e->s_lno,
|
||||||
n->lno = e->lno + len;
|
blame_origin_incref(e->suspect));
|
||||||
n->s_lno = e->s_lno + len;
|
|
||||||
n->num_lines = e->num_lines - len;
|
|
||||||
e->num_lines = len;
|
|
||||||
e->score = 0;
|
|
||||||
/* Push new record to samep */
|
/* Push new record to samep */
|
||||||
n->next = samep;
|
n->next = samep;
|
||||||
samep = n;
|
samep = n;
|
||||||
|
Loading…
Reference in New Issue
Block a user