author | Lars Hjemli <hjemli@gmail.com> | 2010-06-19 09:41:32 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-06-19 09:41:32 (UTC) |
commit | caf0825d97582d137387b8879867247e92cca022 (patch) (unidiff) | |
tree | f330d875b3846467a2167ab83168b5b6cea29cdc | |
parent | d6dc3aee9acadfe368864f24ea18ccd47bbb0b9b (diff) | |
parent | 31ba37c0a44f152005fbb8ab49c05462fb741fd6 (diff) | |
download | cgit-caf0825d97582d137387b8879867247e92cca022.zip cgit-caf0825d97582d137387b8879867247e92cca022.tar.gz cgit-caf0825d97582d137387b8879867247e92cca022.tar.bz2 |
Merge branch 'lh/noweb'
-rw-r--r-- | scan-tree.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/scan-tree.c b/scan-tree.c index dbca797..1e18f3c 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -1,146 +1,148 @@ | |||
1 | #include "cgit.h" | 1 | #include "cgit.h" |
2 | #include "configfile.h" | 2 | #include "configfile.h" |
3 | #include "html.h" | 3 | #include "html.h" |
4 | 4 | ||
5 | #define MAX_PATH 4096 | 5 | #define MAX_PATH 4096 |
6 | 6 | ||
7 | /* return 1 if path contains a objects/ directory and a HEAD file */ | 7 | /* return 1 if path contains a objects/ directory and a HEAD file */ |
8 | static int is_git_dir(const char *path) | 8 | static int is_git_dir(const char *path) |
9 | { | 9 | { |
10 | struct stat st; | 10 | struct stat st; |
11 | static char buf[MAX_PATH]; | 11 | static char buf[MAX_PATH]; |
12 | 12 | ||
13 | if (snprintf(buf, MAX_PATH, "%s/objects", path) >= MAX_PATH) { | 13 | if (snprintf(buf, MAX_PATH, "%s/objects", path) >= MAX_PATH) { |
14 | fprintf(stderr, "Insanely long path: %s\n", path); | 14 | fprintf(stderr, "Insanely long path: %s\n", path); |
15 | return 0; | 15 | return 0; |
16 | } | 16 | } |
17 | if (stat(buf, &st)) { | 17 | if (stat(buf, &st)) { |
18 | if (errno != ENOENT) | 18 | if (errno != ENOENT) |
19 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 19 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
20 | path, strerror(errno), errno); | 20 | path, strerror(errno), errno); |
21 | return 0; | 21 | return 0; |
22 | } | 22 | } |
23 | if (!S_ISDIR(st.st_mode)) | 23 | if (!S_ISDIR(st.st_mode)) |
24 | return 0; | 24 | return 0; |
25 | 25 | ||
26 | sprintf(buf, "%s/HEAD", path); | 26 | sprintf(buf, "%s/HEAD", path); |
27 | if (stat(buf, &st)) { | 27 | if (stat(buf, &st)) { |
28 | if (errno != ENOENT) | 28 | if (errno != ENOENT) |
29 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 29 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
30 | path, strerror(errno), errno); | 30 | path, strerror(errno), errno); |
31 | return 0; | 31 | return 0; |
32 | } | 32 | } |
33 | if (!S_ISREG(st.st_mode)) | 33 | if (!S_ISREG(st.st_mode)) |
34 | return 0; | 34 | return 0; |
35 | 35 | ||
36 | return 1; | 36 | return 1; |
37 | } | 37 | } |
38 | 38 | ||
39 | struct cgit_repo *repo; | 39 | struct cgit_repo *repo; |
40 | repo_config_fn config_fn; | 40 | repo_config_fn config_fn; |
41 | 41 | ||
42 | static void repo_config(const char *name, const char *value) | 42 | static void repo_config(const char *name, const char *value) |
43 | { | 43 | { |
44 | config_fn(repo, name, value); | 44 | config_fn(repo, name, value); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void add_repo(const char *base, const char *path, repo_config_fn fn) | 47 | static void add_repo(const char *base, const char *path, repo_config_fn fn) |
48 | { | 48 | { |
49 | struct stat st; | 49 | struct stat st; |
50 | struct passwd *pwd; | 50 | struct passwd *pwd; |
51 | char *p; | 51 | char *p; |
52 | size_t size; | 52 | size_t size; |
53 | 53 | ||
54 | if (stat(path, &st)) { | 54 | if (stat(path, &st)) { |
55 | fprintf(stderr, "Error accessing %s: %s (%d)\n", | 55 | fprintf(stderr, "Error accessing %s: %s (%d)\n", |
56 | path, strerror(errno), errno); | 56 | path, strerror(errno), errno); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | if (!stat(fmt("%s/noweb", path), &st)) | ||
60 | return; | ||
59 | if ((pwd = getpwuid(st.st_uid)) == NULL) { | 61 | if ((pwd = getpwuid(st.st_uid)) == NULL) { |
60 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", | 62 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", |
61 | path, strerror(errno), errno); | 63 | path, strerror(errno), errno); |
62 | return; | 64 | return; |
63 | } | 65 | } |
64 | if (base == path) | 66 | if (base == path) |
65 | p = fmt("%s", path); | 67 | p = fmt("%s", path); |
66 | else | 68 | else |
67 | p = fmt("%s", path + strlen(base) + 1); | 69 | p = fmt("%s", path + strlen(base) + 1); |
68 | 70 | ||
69 | if (!strcmp(p + strlen(p) - 5, "/.git")) | 71 | if (!strcmp(p + strlen(p) - 5, "/.git")) |
70 | p[strlen(p) - 5] = '\0'; | 72 | p[strlen(p) - 5] = '\0'; |
71 | 73 | ||
72 | repo = cgit_add_repo(xstrdup(p)); | 74 | repo = cgit_add_repo(xstrdup(p)); |
73 | repo->name = repo->url; | 75 | repo->name = repo->url; |
74 | repo->path = xstrdup(path); | 76 | repo->path = xstrdup(path); |
75 | p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; | 77 | p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; |
76 | if (p) | 78 | if (p) |
77 | *p = '\0'; | 79 | *p = '\0'; |
78 | repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); | 80 | repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); |
79 | 81 | ||
80 | p = fmt("%s/description", path); | 82 | p = fmt("%s/description", path); |
81 | if (!stat(p, &st)) | 83 | if (!stat(p, &st)) |
82 | readfile(p, &repo->desc, &size); | 84 | readfile(p, &repo->desc, &size); |
83 | 85 | ||
84 | p = fmt("%s/README.html", path); | 86 | p = fmt("%s/README.html", path); |
85 | if (!stat(p, &st)) | 87 | if (!stat(p, &st)) |
86 | repo->readme = "README.html"; | 88 | repo->readme = "README.html"; |
87 | 89 | ||
88 | p = fmt("%s/cgitrc", path); | 90 | p = fmt("%s/cgitrc", path); |
89 | if (!stat(p, &st)) { | 91 | if (!stat(p, &st)) { |
90 | config_fn = fn; | 92 | config_fn = fn; |
91 | parse_configfile(xstrdup(p), &repo_config); | 93 | parse_configfile(xstrdup(p), &repo_config); |
92 | } | 94 | } |
93 | } | 95 | } |
94 | 96 | ||
95 | static void scan_path(const char *base, const char *path, repo_config_fn fn) | 97 | static void scan_path(const char *base, const char *path, repo_config_fn fn) |
96 | { | 98 | { |
97 | DIR *dir; | 99 | DIR *dir; |
98 | struct dirent *ent; | 100 | struct dirent *ent; |
99 | char *buf; | 101 | char *buf; |
100 | struct stat st; | 102 | struct stat st; |
101 | 103 | ||
102 | if (is_git_dir(path)) { | 104 | if (is_git_dir(path)) { |
103 | add_repo(base, path, fn); | 105 | add_repo(base, path, fn); |
104 | return; | 106 | return; |
105 | } | 107 | } |
106 | if (is_git_dir(fmt("%s/.git", path))) { | 108 | if (is_git_dir(fmt("%s/.git", path))) { |
107 | add_repo(base, fmt("%s/.git", path), fn); | 109 | add_repo(base, fmt("%s/.git", path), fn); |
108 | return; | 110 | return; |
109 | } | 111 | } |
110 | dir = opendir(path); | 112 | dir = opendir(path); |
111 | if (!dir) { | 113 | if (!dir) { |
112 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", | 114 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", |
113 | path, strerror(errno), errno); | 115 | path, strerror(errno), errno); |
114 | return; | 116 | return; |
115 | } | 117 | } |
116 | while((ent = readdir(dir)) != NULL) { | 118 | while((ent = readdir(dir)) != NULL) { |
117 | if (ent->d_name[0] == '.') { | 119 | if (ent->d_name[0] == '.') { |
118 | if (ent->d_name[1] == '\0') | 120 | if (ent->d_name[1] == '\0') |
119 | continue; | 121 | continue; |
120 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') | 122 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') |
121 | continue; | 123 | continue; |
122 | } | 124 | } |
123 | buf = malloc(strlen(path) + strlen(ent->d_name) + 2); | 125 | buf = malloc(strlen(path) + strlen(ent->d_name) + 2); |
124 | if (!buf) { | 126 | if (!buf) { |
125 | fprintf(stderr, "Alloc error on %s: %s (%d)\n", | 127 | fprintf(stderr, "Alloc error on %s: %s (%d)\n", |
126 | path, strerror(errno), errno); | 128 | path, strerror(errno), errno); |
127 | exit(1); | 129 | exit(1); |
128 | } | 130 | } |
129 | sprintf(buf, "%s/%s", path, ent->d_name); | 131 | sprintf(buf, "%s/%s", path, ent->d_name); |
130 | if (stat(buf, &st)) { | 132 | if (stat(buf, &st)) { |
131 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 133 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
132 | buf, strerror(errno), errno); | 134 | buf, strerror(errno), errno); |
133 | free(buf); | 135 | free(buf); |
134 | continue; | 136 | continue; |
135 | } | 137 | } |
136 | if (S_ISDIR(st.st_mode)) | 138 | if (S_ISDIR(st.st_mode)) |
137 | scan_path(base, buf, fn); | 139 | scan_path(base, buf, fn); |
138 | free(buf); | 140 | free(buf); |
139 | } | 141 | } |
140 | closedir(dir); | 142 | closedir(dir); |
141 | } | 143 | } |
142 | 144 | ||
143 | void scan_tree(const char *path, repo_config_fn fn) | 145 | void scan_tree(const char *path, repo_config_fn fn) |
144 | { | 146 | { |
145 | scan_path(path, path, fn); | 147 | scan_path(path, path, fn); |
146 | } | 148 | } |