Skip to content

Commit a9508a1

Browse files
committed
Merge branch 'rs/blame-code-cleanup' into maint
Code clean-up. * rs/blame-code-cleanup: blame: move blame_entry duplication to add_blame_entry()
2 parents 110bdbd + dfa3ad3 commit a9508a1

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

builtin/blame.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,11 @@ static struct origin *find_rename(struct scoreboard *sb,
658658
/*
659659
* Append a new blame entry to a given output queue.
660660
*/
661-
static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e)
661+
static void add_blame_entry(struct blame_entry ***queue,
662+
const struct blame_entry *src)
662663
{
664+
struct blame_entry *e = xmalloc(sizeof(*e));
665+
memcpy(e, src, sizeof(*e));
663666
origin_incref(e->suspect);
664667

665668
e->next = **queue;
@@ -760,21 +763,15 @@ static void split_blame(struct blame_entry ***blamed,
760763
struct blame_entry *split,
761764
struct blame_entry *e)
762765
{
763-
struct blame_entry *new_entry;
764-
765766
if (split[0].suspect && split[2].suspect) {
766767
/* The first part (reuse storage for the existing entry e) */
767768
dup_entry(unblamed, e, &split[0]);
768769

769770
/* The last part -- me */
770-
new_entry = xmalloc(sizeof(*new_entry));
771-
memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
772-
add_blame_entry(unblamed, new_entry);
771+
add_blame_entry(unblamed, &split[2]);
773772

774773
/* ... and the middle part -- parent */
775-
new_entry = xmalloc(sizeof(*new_entry));
776-
memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
777-
add_blame_entry(blamed, new_entry);
774+
add_blame_entry(blamed, &split[1]);
778775
}
779776
else if (!split[0].suspect && !split[2].suspect)
780777
/*
@@ -785,18 +782,12 @@ static void split_blame(struct blame_entry ***blamed,
785782
else if (split[0].suspect) {
786783
/* me and then parent */
787784
dup_entry(unblamed, e, &split[0]);
788-
789-
new_entry = xmalloc(sizeof(*new_entry));
790-
memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
791-
add_blame_entry(blamed, new_entry);
785+
add_blame_entry(blamed, &split[1]);
792786
}
793787
else {
794788
/* parent and then me */
795789
dup_entry(blamed, e, &split[1]);
796-
797-
new_entry = xmalloc(sizeof(*new_entry));
798-
memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
799-
add_blame_entry(unblamed, new_entry);
790+
add_blame_entry(unblamed, &split[2]);
800791
}
801792
}
802793

0 commit comments

Comments
 (0)