]> git.ipfire.org Git - thirdparty/git.git/blame - init-db.c
Make "fsck-cache" use the same revision tracking structure as "rev-tree".
[thirdparty/git.git] / init-db.c
CommitLineData
8bc9a0c7
LT
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
e83c5163
LT
6#include "cache.h"
7
8int main(int argc, char **argv)
9{
10 char *sha1_dir = getenv(DB_ENVIRONMENT), *path;
19b2860c 11 int len, i;
e83c5163 12
4bb04f21
LT
13 if (mkdir(".git", 0755) < 0) {
14 perror("unable to create .git directory");
e83c5163
LT
15 exit(1);
16 }
17
18 /*
19 * If you want to, you can share the DB area with any number of branches.
20 * That has advantages: you can save space by sharing all the SHA1 objects.
21 * On the other hand, it might just make lookup slower and messier. You
22 * be the judge.
23 */
24 sha1_dir = getenv(DB_ENVIRONMENT);
25 if (sha1_dir) {
26 struct stat st;
27 if (!stat(sha1_dir, &st) < 0 && S_ISDIR(st.st_mode))
19b2860c 28 return 0;
e83c5163
LT
29 fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir);
30 }
31
32 /*
aebb2679 33 * The default case is to have a DB per managed directory.
e83c5163
LT
34 */
35 sha1_dir = DEFAULT_DB_ENVIRONMENT;
36 fprintf(stderr, "defaulting to private storage area\n");
37 len = strlen(sha1_dir);
cfd88e2b 38 if (mkdir(sha1_dir, 0755) < 0) {
e83c5163
LT
39 if (errno != EEXIST) {
40 perror(sha1_dir);
41 exit(1);
42 }
43 }
44 path = malloc(len + 40);
45 memcpy(path, sha1_dir, len);
46 for (i = 0; i < 256; i++) {
47 sprintf(path+len, "/%02x", i);
cfd88e2b 48 if (mkdir(path, 0755) < 0) {
e83c5163
LT
49 if (errno != EEXIST) {
50 perror(path);
51 exit(1);
52 }
53 }
54 }
55 return 0;
56}