Skip to content

Commit dfa3ad3

Browse files
rscharfegitster
authored andcommitted
blame: move blame_entry duplication to add_blame_entry()
All callers of add_blame_entry() allocate and copy the second argument. Let the function do it for them, reducing code duplication. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3808ca commit dfa3ad3

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
@@ -657,8 +657,11 @@ static struct origin *find_rename(struct scoreboard *sb,
657657
/*
658658
* Append a new blame entry to a given output queue.
659659
*/
660-
static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e)
660+
static void add_blame_entry(struct blame_entry ***queue,
661+
const struct blame_entry *src)
661662
{
663+
struct blame_entry *e = xmalloc(sizeof(*e));
664+
memcpy(e, src, sizeof(*e));
662665
origin_incref(e->suspect);
663666

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

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

773772
/* ... and the middle part -- parent */
774-
new_entry = xmalloc(sizeof(*new_entry));
775-
memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
776-
add_blame_entry(blamed, new_entry);
773+
add_blame_entry(blamed, &split[1]);
777774
}
778775
else if (!split[0].suspect && !split[2].suspect)
779776
/*
@@ -784,18 +781,12 @@ static void split_blame(struct blame_entry ***blamed,
784781
else if (split[0].suspect) {
785782
/* me and then parent */
786783
dup_entry(unblamed, e, &split[0]);
787-
788-
new_entry = xmalloc(sizeof(*new_entry));
789-
memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
790-
add_blame_entry(blamed, new_entry);
784+
add_blame_entry(blamed, &split[1]);
791785
}
792786
else {
793787
/* parent and then me */
794788
dup_entry(blamed, e, &split[1]);
795-
796-
new_entry = xmalloc(sizeof(*new_entry));
797-
memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
798-
add_blame_entry(unblamed, new_entry);
789+
add_blame_entry(unblamed, &split[2]);
799790
}
800791
}
801792

0 commit comments

Comments
 (0)