author | Jason A. Donenfeld <Jason@zx2c4.com> | 2010-07-29 17:47:50 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-08-04 01:09:32 (UTC) |
commit | 2e4a941626c240bc7858aa7564882c01f657f4e8 (patch) (unidiff) | |
tree | 505c17fab5afcb99cfddf2c4aad0b95c8670f001 /scan-tree.c | |
parent | 3516502aa0df95ecc241caa30161741f59e4e600 (diff) | |
download | cgit-2e4a941626c240bc7858aa7564882c01f657f4e8.zip cgit-2e4a941626c240bc7858aa7564882c01f657f4e8.tar.gz cgit-2e4a941626c240bc7858aa7564882c01f657f4e8.tar.bz2 |
Add support for 'remove-suffix' option
When this option is enabled, the '.git' suffix of repository directories
found while processing the 'scan-path' option will be removed.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-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 | |||
@@ -60,48 +60,51 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
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 | { |