Initial revision of "git", the information manager from hell
[git/graveyard.git] / init-db.c
blob25dc13fe101b219f74007f3194b787dd99e863da
1 #include "cache.h"
3 int main(int argc, char **argv)
5 char *sha1_dir = getenv(DB_ENVIRONMENT), *path;
6 int len, i, fd;
8 if (mkdir(".dircache", 0700) < 0) {
9 perror("unable to create .dircache");
10 exit(1);
14 * If you want to, you can share the DB area with any number of branches.
15 * That has advantages: you can save space by sharing all the SHA1 objects.
16 * On the other hand, it might just make lookup slower and messier. You
17 * be the judge.
19 sha1_dir = getenv(DB_ENVIRONMENT);
20 if (sha1_dir) {
21 struct stat st;
22 if (!stat(sha1_dir, &st) < 0 && S_ISDIR(st.st_mode))
23 return;
24 fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir);
28 * The default case is to have a DB per managed directory.
30 sha1_dir = DEFAULT_DB_ENVIRONMENT;
31 fprintf(stderr, "defaulting to private storage area\n");
32 len = strlen(sha1_dir);
33 if (mkdir(sha1_dir, 0700) < 0) {
34 if (errno != EEXIST) {
35 perror(sha1_dir);
36 exit(1);
39 path = malloc(len + 40);
40 memcpy(path, sha1_dir, len);
41 for (i = 0; i < 256; i++) {
42 sprintf(path+len, "/%02x", i);
43 if (mkdir(path, 0700) < 0) {
44 if (errno != EEXIST) {
45 perror(path);
46 exit(1);
50 return 0;