[PATCH] clone-pack.c:write_one_ref() - Create leading directories.

The function write_one_ref() is passed the list of refs received
from the other end, which was obtained by directory traversal
under $GIT_DIR/refs; this can contain paths other than what
git-init-db prepares and would fail to clone when there is
such.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Junio C Hamano
2005-07-06 01:11:52 -07:00
committed by Linus Torvalds
parent ff9206e72c
commit b2cb94254b
3 changed files with 25 additions and 1 deletions

View File

@ -130,6 +130,25 @@ char *git_path(const char *fmt, ...)
return ret;
}
int safe_create_leading_directories(char *path)
{
char *pos = path;
while (pos) {
pos = strchr(pos, '/');
if (!pos)
break;
*pos = 0;
if (mkdir(path, 0777) < 0)
if (errno != EEXIST) {
*pos = '/';
return -1;
}
*pos++ = '/';
}
return 0;
}
int get_sha1(const char *str, unsigned char *sha1)
{
static const char *prefix[] = {