Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
pack-write: simplify index_pack_lockfile using skip_prefix() and xstr…
…fmt()

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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Sep 2, 2014
1 parent be0b3f8 commit d773144
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pack-write.c
Expand Up @@ -288,13 +288,12 @@ char *index_pack_lockfile(int ip_out)
* case, we need it to remove the corresponding .keep file
* later on. If we don't get that then tough luck with it.
*/
if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n' &&
memcmp(packname, "keep\t", 5) == 0) {
char path[PATH_MAX];
if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n') {
const char *name;
packname[45] = 0;
snprintf(path, sizeof(path), "%s/pack/pack-%s.keep",
get_object_directory(), packname + 5);
return xstrdup(path);
if (skip_prefix(packname, "keep\t", &name))
return xstrfmt("%s/pack/pack-%s.keep",
get_object_directory(), name);
}
return NULL;
}
Expand Down

0 comments on commit d773144

Please sign in to comment.