summaryrefslogtreecommitdiffabout
path: root/ui-summary.c
authorLars Hjemli <hjemli@gmail.com>2008-02-23 21:45:33 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-03-18 07:13:10 (UTC)
commitb1f9b9c1459cb9a30ebf80721aff6ef788d1f891 (patch) (unidiff)
tree05796a741faef90c12aadd3a5c92b702ec870c48 /ui-summary.c
parentb88fb016d0209f7041ac7d3b4d2c077318407a4d (diff)
downloadcgit-b1f9b9c1459cb9a30ebf80721aff6ef788d1f891.zip
cgit-b1f9b9c1459cb9a30ebf80721aff6ef788d1f891.tar.gz
cgit-b1f9b9c1459cb9a30ebf80721aff6ef788d1f891.tar.bz2
Introduce html.h
All html-functions can be quite easily separated from the rest of cgit, so lets do it; the only issue was html_filemode which uses some git-defined macros so the function is moved into ui-shared.c::cgit_print_filemode(). Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-summary.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-summary.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/ui-summary.c b/ui-summary.c
index 3baac08..0afa0a3 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -1,200 +1,201 @@
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 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h"
10 11
11static int header; 12static int header;
12 13
13static int cmp_age(int age1, int age2) 14static int cmp_age(int age1, int age2)
14{ 15{
15 if (age1 != 0 && age2 != 0) 16 if (age1 != 0 && age2 != 0)
16 return age2 - age1; 17 return age2 - age1;
17 18
18 if (age1 == 0 && age2 == 0) 19 if (age1 == 0 && age2 == 0)
19 return 0; 20 return 0;
20 21
21 if (age1 == 0) 22 if (age1 == 0)
22 return +1; 23 return +1;
23 24
24 return -1; 25 return -1;
25} 26}
26 27
27static int cmp_ref_name(const void *a, const void *b) 28static int cmp_ref_name(const void *a, const void *b)
28{ 29{
29 struct refinfo *r1 = *(struct refinfo **)a; 30 struct refinfo *r1 = *(struct refinfo **)a;
30 struct refinfo *r2 = *(struct refinfo **)b; 31 struct refinfo *r2 = *(struct refinfo **)b;
31 32
32 return strcmp(r1->refname, r2->refname); 33 return strcmp(r1->refname, r2->refname);
33} 34}
34 35
35static int cmp_branch_age(const void *a, const void *b) 36static int cmp_branch_age(const void *a, const void *b)
36{ 37{
37 struct refinfo *r1 = *(struct refinfo **)a; 38 struct refinfo *r1 = *(struct refinfo **)a;
38 struct refinfo *r2 = *(struct refinfo **)b; 39 struct refinfo *r2 = *(struct refinfo **)b;
39 40
40 return cmp_age(r1->commit->committer_date, r2->commit->committer_date); 41 return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
41} 42}
42 43
43static int cmp_tag_age(const void *a, const void *b) 44static int cmp_tag_age(const void *a, const void *b)
44{ 45{
45 struct refinfo *r1 = *(struct refinfo **)a; 46 struct refinfo *r1 = *(struct refinfo **)a;
46 struct refinfo *r2 = *(struct refinfo **)b; 47 struct refinfo *r2 = *(struct refinfo **)b;
47 48
48 return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); 49 return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date);
49} 50}
50 51
51static int print_branch(struct refinfo *ref) 52static int print_branch(struct refinfo *ref)
52{ 53{
53 struct commitinfo *info = ref->commit; 54 struct commitinfo *info = ref->commit;
54 char *name = (char *)ref->refname; 55 char *name = (char *)ref->refname;
55 56
56 if (!info) 57 if (!info)
57 return 1; 58 return 1;
58 html("<tr><td>"); 59 html("<tr><td>");
59 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL); 60 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL);
60 html("</td><td>"); 61 html("</td><td>");
61 62
62 if (ref->object->type == OBJ_COMMIT) { 63 if (ref->object->type == OBJ_COMMIT) {
63 cgit_print_age(info->commit->date, -1, NULL); 64 cgit_print_age(info->commit->date, -1, NULL);
64 html("</td><td>"); 65 html("</td><td>");
65 html_txt(info->author); 66 html_txt(info->author);
66 html("</td><td>"); 67 html("</td><td>");
67 cgit_commit_link(info->subject, NULL, NULL, name, NULL); 68 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
68 } else { 69 } else {
69 html("</td><td></td><td>"); 70 html("</td><td></td><td>");
70 cgit_object_link(ref->object); 71 cgit_object_link(ref->object);
71 } 72 }
72 html("</td></tr>\n"); 73 html("</td></tr>\n");
73 return 0; 74 return 0;
74} 75}
75 76
76static void print_tag_header() 77static void print_tag_header()
77{ 78{
78 html("<tr class='nohover'><th class='left'>Tag</th>" 79 html("<tr class='nohover'><th class='left'>Tag</th>"
79 "<th class='left'>Age</th>" 80 "<th class='left'>Age</th>"
80 "<th class='left'>Author</th>" 81 "<th class='left'>Author</th>"
81 "<th class='left'>Reference</th></tr>\n"); 82 "<th class='left'>Reference</th></tr>\n");
82 header = 1; 83 header = 1;
83} 84}
84 85
85static int print_tag(struct refinfo *ref) 86static int print_tag(struct refinfo *ref)
86{ 87{
87 struct tag *tag; 88 struct tag *tag;
88 struct taginfo *info; 89 struct taginfo *info;
89 char *url, *name = (char *)ref->refname; 90 char *url, *name = (char *)ref->refname;
90 91
91 if (ref->object->type == OBJ_TAG) { 92 if (ref->object->type == OBJ_TAG) {
92 tag = (struct tag *)ref->object; 93 tag = (struct tag *)ref->object;
93 info = ref->tag; 94 info = ref->tag;
94 if (!tag || !info) 95 if (!tag || !info)
95 return 1; 96 return 1;
96 html("<tr><td>"); 97 html("<tr><td>");
97 url = cgit_pageurl(ctx.qry.repo, "tag", 98 url = cgit_pageurl(ctx.qry.repo, "tag",
98 fmt("id=%s", name)); 99 fmt("id=%s", name));
99 html_link_open(url, NULL, NULL); 100 html_link_open(url, NULL, NULL);
100 html_txt(name); 101 html_txt(name);
101 html_link_close(); 102 html_link_close();
102 html("</td><td>"); 103 html("</td><td>");
103 if (info->tagger_date > 0) 104 if (info->tagger_date > 0)
104 cgit_print_age(info->tagger_date, -1, NULL); 105 cgit_print_age(info->tagger_date, -1, NULL);
105 html("</td><td>"); 106 html("</td><td>");
106 if (info->tagger) 107 if (info->tagger)
107 html(info->tagger); 108 html(info->tagger);
108 html("</td><td>"); 109 html("</td><td>");
109 cgit_object_link(tag->tagged); 110 cgit_object_link(tag->tagged);
110 html("</td></tr>\n"); 111 html("</td></tr>\n");
111 } else { 112 } else {
112 if (!header) 113 if (!header)
113 print_tag_header(); 114 print_tag_header();
114 html("<tr><td>"); 115 html("<tr><td>");
115 html_txt(name); 116 html_txt(name);
116 html("</td><td colspan='2'/><td>"); 117 html("</td><td colspan='2'/><td>");
117 cgit_object_link(ref->object); 118 cgit_object_link(ref->object);
118 html("</td></tr>\n"); 119 html("</td></tr>\n");
119 } 120 }
120 return 0; 121 return 0;
121} 122}
122 123
123static void print_refs_link(char *path) 124static void print_refs_link(char *path)
124{ 125{
125 html("<tr class='nohover'><td colspan='4'>"); 126 html("<tr class='nohover'><td colspan='4'>");
126 cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); 127 cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path);
127 html("</td></tr>"); 128 html("</td></tr>");
128} 129}
129 130
130void cgit_print_branches(int maxcount) 131void cgit_print_branches(int maxcount)
131{ 132{
132 struct reflist list; 133 struct reflist list;
133 int i; 134 int i;
134 135
135 html("<tr class='nohover'><th class='left'>Branch</th>" 136 html("<tr class='nohover'><th class='left'>Branch</th>"
136 "<th class='left'>Idle</th>" 137 "<th class='left'>Idle</th>"
137 "<th class='left'>Author</th>" 138 "<th class='left'>Author</th>"
138 "<th class='left'>Head commit</th></tr>\n"); 139 "<th class='left'>Head commit</th></tr>\n");
139 140
140 list.refs = NULL; 141 list.refs = NULL;
141 list.alloc = list.count = 0; 142 list.alloc = list.count = 0;
142 for_each_branch_ref(cgit_refs_cb, &list); 143 for_each_branch_ref(cgit_refs_cb, &list);
143 144
144 if (maxcount == 0 || maxcount > list.count) 145 if (maxcount == 0 || maxcount > list.count)
145 maxcount = list.count; 146 maxcount = list.count;
146 147
147 if (maxcount < list.count) { 148 if (maxcount < list.count) {
148 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); 149 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
149 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); 150 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
150 } 151 }
151 152
152 for(i=0; i<maxcount; i++) 153 for(i=0; i<maxcount; i++)
153 print_branch(list.refs[i]); 154 print_branch(list.refs[i]);
154 155
155 if (maxcount < list.count) 156 if (maxcount < list.count)
156 print_refs_link("heads"); 157 print_refs_link("heads");
157} 158}
158 159
159void cgit_print_tags(int maxcount) 160void cgit_print_tags(int maxcount)
160{ 161{
161 struct reflist list; 162 struct reflist list;
162 int i; 163 int i;
163 164
164 header = 0; 165 header = 0;
165 list.refs = NULL; 166 list.refs = NULL;
166 list.alloc = list.count = 0; 167 list.alloc = list.count = 0;
167 for_each_tag_ref(cgit_refs_cb, &list); 168 for_each_tag_ref(cgit_refs_cb, &list);
168 if (list.count == 0) 169 if (list.count == 0)
169 return; 170 return;
170 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); 171 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
171 if (!maxcount) 172 if (!maxcount)
172 maxcount = list.count; 173 maxcount = list.count;
173 else if (maxcount > list.count) 174 else if (maxcount > list.count)
174 maxcount = list.count; 175 maxcount = list.count;
175 print_tag_header(); 176 print_tag_header();
176 for(i=0; i<maxcount; i++) 177 for(i=0; i<maxcount; i++)
177 print_tag(list.refs[i]); 178 print_tag(list.refs[i]);
178 179
179 if (maxcount < list.count) 180 if (maxcount < list.count)
180 print_refs_link("tags"); 181 print_refs_link("tags");
181} 182}
182 183
183void cgit_print_summary() 184void cgit_print_summary()
184{ 185{
185 if (ctx.repo->readme) { 186 if (ctx.repo->readme) {
186 html("<div id='summary'>"); 187 html("<div id='summary'>");
187 html_include(ctx.repo->readme); 188 html_include(ctx.repo->readme);
188 html("</div>"); 189 html("</div>");
189 } 190 }
190 if (ctx.cfg.summary_log > 0) 191 if (ctx.cfg.summary_log > 0)
191 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, 192 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
192 NULL, NULL, 0); 193 NULL, NULL, 0);
193 html("<table summary='repository info' class='list nowrap'>"); 194 html("<table summary='repository info' class='list nowrap'>");
194 if (ctx.cfg.summary_log > 0) 195 if (ctx.cfg.summary_log > 0)
195 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 196 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
196 cgit_print_branches(ctx.cfg.summary_branches); 197 cgit_print_branches(ctx.cfg.summary_branches);
197 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 198 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
198 cgit_print_tags(ctx.cfg.summary_tags); 199 cgit_print_tags(ctx.cfg.summary_tags);
199 html("</table>"); 200 html("</table>");
200} 201}