pack-write: simplify index_pack_lockfile using skip_prefix() and xstrfmt()
Get rid of magic string length constants by using skip_prefix() instead of memcmp() and use xstrfmt() for building a string instead of a PATH_MAX-sized buffer, snprintf() and xstrdup(). Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 30, 2014 at 11:47 UTC
d773144417b1a87b4529144ab0530ecfea103754
1 file changed
+5
-6
pack-write.c
+5
-6
@@ -288,13 +288,12 @@ char *index_pack_lockfile(int ip_out)
288
* case, we need it to remove the corresponding .keep file
289
* later on. If we don't get that then tough luck with it.
290
*/
291
- if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n' &&
292
- memcmp(packname, "keep\t", 5) == 0) {
293
- char path[PATH_MAX];
291
+ if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n') {
292
+ const char *name;
293
packname[45] = 0;
295
- snprintf(path, sizeof(path), "%s/pack/pack-%s.keep",
296
- get_object_directory(), packname + 5);
297
- return xstrdup(path);
294
+ if (skip_prefix(packname, "keep\t", &name))
295
+ return xstrfmt("%s/pack/pack-%s.keep",
296
+ get_object_directory(), name);
297
}
298
return NULL;
299
}