]>
Commit | Line | Data |
---|---|---|
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 | ||
e99d59ff | 8 | static void safe_create_dir(const char *dir) |
cb126d8d ZW |
9 | { |
10 | if (mkdir(dir, 0755) < 0) { | |
11 | if (errno != EEXIST) { | |
12 | perror(dir); | |
13 | exit(1); | |
14 | } | |
15 | } | |
16 | } | |
17 | ||
cad88fdf LT |
18 | static void create_default_files(const char *git_dir) |
19 | { | |
20 | unsigned len = strlen(git_dir); | |
21 | static char path[PATH_MAX]; | |
22 | ||
23 | if (len > sizeof(path)-50) | |
24 | die("insane git directory %s", git_dir); | |
25 | memcpy(path, git_dir, len); | |
26 | ||
27 | if (len && path[len-1] != '/') | |
28 | path[len++] = '/'; | |
29 | ||
30 | /* | |
31 | * Create .git/refs/{heads,tags} | |
32 | */ | |
33 | strcpy(path + len, "refs"); | |
34 | safe_create_dir(path); | |
35 | strcpy(path + len, "refs/heads"); | |
36 | safe_create_dir(path); | |
37 | strcpy(path + len, "refs/tags"); | |
38 | safe_create_dir(path); | |
39 | ||
40 | /* | |
41 | * Create the default symlink from ".git/HEAD" to the "master" | |
42 | * branch | |
43 | */ | |
44 | strcpy(path + len, "HEAD"); | |
45 | if (symlink("refs/heads/master", path) < 0) { | |
46 | if (errno != EEXIST) { | |
47 | perror(path); | |
48 | exit(1); | |
49 | } | |
50 | } | |
51 | } | |
52 | ||
4696cb93 ZW |
53 | /* |
54 | * If you want to, you can share the DB area with any number of branches. | |
55 | * That has advantages: you can save space by sharing all the SHA1 objects. | |
56 | * On the other hand, it might just make lookup slower and messier. You | |
57 | * be the judge. The default case is to have one DB per managed directory. | |
58 | */ | |
e83c5163 LT |
59 | int main(int argc, char **argv) |
60 | { | |
cad88fdf | 61 | const char *git_dir; |
d19938ab JH |
62 | const char *sha1_dir; |
63 | char *path; | |
19b2860c | 64 | int len, i; |
e83c5163 | 65 | |
cad88fdf LT |
66 | /* |
67 | * Set up the default .git directory contents | |
68 | */ | |
69 | git_dir = gitenv(GIT_DIR_ENVIRONMENT); | |
70 | if (!git_dir) { | |
71 | git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; | |
addb315d | 72 | fprintf(stderr, "defaulting to local storage area\n"); |
e83c5163 | 73 | } |
cad88fdf LT |
74 | safe_create_dir(git_dir); |
75 | create_default_files(git_dir); | |
76 | ||
77 | /* | |
78 | * And set up the object store. | |
79 | */ | |
80 | sha1_dir = get_object_directory(); | |
e83c5163 | 81 | len = strlen(sha1_dir); |
812666c8 | 82 | path = xmalloc(len + 40); |
e83c5163 | 83 | memcpy(path, sha1_dir, len); |
cb126d8d ZW |
84 | |
85 | safe_create_dir(sha1_dir); | |
e83c5163 LT |
86 | for (i = 0; i < 256; i++) { |
87 | sprintf(path+len, "/%02x", i); | |
cb126d8d | 88 | safe_create_dir(path); |
e83c5163 LT |
89 | } |
90 | return 0; | |
91 | } |