-rw-r--r-- | scan-tree.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/scan-tree.c b/scan-tree.c index 9bf9b38..a83a78c 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -36,96 +36,99 @@ static int is_git_dir(const char *path) | |||
36 | if (stat(buf, &st)) { | 36 | if (stat(buf, &st)) { |
37 | if (errno != ENOENT) | 37 | if (errno != ENOENT) |
38 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 38 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
39 | path, strerror(errno), errno); | 39 | path, strerror(errno), errno); |
40 | return 0; | 40 | return 0; |
41 | } | 41 | } |
42 | if (!S_ISREG(st.st_mode)) | 42 | if (!S_ISREG(st.st_mode)) |
43 | return 0; | 43 | return 0; |
44 | 44 | ||
45 | return 1; | 45 | return 1; |
46 | } | 46 | } |
47 | 47 | ||
48 | struct cgit_repo *repo; | 48 | struct cgit_repo *repo; |
49 | repo_config_fn config_fn; | 49 | repo_config_fn config_fn; |
50 | 50 | ||
51 | static void repo_config(const char *name, const char *value) | 51 | static void repo_config(const char *name, const char *value) |
52 | { | 52 | { |
53 | config_fn(repo, name, value); | 53 | config_fn(repo, name, value); |
54 | } | 54 | } |
55 | 55 | ||
56 | static void add_repo(const char *base, const char *path, repo_config_fn fn) | 56 | static void add_repo(const char *base, const char *path, repo_config_fn fn) |
57 | { | 57 | { |
58 | struct stat st; | 58 | struct stat st; |
59 | struct passwd *pwd; | 59 | struct passwd *pwd; |
60 | char *p; | 60 | char *p; |
61 | size_t size; | 61 | size_t size; |
62 | 62 | ||
63 | if (stat(path, &st)) { | 63 | if (stat(path, &st)) { |
64 | fprintf(stderr, "Error accessing %s: %s (%d)\n", | 64 | fprintf(stderr, "Error accessing %s: %s (%d)\n", |
65 | path, strerror(errno), errno); | 65 | path, strerror(errno), errno); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | if (!stat(fmt("%s/noweb", path), &st)) | 68 | if (!stat(fmt("%s/noweb", path), &st)) |
69 | return; | 69 | return; |
70 | if ((pwd = getpwuid(st.st_uid)) == NULL) { | 70 | if ((pwd = getpwuid(st.st_uid)) == NULL) { |
71 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", | 71 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", |
72 | path, strerror(errno), errno); | 72 | path, strerror(errno), errno); |
73 | return; | 73 | return; |
74 | } | 74 | } |
75 | if (base == path) | 75 | if (base == path) |
76 | p = fmt("%s", path); | 76 | p = fmt("%s", path); |
77 | else | 77 | else |
78 | p = fmt("%s", path + strlen(base) + 1); | 78 | p = fmt("%s", path + strlen(base) + 1); |
79 | 79 | ||
80 | if (!strcmp(p + strlen(p) - 5, "/.git")) | 80 | if (!strcmp(p + strlen(p) - 5, "/.git")) |
81 | p[strlen(p) - 5] = '\0'; | 81 | p[strlen(p) - 5] = '\0'; |
82 | 82 | ||
83 | repo = cgit_add_repo(xstrdup(p)); | 83 | repo = cgit_add_repo(xstrdup(p)); |
84 | if (ctx.cfg.remove_suffix) | ||
85 | if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) | ||
86 | *p = '\0'; | ||
84 | repo->name = repo->url; | 87 | repo->name = repo->url; |
85 | repo->path = xstrdup(path); | 88 | repo->path = xstrdup(path); |
86 | p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; | 89 | p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; |
87 | if (p) | 90 | if (p) |
88 | *p = '\0'; | 91 | *p = '\0'; |
89 | repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); | 92 | repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); |
90 | 93 | ||
91 | p = fmt("%s/description", path); | 94 | p = fmt("%s/description", path); |
92 | if (!stat(p, &st)) | 95 | if (!stat(p, &st)) |
93 | readfile(p, &repo->desc, &size); | 96 | readfile(p, &repo->desc, &size); |
94 | 97 | ||
95 | p = fmt("%s/README.html", path); | 98 | p = fmt("%s/README.html", path); |
96 | if (!stat(p, &st)) | 99 | if (!stat(p, &st)) |
97 | repo->readme = "README.html"; | 100 | repo->readme = "README.html"; |
98 | 101 | ||
99 | p = fmt("%s/cgitrc", path); | 102 | p = fmt("%s/cgitrc", path); |
100 | if (!stat(p, &st)) { | 103 | if (!stat(p, &st)) { |
101 | config_fn = fn; | 104 | config_fn = fn; |
102 | parse_configfile(xstrdup(p), &repo_config); | 105 | parse_configfile(xstrdup(p), &repo_config); |
103 | } | 106 | } |
104 | } | 107 | } |
105 | 108 | ||
106 | static void scan_path(const char *base, const char *path, repo_config_fn fn) | 109 | static void scan_path(const char *base, const char *path, repo_config_fn fn) |
107 | { | 110 | { |
108 | DIR *dir; | 111 | DIR *dir; |
109 | struct dirent *ent; | 112 | struct dirent *ent; |
110 | char *buf; | 113 | char *buf; |
111 | struct stat st; | 114 | struct stat st; |
112 | 115 | ||
113 | if (is_git_dir(path)) { | 116 | if (is_git_dir(path)) { |
114 | add_repo(base, path, fn); | 117 | add_repo(base, path, fn); |
115 | return; | 118 | return; |
116 | } | 119 | } |
117 | if (is_git_dir(fmt("%s/.git", path))) { | 120 | if (is_git_dir(fmt("%s/.git", path))) { |
118 | add_repo(base, fmt("%s/.git", path), fn); | 121 | add_repo(base, fmt("%s/.git", path), fn); |
119 | return; | 122 | return; |
120 | } | 123 | } |
121 | dir = opendir(path); | 124 | dir = opendir(path); |
122 | if (!dir) { | 125 | if (!dir) { |
123 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", | 126 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", |
124 | path, strerror(errno), errno); | 127 | path, strerror(errno), errno); |
125 | return; | 128 | return; |
126 | } | 129 | } |
127 | while((ent = readdir(dir)) != NULL) { | 130 | while((ent = readdir(dir)) != NULL) { |
128 | if (ent->d_name[0] == '.') { | 131 | if (ent->d_name[0] == '.') { |
129 | if (ent->d_name[1] == '\0') | 132 | if (ent->d_name[1] == '\0') |
130 | continue; | 133 | continue; |
131 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') | 134 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') |