diff options
Diffstat (limited to 'ui-summary.c')
-rw-r--r-- | ui-summary.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/ui-summary.c b/ui-summary.c index a2c018e..b203bcc 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
4 | * | 5 | * |
5 | * Licensed under GNU General Public License v2 | 6 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 7 | * (see COPYING for full license text) |
@@ -10,6 +11,7 @@ | |||
10 | #include "html.h" | 11 | #include "html.h" |
11 | #include "ui-log.h" | 12 | #include "ui-log.h" |
12 | #include "ui-refs.h" | 13 | #include "ui-refs.h" |
14 | #include "ui-blob.h" | ||
13 | 15 | ||
14 | int urls = 0; | 16 | int urls = 0; |
15 | 17 | ||
@@ -68,24 +70,54 @@ void cgit_print_summary() | |||
68 | 70 | ||
69 | void cgit_print_repo_readme(char *path) | 71 | void cgit_print_repo_readme(char *path) |
70 | { | 72 | { |
71 | char *slash, *tmp; | 73 | char *slash, *tmp, *colon, *ref; |
72 | 74 | ||
73 | if (!ctx.repo->readme) | 75 | if (!ctx.repo->readme || !(*ctx.repo->readme)) |
74 | return; | 76 | return; |
75 | 77 | ||
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 | */ | ||
76 | if (path) { | 98 | if (path) { |
77 | slash = strrchr(ctx.repo->readme, '/'); | 99 | slash = strrchr(ctx.repo->readme, '/'); |
78 | if (!slash) | 100 | if (!slash) { |
79 | return; | 101 | if (!colon) |
102 | return; | ||
103 | slash = colon; | ||
104 | } | ||
80 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); | 105 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); |
81 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); | 106 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); |
82 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); | 107 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); |
83 | } else | 108 | } else |
84 | tmp = ctx.repo->readme; | 109 | tmp = ctx.repo->readme; |
110 | |||
111 | /* Print the calculated readme, either from the git repo or from the | ||
112 | * filesystem, while applying the about-filter. | ||
113 | */ | ||
85 | html("<div id='summary'>"); | 114 | html("<div id='summary'>"); |
86 | if (ctx.repo->about_filter) | 115 | if (ctx.repo->about_filter) |
87 | cgit_open_filter(ctx.repo->about_filter); | 116 | cgit_open_filter(ctx.repo->about_filter); |
88 | html_include(tmp); | 117 | if (ref) |
118 | cgit_print_file(tmp, ref); | ||
119 | else | ||
120 | html_include(tmp); | ||
89 | if (ctx.repo->about_filter) | 121 | if (ctx.repo->about_filter) |
90 | cgit_close_filter(ctx.repo->about_filter); | 122 | cgit_close_filter(ctx.repo->about_filter); |
91 | html("</div>"); | 123 | html("</div>"); |