summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-10-03 20:35:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-10-10 20:52:36 (GMT)
commitafbba2f09ab06424d8b38908f4d76a1503f49a25 (patch)
tree345101f3da324d530ac0fe8ffc2cb9f0d164954e /sha1_file.c
parent597f9134ded20f882e2bf6bca8b0e1f03981b98d (diff)
downloadgit-afbba2f09ab06424d8b38908f4d76a1503f49a25.zip
git-afbba2f09ab06424d8b38908f4d76a1503f49a25.tar.gz
git-afbba2f09ab06424d8b38908f4d76a1503f49a25.tar.bz2
fill_sha1_file: write "boring" characters
This function forms a sha1 as "xx/yyyy...", but skips over the slot for the slash rather than writing it, leaving it to the caller to do so. It also does not bother to put in a trailing NUL, even though every caller would want it (we're forming a path which by definition is not a directory, so the only thing to do with it is feed it to a system call). Let's make the lives of our callers easier by just writing out the internal "/" and the NUL. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 011532a..da7b922 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -178,10 +178,12 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
for (i = 0; i < 20; i++) {
static char hex[] = "0123456789abcdef";
unsigned int val = sha1[i];
- char *pos = pathbuf + i*2 + (i > 0);
- *pos++ = hex[val >> 4];
- *pos = hex[val & 0xf];
+ *pathbuf++ = hex[val >> 4];
+ *pathbuf++ = hex[val & 0xf];
+ if (!i)
+ *pathbuf++ = '/';
}
+ *pathbuf = '\0';
}
const char *sha1_file_name(const unsigned char *sha1)
@@ -198,8 +200,6 @@ const char *sha1_file_name(const unsigned char *sha1)
die("insanely long object directory %s", objdir);
memcpy(buf, objdir, len);
buf[len] = '/';
- buf[len+3] = '/';
- buf[len+42] = '\0';
fill_sha1_path(buf + len + 1, sha1);
return buf;
}
@@ -406,8 +406,6 @@ struct alternate_object_database *alloc_alt_odb(const char *dir)
ent->name = ent->scratch + dirlen + 1;
ent->scratch[dirlen] = '/';
- ent->scratch[dirlen + 3] = '/';
- ent->scratch[entlen-1] = 0;
return ent;
}