blame: create entry prepend function
Create function that populates a blame_entry and prepends it to a list. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff Smith committed
May 24, 2017 at 00:15 UTC
e94f77f0e28788972c3c828bdcbe5d68d034849e
1 file changed
+15
-10
builtin/blame.c
+15
-10
@@ -2643,6 +2643,20 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
2643
*orig = o;
2644
}
2645
2646
+struct blame_entry *blame_entry_prepend(struct blame_entry *head,
2647
+ long start, long end,
2648
+ struct blame_origin *o)
2649
+{
2650
+ struct blame_entry *new_head = xcalloc(1, sizeof(struct blame_entry));
2651
+ new_head->lno = start;
2652
+ new_head->num_lines = end - start;
2653
+ new_head->suspect = o;
2654
+ new_head->s_lno = start;
2655
+ new_head->next = head;
2656
+ blame_origin_incref(o);
2657
+ return new_head;
2658
+}
2659
+
2660
int cmd_blame(int argc, const char **argv, const char *prefix)
2661
{
2662
struct rev_info revs;
@@ -2885,16 +2899,7 @@ parse_done:
2899
2900
for (range_i = ranges.nr; range_i > 0; --range_i) {
2901
const struct range *r = &ranges.ranges[range_i - 1];
2888
- long bottom = r->start;
2889
- long top = r->end;
2890
- struct blame_entry *next = ent;
2891
- ent = xcalloc(1, sizeof(*ent));
2892
- ent->lno = bottom;
2893
- ent->num_lines = top - bottom;
2894
- ent->suspect = o;
2895
- ent->s_lno = bottom;
2896
- ent->next = next;
2897
- blame_origin_incref(o);
2902
+ ent = blame_entry_prepend(ent, r->start, r->end, o);
2903
}
2904
2905
o->suspects = ent;