@@ -838,6 +838,27 @@ static struct blame_entry *reverse_blame(struct blame_entry *head,
838
838
return tail ;
839
839
}
840
840
841
+ /*
842
+ * Splits a blame entry into two entries at 'len' lines. The original 'e'
843
+ * consists of len lines, i.e. [e->lno, e->lno + len), and the second part,
844
+ * which is returned, consists of the remainder: [e->lno + len, e->lno +
845
+ * e->num_lines). The caller needs to sort out the reference counting for the
846
+ * new entry's suspect.
847
+ */
848
+ static struct blame_entry * split_blame_at (struct blame_entry * e , int len ,
849
+ struct blame_origin * new_suspect )
850
+ {
851
+ struct blame_entry * n = xcalloc (1 , sizeof (struct blame_entry ));
852
+
853
+ n -> suspect = new_suspect ;
854
+ n -> lno = e -> lno + len ;
855
+ n -> s_lno = e -> s_lno + len ;
856
+ n -> num_lines = e -> num_lines - len ;
857
+ e -> num_lines = len ;
858
+ e -> score = 0 ;
859
+ return n ;
860
+ }
861
+
841
862
/*
842
863
* Process one hunk from the patch between the current suspect for
843
864
* 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,
864
885
*/
865
886
if (e -> s_lno + e -> num_lines > tlno ) {
866
887
/* Move second half to a new record */
867
- int len = tlno - e -> s_lno ;
868
- struct blame_entry * n = xcalloc (1 , sizeof (struct blame_entry ));
869
- n -> suspect = e -> suspect ;
870
- n -> lno = e -> lno + len ;
871
- n -> s_lno = e -> s_lno + len ;
872
- n -> num_lines = e -> num_lines - len ;
873
- e -> num_lines = len ;
874
- e -> score = 0 ;
888
+ struct blame_entry * n ;
889
+
890
+ n = split_blame_at (e , tlno - e -> s_lno , e -> suspect );
875
891
/* Push new record to diffp */
876
892
n -> next = diffp ;
877
893
diffp = n ;
@@ -918,14 +934,10 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
918
934
* Move second half to a new record to be
919
935
* processed by later chunks
920
936
*/
921
- int len = same - e -> s_lno ;
922
- struct blame_entry * n = xcalloc (1 , sizeof (struct blame_entry ));
923
- n -> suspect = blame_origin_incref (e -> suspect );
924
- n -> lno = e -> lno + len ;
925
- n -> s_lno = e -> s_lno + len ;
926
- n -> num_lines = e -> num_lines - len ;
927
- e -> num_lines = len ;
928
- e -> score = 0 ;
937
+ struct blame_entry * n ;
938
+
939
+ n = split_blame_at (e , same - e -> s_lno ,
940
+ blame_origin_incref (e -> suspect ));
929
941
/* Push new record to samep */
930
942
n -> next = samep ;
931
943
samep = n ;
0 commit comments