[PATCH] Ensure list insertion method does not depend on position of --merge-order...
[git.git] / sha1_file.c
index bbb749c..fd6096f 100644 (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[] = {
@@ -463,6 +482,7 @@ static void prepare_packed_git_one(char *objdir)
                p->next = packed_git;
                packed_git = p;
        }
+       closedir(dir);
 }
 
 void prepare_packed_git(void)