-rw-r--r-- | ui-summary.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/ui-summary.c b/ui-summary.c index 02f191e..b203bcc 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,110 +1,124 @@ | |||
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 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> |
5 | * | 5 | * |
6 | * Licensed under GNU General Public License v2 | 6 | * Licensed under GNU General Public License v2 |
7 | * (see COPYING for full license text) | 7 | * (see COPYING for full license text) |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "cgit.h" | 10 | #include "cgit.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-log.h" | 12 | #include "ui-log.h" |
13 | #include "ui-refs.h" | 13 | #include "ui-refs.h" |
14 | #include "ui-blob.h" | 14 | #include "ui-blob.h" |
15 | 15 | ||
16 | int urls = 0; | 16 | int urls = 0; |
17 | 17 | ||
18 | static void print_url(char *base, char *suffix) | 18 | static void print_url(char *base, char *suffix) |
19 | { | 19 | { |
20 | if (!base || !*base) | 20 | if (!base || !*base) |
21 | return; | 21 | return; |
22 | if (urls++ == 0) { | 22 | if (urls++ == 0) { |
23 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 23 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
24 | html("<tr><th class='left' colspan='4'>Clone</th></tr>\n"); | 24 | html("<tr><th class='left' colspan='4'>Clone</th></tr>\n"); |
25 | } | 25 | } |
26 | if (suffix && *suffix) | 26 | if (suffix && *suffix) |
27 | base = fmt("%s/%s", base, suffix); | 27 | base = fmt("%s/%s", base, suffix); |
28 | html("<tr><td colspan='4'><a href='"); | 28 | html("<tr><td colspan='4'><a href='"); |
29 | html_url_path(base); | 29 | html_url_path(base); |
30 | html("'>"); | 30 | html("'>"); |
31 | html_txt(base); | 31 | html_txt(base); |
32 | html("</a></td></tr>\n"); | 32 | html("</a></td></tr>\n"); |
33 | } | 33 | } |
34 | 34 | ||
35 | static void print_urls(char *txt, char *suffix) | 35 | static void print_urls(char *txt, char *suffix) |
36 | { | 36 | { |
37 | char *h = txt, *t, c; | 37 | char *h = txt, *t, c; |
38 | 38 | ||
39 | while (h && *h) { | 39 | while (h && *h) { |
40 | while (h && *h == ' ') | 40 | while (h && *h == ' ') |
41 | h++; | 41 | h++; |
42 | t = h; | 42 | t = h; |
43 | while (t && *t && *t != ' ') | 43 | while (t && *t && *t != ' ') |
44 | t++; | 44 | t++; |
45 | c = *t; | 45 | c = *t; |
46 | *t = 0; | 46 | *t = 0; |
47 | print_url(h, suffix); | 47 | print_url(h, suffix); |
48 | *t = c; | 48 | *t = c; |
49 | h = t; | 49 | h = t; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void cgit_print_summary() | 53 | void cgit_print_summary() |
54 | { | 54 | { |
55 | html("<table summary='repository info' class='list nowrap'>"); | 55 | html("<table summary='repository info' class='list nowrap'>"); |
56 | cgit_print_branches(ctx.cfg.summary_branches); | 56 | cgit_print_branches(ctx.cfg.summary_branches); |
57 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 57 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
58 | cgit_print_tags(ctx.cfg.summary_tags); | 58 | cgit_print_tags(ctx.cfg.summary_tags); |
59 | if (ctx.cfg.summary_log > 0) { | 59 | if (ctx.cfg.summary_log > 0) { |
60 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 60 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
61 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, | 61 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, |
62 | NULL, NULL, 0); | 62 | NULL, NULL, 0); |
63 | } | 63 | } |
64 | if (ctx.repo->clone_url) | 64 | if (ctx.repo->clone_url) |
65 | print_urls(ctx.repo->clone_url, NULL); | 65 | print_urls(ctx.repo->clone_url, NULL); |
66 | else if (ctx.cfg.clone_prefix) | 66 | else if (ctx.cfg.clone_prefix) |
67 | print_urls(ctx.cfg.clone_prefix, ctx.repo->url); | 67 | print_urls(ctx.cfg.clone_prefix, ctx.repo->url); |
68 | html("</table>"); | 68 | html("</table>"); |
69 | } | 69 | } |
70 | 70 | ||
71 | void cgit_print_repo_readme(char *path) | 71 | void cgit_print_repo_readme(char *path) |
72 | { | 72 | { |
73 | char *slash, *tmp, *colon, *ref = 0; | 73 | char *slash, *tmp, *colon, *ref; |
74 | 74 | ||
75 | if (!ctx.repo->readme) | 75 | if (!ctx.repo->readme || !(*ctx.repo->readme)) |
76 | return; | 76 | return; |
77 | 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 | */ | ||
78 | if (path) { | 98 | if (path) { |
79 | slash = strrchr(ctx.repo->readme, '/'); | 99 | slash = strrchr(ctx.repo->readme, '/'); |
80 | if (!slash) { | 100 | if (!slash) { |
81 | slash = strchr(ctx.repo->readme, ':'); | 101 | if (!colon) |
82 | if (!slash) | ||
83 | return; | 102 | return; |
103 | slash = colon; | ||
84 | } | 104 | } |
85 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); | 105 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); |
86 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); | 106 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); |
87 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); | 107 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); |
88 | } else | 108 | } else |
89 | tmp = ctx.repo->readme; | 109 | tmp = ctx.repo->readme; |
90 | colon = strchr(tmp, ':'); | 110 | |
91 | if (colon && strlen(colon) > 1) { | 111 | /* Print the calculated readme, either from the git repo or from the |
92 | *colon = '\0'; | 112 | * filesystem, while applying the about-filter. |
93 | ref = tmp; | 113 | */ |
94 | tmp = colon + 1; | ||
95 | while ((*tmp == '/' || *tmp == ':') && *tmp != '\0') | ||
96 | ++tmp; | ||
97 | if (!(*tmp)) | ||
98 | return; | ||
99 | } | ||
100 | html("<div id='summary'>"); | 114 | html("<div id='summary'>"); |
101 | if (ctx.repo->about_filter) | 115 | if (ctx.repo->about_filter) |
102 | cgit_open_filter(ctx.repo->about_filter); | 116 | cgit_open_filter(ctx.repo->about_filter); |
103 | if (ref) | 117 | if (ref) |
104 | cgit_print_file(tmp, ref); | 118 | cgit_print_file(tmp, ref); |
105 | else | 119 | else |
106 | html_include(tmp); | 120 | html_include(tmp); |
107 | if (ctx.repo->about_filter) | 121 | if (ctx.repo->about_filter) |
108 | cgit_close_filter(ctx.repo->about_filter); | 122 | cgit_close_filter(ctx.repo->about_filter); |
109 | html("</div>"); | 123 | html("</div>"); |
110 | } | 124 | } |