{"thread":{"id":"45337","subject":"[PATCH] blame: move blame_entry duplication to add_blame_entry()","startedAt":"2017-03-10T00:13:40Z","lastAt":"2017-03-10T16:20:52Z","messageCount":3,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"313725","messageId":"11b8ad3a-cd3d-2fd6-4b06-b442099c2709@web.de","threadId":"45337","inReplyTo":null,"subject":"[PATCH] blame: move blame_entry duplication to add_blame_entry()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-03-10T00:12:59Z","receivedAt":"2017-03-10T00:13:40Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"All callers of add_blame_entry() allocate and copy the second argument.\nLet the function do it for them, reducing code duplication.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/blame.c | 25 ++++++++-----------------\n 1 file changed, 8 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex cffc626540..f7aa95f4ba 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -658,8 +658,11 @@ static struct origin *find_rename(struct scoreboard *sb,\n /*\n  * Append a new blame entry to a given output queue.\n  */\n-static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e)\n+static void add_blame_entry(struct blame_entry ***queue,\n+\t\t\t    const struct blame_entry *src)\n {\n+\tstruct blame_entry *e = xmalloc(sizeof(*e));\n+\tmemcpy(e, src, sizeof(*e));\n \torigin_incref(e->suspect);\n \n \te->next = **queue;\n@@ -760,21 +763,15 @@ static void split_blame(struct blame_entry ***blamed,\n \t\t\tstruct blame_entry *split,\n \t\t\tstruct blame_entry *e)\n {\n-\tstruct blame_entry *new_entry;\n-\n \tif (split[0].suspect && split[2].suspect) {\n \t\t/* The first part (reuse storage for the existing entry e) */\n \t\tdup_entry(unblamed, e, &split[0]);\n \n \t\t/* The last part -- me */\n-\t\tnew_entry = xmalloc(sizeof(*new_entry));\n-\t\tmemcpy(new_entry, &(split[2]), sizeof(struct blame_entry));\n-\t\tadd_blame_entry(unblamed, new_entry);\n+\t\tadd_blame_entry(unblamed, &split[2]);\n \n \t\t/* ... and the middle part -- parent */\n-\t\tnew_entry = xmalloc(sizeof(*new_entry));\n-\t\tmemcpy(new_entry, &(split[1]), sizeof(struct blame_entry));\n-\t\tadd_blame_entry(blamed, new_entry);\n+\t\tadd_blame_entry(blamed, &split[1]);\n \t}\n \telse if (!split[0].suspect && !split[2].suspect)\n \t\t/*\n@@ -785,18 +782,12 @@ static void split_blame(struct blame_entry ***blamed,\n \telse if (split[0].suspect) {\n \t\t/* me and then parent */\n \t\tdup_entry(unblamed, e, &split[0]);\n-\n-\t\tnew_entry = xmalloc(sizeof(*new_entry));\n-\t\tmemcpy(new_entry, &(split[1]), sizeof(struct blame_entry));\n-\t\tadd_blame_entry(blamed, new_entry);\n+\t\tadd_blame_entry(blamed, &split[1]);\n \t}\n \telse {\n \t\t/* parent and then me */\n \t\tdup_entry(blamed, e, &split[1]);\n-\n-\t\tnew_entry = xmalloc(sizeof(*new_entry));\n-\t\tmemcpy(new_entry, &(split[2]), sizeof(struct blame_entry));\n-\t\tadd_blame_entry(unblamed, new_entry);\n+\t\tadd_blame_entry(unblamed, &split[2]);\n \t}\n }\n \n-- \n2.12.0\n\n"},{"id":"313739","messageId":"20170310083238.hjfnkmcgufi3oehq@sigill.intra.peff.net","threadId":"45337","inReplyTo":"11b8ad3a-cd3d-2fd6-4b06-b442099c2709@web.de","subject":"Re: [PATCH] blame: move blame_entry duplication to add_blame_entry()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-10T08:32:39Z","receivedAt":"2017-03-10T08:32:45Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 10, 2017 at 01:12:59AM +0100, René Scharfe wrote:\n\n> All callers of add_blame_entry() allocate and copy the second argument.\n> Let the function do it for them, reducing code duplication.\n\nI assume you found this due to the DUPLICATE() discussion elsewhere.\nRegardless of the results of that discussion, I think this is a nice\nsimplification.\n\n-Peff\n"},{"id":"313752","messageId":"bcb26ae4-ea18-b232-a0e6-2877cda7ccc8@web.de","threadId":"45337","inReplyTo":"20170310083238.hjfnkmcgufi3oehq@sigill.intra.peff.net","subject":"Re: [PATCH] blame: move blame_entry duplication to add_blame_entry()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-03-10T16:20:16Z","receivedAt":"2017-03-10T16:20:52Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 10.03.2017 um 09:32 schrieb Jeff King:\n> On Fri, Mar 10, 2017 at 01:12:59AM +0100, René Scharfe wrote:\n>\n>> All callers of add_blame_entry() allocate and copy the second argument.\n>> Let the function do it for them, reducing code duplication.\n>\n> I assume you found this due to the DUPLICATE() discussion elsewhere.\n\nIndeed, your grep command in that discussion showed them.\n\nRené\n"}]}