{"thread":{"id":"37452","subject":"[PATCH] pack-write: simplify index_pack_lockfile using skip_prefix() and xstrfmt()","startedAt":"2014-08-30T09:47:19Z","lastAt":"2014-08-30T09:47:19Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"248642","messageId":"54019DA7.2050002@web.de","threadId":"37452","inReplyTo":null,"subject":"[PATCH] pack-write: simplify index_pack_lockfile using skip_prefix() and xstrfmt()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-08-30T09:47:19Z","receivedAt":"2014-08-30T09:47:19Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Get rid of magic string length constants by using skip_prefix() instead\nof memcmp() and use xstrfmt() for building a string instead of a\nPATH_MAX-sized buffer, snprintf() and xstrdup().\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n pack-write.c | 11 +++++------\n 1 file changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/pack-write.c b/pack-write.c\nindex 9ccf804..33293ce 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -288,13 +288,12 @@ char *index_pack_lockfile(int ip_out)\n \t * case, we need it to remove the corresponding .keep file\n \t * later on.  If we don't get that then tough luck with it.\n \t */\n-\tif (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\\n' &&\n-\t    memcmp(packname, \"keep\\t\", 5) == 0) {\n-\t\tchar path[PATH_MAX];\n+\tif (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\\n') {\n+\t\tconst char *name;\n \t\tpackname[45] = 0;\n-\t\tsnprintf(path, sizeof(path), \"%s/pack/pack-%s.keep\",\n-\t\t\t get_object_directory(), packname + 5);\n-\t\treturn xstrdup(path);\n+\t\tif (skip_prefix(packname, \"keep\\t\", &name))\n+\t\t\treturn xstrfmt(\"%s/pack/pack-%s.keep\",\n+\t\t\t\t       get_object_directory(), name);\n \t}\n \treturn NULL;\n }\n-- \n2.1.0\n"}]}