History

Merge branch 'lh/readme'

Lars Hjemli committed 16 years ago

Commit e76a1ea2 parents 857696d 515edb06 files · +43 −24Browse files

Unified · Split

6 files
  1. cgit.c +3 −5
  2. cgit.h +1 −0
  3. cgitrc.5.txt +5 −1
  4. scan-tree.c +5 −3
  5. shared.c +1 −1
  6. ui-summary.c +28 −14
cgit.c+3−5
@@ -72,11 +72,7 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) · 71 unmodified lines
7272 else if (!strcmp(name, "section"))
7373 repo->section = xstrdup(value);
7474 else if (!strcmp(name, "readme") && value != NULL) {
75− char *colon;
76− if (*value == '/' || ((colon = strchr(value, ':')) != NULL && colon != value && *(colon + 1) != '\0'))
77− repo->readme = xstrdup(value);
78− else
79− repo->readme = xstrdup(fmt("%s/%s", repo->path, value));
75+ repo->readme = xstrdup(value);
8076 } else if (ctx.cfg.enable_filter_overrides) {
8177 if (!strcmp(name, "about-filter"))
8278 repo->about_filter = new_filter(value, 0);
@@ -97,6 +93,8 @@ void config_cb(const char *name, const char *value) · 14 unmodified lines
9793 ctx.repo->path = trim_end(value, '/');
9894 else if (ctx.repo && !prefixcmp(name, "repo."))
9995 repo_config(ctx.repo, name + 5, value);
96+ else if (!strcmp(name, "readme"))
97+ ctx.cfg.readme = xstrdup(value);
10098 else if (!strcmp(name, "root-title"))
10199 ctx.cfg.root_title = xstrdup(value);
102100 else if (!strcmp(name, "root-desc"))
cgit.h+1−0
@@ -168,6 +168,7 @@ struct cgit_config { · 167 unmodified lines
168168 char *logo_link;
169169 char *module_link;
170170 char *project_list;
171+ char *readme;
171172 char *robots;
172173 char *root_title;
173174 char *root_desc;
cgitrc.5.txt+5−1
@@ -234,6 +234,10 @@ project-list:: · 233 unmodified lines
234234 should loaded as git repositories. This must be defined prior to
235235 scan-path. Default value: none. See also: scan-path.
236236
237+readme::
238+ Text which will be used as default value for "repo.readme". Default
239+ value: none.
240+
237241 remove-suffix::
238242 If set to "1" and scan-path is enabled, if any repositories are found
239243 with a suffix of ".git", this suffix will be removed for the url and
@@ -373,7 +377,7 @@ repo.readme:: · 133 unmodified lines
373377 A path (relative to <repo.path>) which specifies a file to include
374378 verbatim as the "About" page for this repo. You may also specify a
375379 git refspec by head or by hash by prepending the refspec followed by
376− a colon. For example, "master:docs/readme.mkd" Default value: none.
380+ a colon. For example, "master:docs/readme.mkd" Default value: <readme>.
377381
378382 repo.snapshots::
379383 A mask of allowed snapshot-formats for this repo, restricted by the
scan-tree.c+5−3
@@ -110,9 +110,11 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) · 109 unmodified lines
110110 if (!stat(p, &st))
111111 readfile(p, &repo->desc, &size);
112112
113− p = fmt("%s/README.html", path);
114− if (!stat(p, &st))
115− repo->readme = "README.html";
113+ if (!repo->readme) {
114+ p = fmt("%s/README.html", path);
115+ if (!stat(p, &st))
116+ repo->readme = "README.html";
117+ }
116118
117119 p = fmt("%s/cgitrc", path);
118120 if (!stat(p, &st)) {
shared.c+1−1
@@ -62,7 +62,7 @@ struct cgit_repo *cgit_add_repo(const char *url) · 61 unmodified lines
6262 ret->enable_subject_links = ctx.cfg.enable_subject_links;
6363 ret->max_stats = ctx.cfg.max_stats;
6464 ret->module_link = ctx.cfg.module_link;
65− ret->readme = NULL;
65+ ret->readme = ctx.cfg.readme;
6666 ret->mtime = -1;
6767 ret->about_filter = ctx.cfg.about_filter;
6868 ret->commit_filter = ctx.cfg.commit_filter;
ui-summary.c+28−14
@@ -70,33 +70,47 @@ void cgit_print_summary() · 69 unmodified lines
7070
7171 void cgit_print_repo_readme(char *path)
7272 {
73− char *slash, *tmp, *colon, *ref = 0;
73+ char *slash, *tmp, *colon, *ref;
7474
75− if (!ctx.repo->readme)
75+ if (!ctx.repo->readme || !(*ctx.repo->readme))
7676 return;
7777
78+ ref = NULL;
79+
80+ /* Check if the readme is tracked in the git repo. */
81+ colon = strchr(ctx.repo->readme, ':');
82+ if (colon && strlen(colon) > 1) {
83+ *colon = '\0';
84+ ref = ctx.repo->readme;
85+ ctx.repo->readme = colon + 1;
86+ if (!(*ctx.repo->readme))
87+ return;
88+ }
89+
90+ /* Prepend repo path to relative readme path unless tracked. */
91+ if (!ref && *ctx.repo->readme != '/')
92+ ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path,
93+ ctx.repo->readme));
94+
95+ /* If a subpath is specified for the about page, make it relative
96+ * to the directory containing the configured readme.
97+ */
7898 if (path) {
7999 slash = strrchr(ctx.repo->readme, '/');
80100 if (!slash) {
81− slash = strchr(ctx.repo->readme, ':');
82− if (!slash)
101+ if (!colon)
83102 return;
103+ slash = colon;
84104 }
85105 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
86106 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
87107 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
88108 } else
89109 tmp = ctx.repo->readme;
90− colon = strchr(tmp, ':');
91− if (colon && strlen(colon) > 1) {
92− *colon = '\0';
93− ref = tmp;
94− tmp = colon + 1;
95− while ((*tmp == '/' || *tmp == ':') && *tmp != '\0')
96− ++tmp;
97− if (!(*tmp))
98− return;
99− }
110+
111+ /* Print the calculated readme, either from the git repo or from the
112+ * filesystem, while applying the about-filter.
113+ */
100114 html("<div id='summary'>");
101115 if (ctx.repo->about_filter)
102116 cgit_open_filter(ctx.repo->about_filter);