Skip to content

Commit e94f77f

Browse files
whydoubtgitster
authored andcommitted
blame: create entry prepend function
Create function that populates a blame_entry and prepends it to a list. Signed-off-by: Jeff Smith <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0d0ef1 commit e94f77f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

builtin/blame.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,20 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
26432643
*orig = o;
26442644
}
26452645

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+
26462660
int cmd_blame(int argc, const char **argv, const char *prefix)
26472661
{
26482662
struct rev_info revs;
@@ -2885,16 +2899,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
28852899

28862900
for (range_i = ranges.nr; range_i > 0; --range_i) {
28872901
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);
28982903
}
28992904

29002905
o->suspects = ent;

0 commit comments

Comments
 (0)