aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-07-06 01:11:52 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-06 10:39:58 -0700
commitb2cb94254be7bf8b44c851897dd29a00ce654e3c (patch)
tree350b5b896310eb41ce6786176727a1bc22ef2350 /sha1_file.c
parentff9206e72c71aa2e51c7cbee911f47b5838a5845 (diff)
downloadgit-b2cb94254be7bf8b44c851897dd29a00ce654e3c.tar.gz
git-b2cb94254be7bf8b44c851897dd29a00ce654e3c.tar.xz
[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>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 174727664..fd6096f41 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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[] = {