3 const char **get_pathspec(const char *prefix, char **pathspec)
5 char *entry = *pathspec;
18 } while ((entry = *++p) != NULL);
19 return (const char **) pathspec;
23 static const char *spec[2];
29 /* Otherwise we have to re-write the entries.. */
30 prefixlen = strlen(prefix);
33 int speclen, len = prefixlen;
37 if (!strcmp(entry, ".")) {
41 if (!strncmp(entry, "./", 2)) {
45 if (!strncmp(entry, "../", 3)) {
48 die("'%s' is outside repository", *p);
50 } while (len && prefix[len-1] != '/');
56 speclen = strlen(entry);
57 n = xmalloc(speclen + len + 1);
59 memcpy(n, prefix, len);
60 memcpy(n + len, entry, speclen+1);
62 } while ((entry = *++p) != NULL);
63 return (const char **) pathspec;
66 const char *setup_git_directory(void)
68 static char cwd[PATH_MAX+1];
72 * If GIT_DIR is set explicitly, we're not going
75 if (gitenv(GIT_DIR_ENVIRONMENT))
78 if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
79 die("Unable to read current working directory");
81 offset = len = strlen(cwd);
84 * We always want to see a .git/HEAD and a .git/refs/
87 if (!access(".git/HEAD", R_OK) && !access(".git/refs/", X_OK)) {
89 * Then we need either a GIT_OBJECT_DIRECTORY define
90 * or a .git/objects/ directory
92 if (gitenv(DB_ENVIRONMENT) || !access(".git/objects/", X_OK))
98 die("Not a git repository");
99 } while (cwd[--offset] != '/');
105 /* Make "offset" point to past the '/', and add a '/' at the end */