Skip to content

Commit

Permalink
Remove redundant code, eliminate one static variable
Browse files Browse the repository at this point in the history
Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Heikki Orsila authored and Junio C Hamano committed May 25, 2008
1 parent 998b912 commit 633f43e
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,54 +176,44 @@ char *sha1_file_name(const unsigned char *sha1)
return base;
}

char *sha1_pack_name(const unsigned char *sha1)
static char *sha1_get_pack_name(const unsigned char *sha1,
char **name, char **base)
{
static const char hex[] = "0123456789abcdef";
static char *name, *base, *buf;
char *buf;
int i;

if (!base) {
if (!*base) {
const char *sha1_file_directory = get_object_directory();
int len = strlen(sha1_file_directory);
base = xmalloc(len + 60);
sprintf(base, "%s/pack/pack-1234567890123456789012345678901234567890.pack", sha1_file_directory);
name = base + len + 11;
*base = xmalloc(len + 60);
sprintf(*base, "%s/pack/pack-1234567890123456789012345678901234567890.pack", sha1_file_directory);
*name = *base + len + 11;
}

buf = name;
buf = *name;

for (i = 0; i < 20; i++) {
unsigned int val = *sha1++;
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}

return base;
return *base;
}

char *sha1_pack_index_name(const unsigned char *sha1)
char *sha1_pack_name(const unsigned char *sha1)
{
static const char hex[] = "0123456789abcdef";
static char *name, *base, *buf;
int i;

if (!base) {
const char *sha1_file_directory = get_object_directory();
int len = strlen(sha1_file_directory);
base = xmalloc(len + 60);
sprintf(base, "%s/pack/pack-1234567890123456789012345678901234567890.idx", sha1_file_directory);
name = base + len + 11;
}
static char *name, *base;

buf = name;
return sha1_get_pack_name(sha1, &name, &base);
}

for (i = 0; i < 20; i++) {
unsigned int val = *sha1++;
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}
char *sha1_pack_index_name(const unsigned char *sha1)
{
static char *name, *base;

return base;
return sha1_get_pack_name(sha1, &name, &base);
}

struct alternate_object_database *alt_odb_list;
Expand Down

0 comments on commit 633f43e

Please sign in to comment.