git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blame: move blame_entry duplication to add_blame_entry()
@ 2017-03-10  0:12 René Scharfe
  2017-03-10  8:32 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2017-03-10  0:12 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Jeff King

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 <l.s.r@web.de>
---
 builtin/blame.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index cffc626540..f7aa95f4ba 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -658,8 +658,11 @@ static struct origin *find_rename(struct scoreboard *sb,
 /*
  * Append a new blame entry to a given output queue.
  */
-static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e)
+static void add_blame_entry(struct blame_entry ***queue,
+			    const struct blame_entry *src)
 {
+	struct blame_entry *e = xmalloc(sizeof(*e));
+	memcpy(e, src, sizeof(*e));
 	origin_incref(e->suspect);
 
 	e->next = **queue;
@@ -760,21 +763,15 @@ static void split_blame(struct blame_entry ***blamed,
 			struct blame_entry *split,
 			struct blame_entry *e)
 {
-	struct blame_entry *new_entry;
-
 	if (split[0].suspect && split[2].suspect) {
 		/* The first part (reuse storage for the existing entry e) */
 		dup_entry(unblamed, e, &split[0]);
 
 		/* The last part -- me */
-		new_entry = xmalloc(sizeof(*new_entry));
-		memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
-		add_blame_entry(unblamed, new_entry);
+		add_blame_entry(unblamed, &split[2]);
 
 		/* ... and the middle part -- parent */
-		new_entry = xmalloc(sizeof(*new_entry));
-		memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
-		add_blame_entry(blamed, new_entry);
+		add_blame_entry(blamed, &split[1]);
 	}
 	else if (!split[0].suspect && !split[2].suspect)
 		/*
@@ -785,18 +782,12 @@ static void split_blame(struct blame_entry ***blamed,
 	else if (split[0].suspect) {
 		/* me and then parent */
 		dup_entry(unblamed, e, &split[0]);
-
-		new_entry = xmalloc(sizeof(*new_entry));
-		memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
-		add_blame_entry(blamed, new_entry);
+		add_blame_entry(blamed, &split[1]);
 	}
 	else {
 		/* parent and then me */
 		dup_entry(blamed, e, &split[1]);
-
-		new_entry = xmalloc(sizeof(*new_entry));
-		memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
-		add_blame_entry(unblamed, new_entry);
+		add_blame_entry(unblamed, &split[2]);
 	}
 }
 
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] blame: move blame_entry duplication to add_blame_entry()
  2017-03-10  0:12 [PATCH] blame: move blame_entry duplication to add_blame_entry() René Scharfe
@ 2017-03-10  8:32 ` Jeff King
  2017-03-10 16:20   ` René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2017-03-10  8:32 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

On Fri, Mar 10, 2017 at 01:12:59AM +0100, René Scharfe wrote:

> All callers of add_blame_entry() allocate and copy the second argument.
> Let the function do it for them, reducing code duplication.

I assume you found this due to the DUPLICATE() discussion elsewhere.
Regardless of the results of that discussion, I think this is a nice
simplification.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] blame: move blame_entry duplication to add_blame_entry()
  2017-03-10  8:32 ` Jeff King
@ 2017-03-10 16:20   ` René Scharfe
  0 siblings, 0 replies; 3+ messages in thread
From: René Scharfe @ 2017-03-10 16:20 UTC (permalink / raw)
  To: Jeff King; +Cc: Git List, Junio C Hamano

Am 10.03.2017 um 09:32 schrieb Jeff King:
> On Fri, Mar 10, 2017 at 01:12:59AM +0100, René Scharfe wrote:
>
>> All callers of add_blame_entry() allocate and copy the second argument.
>> Let the function do it for them, reducing code duplication.
>
> I assume you found this due to the DUPLICATE() discussion elsewhere.

Indeed, your grep command in that discussion showed them.

René

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-10 16:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10  0:12 [PATCH] blame: move blame_entry duplication to add_blame_entry() René Scharfe
2017-03-10  8:32 ` Jeff King
2017-03-10 16:20   ` René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).