3 char *prefix_path(const char *prefix, int len, char *path)
31 /* Remove last component of the prefix */
34 die("'%s' is outside repository", orig);
36 } while (len && prefix[len-1] != '/');
40 int speclen = strlen(path);
41 char *n = xmalloc(speclen + len + 1);
43 memcpy(n, prefix, len);
44 memcpy(n + len, path, speclen+1);
50 const char **get_pathspec(const char *prefix, char **pathspec)
52 char *entry = *pathspec;
56 if (!prefix && !entry)
60 static const char *spec[2];
66 /* Otherwise we have to re-write the entries.. */
68 prefixlen = prefix ? strlen(prefix) : 0;
70 *p = prefix_path(prefix, prefixlen, entry);
71 } while ((entry = *++p) != NULL);
72 return (const char **) pathspec;
75 const char *setup_git_directory(void)
77 static char cwd[PATH_MAX+1];
81 * If GIT_DIR is set explicitly, we're not going
84 if (gitenv(GIT_DIR_ENVIRONMENT))
87 if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
88 die("Unable to read current working directory");
90 offset = len = strlen(cwd);
93 * We always want to see a .git/refs/ subdirectory
95 if (!access(".git/refs/", X_OK)) {
97 * Then we need either a GIT_OBJECT_DIRECTORY define
98 * or a .git/objects/ directory
100 if (gitenv(DB_ENVIRONMENT) || !access(".git/objects/", X_OK))
106 die("Not a git repository");
107 } while (cwd[--offset] != '/');
113 /* Make "offset" point to past the '/', and add a '/' at the end */