Signed-off-by: Jeff Smith <[email protected]>
---
blame.c | 16 ++++++++++++++++
blame.h | 2 ++
builtin/blame.c | 11 +----------
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/blame.c b/blame.c
index f6c9cb7..00404b9 100644
--- a/blame.c
+++ b/blame.c
@@ -1845,3 +1845,19 @@ void setup_scoreboard(struct blame_scoreboard *sb, const
char *path, struct blam
if (orig)
*orig = o;
}
+
+
+
+struct blame_entry *blame_entry_prepend(struct blame_entry *head,
+ long start, long end,
+ struct blame_origin *o)
+{
+ struct blame_entry *new_head = xcalloc(1, sizeof(struct blame_entry));
+ new_head->lno = start;
+ new_head->num_lines = end - start;
+ new_head->suspect = o;
+ new_head->s_lno = start;
+ new_head->next = head;
+ blame_origin_incref(o);
+ return new_head;
+}
diff --git a/blame.h b/blame.h
index 76fd8ef..a6c915c 100644
--- a/blame.h
+++ b/blame.h
@@ -170,4 +170,6 @@ extern const char *blame_nth_line(struct blame_scoreboard
*sb, long lno);
extern void init_scoreboard(struct blame_scoreboard *sb);
extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path,
struct blame_origin **orig);
+extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long
start, long end, struct blame_origin *o);
+
#endif /* BLAME_H */
diff --git a/builtin/blame.c b/builtin/blame.c
index 7ec5a73..8a858b0 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -890,16 +890,7 @@ int cmd_blame(int argc, const char **argv, const char
*prefix)
for (range_i = ranges.nr; range_i > 0; --range_i) {
const struct range *r = &ranges.ranges[range_i - 1];
- long bottom = r->start;
- long top = r->end;
- struct blame_entry *next = ent;
- ent = xcalloc(1, sizeof(*ent));
- ent->lno = bottom;
- ent->num_lines = top - bottom;
- ent->suspect = o;
- ent->s_lno = bottom;
- ent->next = next;
- blame_origin_incref(o);
+ ent = blame_entry_prepend(ent, r->start, r->end, o);
}
o->suspects = ent;
--
2.9.3