return git_index_file;
}
+char *git_path(const char *fmt, ...)
+{
+ static char pathname[PATH_MAX], *ret;
+ va_list args;
+ int len;
+
+ if (!git_dir)
+ setup_git_env();
+ len = strlen(git_dir);
+ if (len > PATH_MAX-100)
+ return "pad-path";
+ memcpy(pathname, git_dir, len);
+ if (len && git_dir[len-1] != '/')
+ pathname[len++] = '/';
+ va_start(args, fmt);
+ vsnprintf(pathname + len, sizeof(pathname) - len, fmt, args);
+ va_end(args);
+ ret = pathname;
+
+ /* Clean it up */
+ if (!memcmp(pathname, "./", 2)) {
+ ret += 2;
+ while (*ret == '/')
+ ret++;
+ }
+ 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 char pathname[PATH_MAX];
static const char *prefix[] = {
"",
"refs",
if (!get_sha1_hex(str, sha1))
return 0;
- if (!git_dir)
- setup_git_env();
for (p = prefix; *p; p++) {
- snprintf(pathname, sizeof(pathname), "%s/%s/%s",
- git_dir, *p, str);
+ char * pathname = git_path("%s/%s", *p, str);
if (!get_sha1_file(pathname, sha1))
return 0;
}
p->next = packed_git;
packed_git = p;
}
+ closedir(dir);
}
void prepare_packed_git(void)
return inflate(stream, 0);
}
-void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size)
+static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size)
{
int bytes = strlen(buffer) + 1;
unsigned char *buf = xmalloc(1+size);
return 0;
}
+int has_sha1_pack(const unsigned char *sha1)
+{
+ struct pack_entry e;
+ return find_pack_entry(sha1, &e);
+}
+
int has_sha1_file(const unsigned char *sha1)
{
struct stat st;