Skip to content

Commit afbba2f

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 597f913 commit afbba2f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

sha1_file.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
178178
for (i = 0; i < 20; i++) {
179179
static char hex[] = "0123456789abcdef";
180180
unsigned int val = sha1[i];
181-
char *pos = pathbuf + i*2 + (i > 0);
182-
*pos++ = hex[val >> 4];
183-
*pos = hex[val & 0xf];
181+
*pathbuf++ = hex[val >> 4];
182+
*pathbuf++ = hex[val & 0xf];
183+
if (!i)
184+
*pathbuf++ = '/';
184185
}
186+
*pathbuf = '\0';
185187
}
186188

187189
const char *sha1_file_name(const unsigned char *sha1)
@@ -198,8 +200,6 @@ const char *sha1_file_name(const unsigned char *sha1)
198200
die("insanely long object directory %s", objdir);
199201
memcpy(buf, objdir, len);
200202
buf[len] = '/';
201-
buf[len+3] = '/';
202-
buf[len+42] = '\0';
203203
fill_sha1_path(buf + len + 1, sha1);
204204
return buf;
205205
}
@@ -406,8 +406,6 @@ struct alternate_object_database *alloc_alt_odb(const char *dir)
406406

407407
ent->name = ent->scratch + dirlen + 1;
408408
ent->scratch[dirlen] = '/';
409-
ent->scratch[dirlen + 3] = '/';
410-
ent->scratch[entlen-1] = 0;
411409

412410
return ent;
413411
}

0 commit comments

Comments
 (0)