author | Ondrej Jirman <ondrej.jirman@zonio.net> | 2007-05-26 01:33:41 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-31 08:25:48 (UTC) |
commit | 51a960a3ca6b0cade97db287a342996c3e1de48d (patch) (unidiff) | |
tree | d3360cd301c9e13d7aa9492e6628bf8d71736608 /ui-summary.c | |
parent | 6130231ed5e7475836a44d79d5f09e300e71a407 (diff) | |
download | cgit-51a960a3ca6b0cade97db287a342996c3e1de48d.zip cgit-51a960a3ca6b0cade97db287a342996c3e1de48d.tar.gz cgit-51a960a3ca6b0cade97db287a342996c3e1de48d.tar.bz2 |
Implemented configurable HEAD shortlog on summary page.
This mirrors similiar functionality in gitweb. After clicking on
project on projectlist you will immediatelly see quick summary
of last N commits on HEAD.
[lh: changed from HEAD to cgit_query_head]
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-summary.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ui-summary.c b/ui-summary.c index 15e8aec..4bda4c2 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,212 +1,218 @@ | |||
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 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
14 | int flags, void *cb_data) | 14 | int flags, void *cb_data) |
15 | { | 15 | { |
16 | struct commit *commit; | 16 | struct commit *commit; |
17 | struct commitinfo *info; | 17 | struct commitinfo *info; |
18 | char buf[256], *url; | 18 | char buf[256], *url; |
19 | 19 | ||
20 | strncpy(buf, refname, sizeof(buf)); | 20 | strncpy(buf, refname, sizeof(buf)); |
21 | commit = lookup_commit(sha1); | 21 | commit = lookup_commit(sha1); |
22 | // object is not really parsed at this point, because of some fallout | ||
23 | // from previous calls to git functions in cgit_print_log() | ||
24 | commit->object.parsed = 0; | ||
22 | if (commit && !parse_commit(commit)){ | 25 | if (commit && !parse_commit(commit)){ |
23 | info = cgit_parse_commit(commit); | 26 | info = cgit_parse_commit(commit); |
24 | html("<tr><td>"); | 27 | html("<tr><td>"); |
25 | url = cgit_pageurl(cgit_query_repo, "log", | 28 | url = cgit_pageurl(cgit_query_repo, "log", |
26 | fmt("h=%s", refname)); | 29 | fmt("h=%s", refname)); |
27 | html_link_open(url, NULL, NULL); | 30 | html_link_open(url, NULL, NULL); |
28 | html_txt(buf); | 31 | html_txt(buf); |
29 | html_link_close(); | 32 | html_link_close(); |
30 | html("</td><td>"); | 33 | html("</td><td>"); |
31 | cgit_print_age(commit->date, -1, NULL); | 34 | cgit_print_age(commit->date, -1, NULL); |
32 | html("</td><td>"); | 35 | html("</td><td>"); |
33 | html_txt(info->author); | 36 | html_txt(info->author); |
34 | html("</td><td>"); | 37 | html("</td><td>"); |
35 | url = cgit_pageurl(cgit_query_repo, "commit", | 38 | url = cgit_pageurl(cgit_query_repo, "commit", |
36 | fmt("h=%s", sha1_to_hex(sha1))); | 39 | fmt("h=%s", sha1_to_hex(sha1))); |
37 | html_link_open(url, NULL, NULL); | 40 | html_link_open(url, NULL, NULL); |
38 | html_ntxt(cgit_max_msg_len, info->subject); | 41 | html_ntxt(cgit_max_msg_len, info->subject); |
39 | html_link_close(); | 42 | html_link_close(); |
40 | html("</td></tr>\n"); | 43 | html("</td></tr>\n"); |
41 | cgit_free_commitinfo(info); | 44 | cgit_free_commitinfo(info); |
42 | } else { | 45 | } else { |
43 | html("<tr><td>"); | 46 | html("<tr><td>"); |
44 | html_txt(buf); | 47 | html_txt(buf); |
45 | html("</td><td colspan='3'>"); | 48 | html("</td><td colspan='3'>"); |
46 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 49 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
47 | html("</td></tr>\n"); | 50 | html("</td></tr>\n"); |
48 | } | 51 | } |
49 | return 0; | 52 | return 0; |
50 | } | 53 | } |
51 | 54 | ||
52 | 55 | ||
53 | static void cgit_print_object_ref(struct object *obj) | 56 | static void cgit_print_object_ref(struct object *obj) |
54 | { | 57 | { |
55 | char *page, *arg, *url; | 58 | char *page, *arg, *url; |
56 | 59 | ||
57 | if (obj->type == OBJ_COMMIT) { | 60 | if (obj->type == OBJ_COMMIT) { |
58 | page = "commit"; | 61 | page = "commit"; |
59 | arg = "h"; | 62 | arg = "h"; |
60 | } else if (obj->type == OBJ_TREE) { | 63 | } else if (obj->type == OBJ_TREE) { |
61 | page = "tree"; | 64 | page = "tree"; |
62 | arg = "id"; | 65 | arg = "id"; |
63 | } else { | 66 | } else { |
64 | page = "view"; | 67 | page = "view"; |
65 | arg = "id"; | 68 | arg = "id"; |
66 | } | 69 | } |
67 | 70 | ||
68 | url = cgit_pageurl(cgit_query_repo, page, | 71 | url = cgit_pageurl(cgit_query_repo, page, |
69 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 72 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
70 | html_link_open(url, NULL, NULL); | 73 | html_link_open(url, NULL, NULL); |
71 | htmlf("%s %s", typename(obj->type), | 74 | htmlf("%s %s", typename(obj->type), |
72 | sha1_to_hex(obj->sha1)); | 75 | sha1_to_hex(obj->sha1)); |
73 | html_link_close(); | 76 | html_link_close(); |
74 | } | 77 | } |
75 | 78 | ||
76 | static void print_tag_header() | 79 | static void print_tag_header() |
77 | { | 80 | { |
78 | html("<tr class='nohover'><th class='left'>Tag</th>" | 81 | html("<tr class='nohover'><th class='left'>Tag</th>" |
79 | "<th class='left'>Age</th>" | 82 | "<th class='left'>Age</th>" |
80 | "<th class='left'>Author</th>" | 83 | "<th class='left'>Author</th>" |
81 | "<th class='left'>Reference</th></tr>\n"); | 84 | "<th class='left'>Reference</th></tr>\n"); |
82 | header = 1; | 85 | header = 1; |
83 | } | 86 | } |
84 | 87 | ||
85 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 88 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, |
86 | int flags, void *cb_data) | 89 | int flags, void *cb_data) |
87 | { | 90 | { |
88 | struct tag *tag; | 91 | struct tag *tag; |
89 | struct taginfo *info; | 92 | struct taginfo *info; |
90 | struct object *obj; | 93 | struct object *obj; |
91 | char buf[256], *url; | 94 | char buf[256], *url; |
92 | 95 | ||
93 | strncpy(buf, refname, sizeof(buf)); | 96 | strncpy(buf, refname, sizeof(buf)); |
94 | obj = parse_object(sha1); | 97 | obj = parse_object(sha1); |
95 | if (!obj) | 98 | if (!obj) |
96 | return 1; | 99 | return 1; |
97 | if (obj->type == OBJ_TAG) { | 100 | if (obj->type == OBJ_TAG) { |
98 | tag = lookup_tag(sha1); | 101 | tag = lookup_tag(sha1); |
99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 102 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
100 | return 2; | 103 | return 2; |
101 | if (!header) | 104 | if (!header) |
102 | print_tag_header(); | 105 | print_tag_header(); |
103 | html("<tr><td>"); | 106 | html("<tr><td>"); |
104 | url = cgit_pageurl(cgit_query_repo, "view", | 107 | url = cgit_pageurl(cgit_query_repo, "view", |
105 | fmt("id=%s", sha1_to_hex(sha1))); | 108 | fmt("id=%s", sha1_to_hex(sha1))); |
106 | html_link_open(url, NULL, NULL); | 109 | html_link_open(url, NULL, NULL); |
107 | html_txt(buf); | 110 | html_txt(buf); |
108 | html_link_close(); | 111 | html_link_close(); |
109 | html("</td><td>"); | 112 | html("</td><td>"); |
110 | if (info->tagger_date > 0) | 113 | if (info->tagger_date > 0) |
111 | cgit_print_age(info->tagger_date, -1, NULL); | 114 | cgit_print_age(info->tagger_date, -1, NULL); |
112 | html("</td><td>"); | 115 | html("</td><td>"); |
113 | if (info->tagger) | 116 | if (info->tagger) |
114 | html(info->tagger); | 117 | html(info->tagger); |
115 | html("</td><td>"); | 118 | html("</td><td>"); |
116 | cgit_print_object_ref(tag->tagged); | 119 | cgit_print_object_ref(tag->tagged); |
117 | html("</td></tr>\n"); | 120 | html("</td></tr>\n"); |
118 | } else { | 121 | } else { |
119 | if (!header) | 122 | if (!header) |
120 | print_tag_header(); | 123 | print_tag_header(); |
121 | html("<tr><td>"); | 124 | html("<tr><td>"); |
122 | html_txt(buf); | 125 | html_txt(buf); |
123 | html("</td><td colspan='2'/><td>"); | 126 | html("</td><td colspan='2'/><td>"); |
124 | cgit_print_object_ref(obj); | 127 | cgit_print_object_ref(obj); |
125 | html("</td></tr>\n"); | 128 | html("</td></tr>\n"); |
126 | } | 129 | } |
127 | return 0; | 130 | return 0; |
128 | } | 131 | } |
129 | 132 | ||
130 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 133 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
131 | int flags, void *cb_data) | 134 | int flags, void *cb_data) |
132 | { | 135 | { |
133 | struct tag *tag; | 136 | struct tag *tag; |
134 | struct taginfo *info; | 137 | struct taginfo *info; |
135 | struct object *obj; | 138 | struct object *obj; |
136 | char buf[256], *url; | 139 | char buf[256], *url; |
137 | unsigned char fileid[20]; | 140 | unsigned char fileid[20]; |
138 | 141 | ||
139 | if (prefixcmp(refname, "refs/archives")) | 142 | if (prefixcmp(refname, "refs/archives")) |
140 | return 0; | 143 | return 0; |
141 | strncpy(buf, refname+14, sizeof(buf)); | 144 | strncpy(buf, refname+14, sizeof(buf)); |
142 | obj = parse_object(sha1); | 145 | obj = parse_object(sha1); |
143 | if (!obj) | 146 | if (!obj) |
144 | return 1; | 147 | return 1; |
145 | if (obj->type == OBJ_TAG) { | 148 | if (obj->type == OBJ_TAG) { |
146 | tag = lookup_tag(sha1); | 149 | tag = lookup_tag(sha1); |
147 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 150 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
148 | return 0; | 151 | return 0; |
149 | hashcpy(fileid, tag->tagged->sha1); | 152 | hashcpy(fileid, tag->tagged->sha1); |
150 | } else if (obj->type != OBJ_BLOB) { | 153 | } else if (obj->type != OBJ_BLOB) { |
151 | return 0; | 154 | return 0; |
152 | } else { | 155 | } else { |
153 | hashcpy(fileid, sha1); | 156 | hashcpy(fileid, sha1); |
154 | } | 157 | } |
155 | if (!header) { | 158 | if (!header) { |
156 | html("<table id='downloads'>"); | 159 | html("<table id='downloads'>"); |
157 | html("<tr><th>Downloads</th></tr>"); | 160 | html("<tr><th>Downloads</th></tr>"); |
158 | header = 1; | 161 | header = 1; |
159 | } | 162 | } |
160 | html("<tr><td>"); | 163 | html("<tr><td>"); |
161 | url = cgit_pageurl(cgit_query_repo, "blob", | 164 | url = cgit_pageurl(cgit_query_repo, "blob", |
162 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 165 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
163 | buf)); | 166 | buf)); |
164 | html_link_open(url, NULL, NULL); | 167 | html_link_open(url, NULL, NULL); |
165 | html_txt(buf); | 168 | html_txt(buf); |
166 | html_link_close(); | 169 | html_link_close(); |
167 | html("</td></tr>"); | 170 | html("</td></tr>"); |
168 | return 0; | 171 | return 0; |
169 | } | 172 | } |
170 | 173 | ||
171 | static void cgit_print_branches() | 174 | static void cgit_print_branches() |
172 | { | 175 | { |
173 | html("<tr class='nohover'><th class='left'>Branch</th>" | 176 | html("<tr class='nohover'><th class='left'>Branch</th>" |
174 | "<th class='left'>Idle</th>" | 177 | "<th class='left'>Idle</th>" |
175 | "<th class='left'>Author</th>" | 178 | "<th class='left'>Author</th>" |
176 | "<th class='left'>Head commit</th></tr>\n"); | 179 | "<th class='left'>Head commit</th></tr>\n"); |
177 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 180 | for_each_branch_ref(cgit_print_branch_cb, NULL); |
178 | } | 181 | } |
179 | 182 | ||
180 | static void cgit_print_tags() | 183 | static void cgit_print_tags() |
181 | { | 184 | { |
182 | header = 0; | 185 | header = 0; |
183 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 186 | for_each_tag_ref(cgit_print_tag_cb, NULL); |
184 | } | 187 | } |
185 | 188 | ||
186 | static void cgit_print_archives() | 189 | static void cgit_print_archives() |
187 | { | 190 | { |
188 | header = 0; | 191 | header = 0; |
189 | for_each_ref(cgit_print_archive_cb, NULL); | 192 | for_each_ref(cgit_print_archive_cb, NULL); |
190 | if (header) | 193 | if (header) |
191 | html("</table>"); | 194 | html("</table>"); |
192 | } | 195 | } |
193 | 196 | ||
194 | void cgit_print_summary() | 197 | void cgit_print_summary() |
195 | { | 198 | { |
196 | html("<div id='summary'>"); | 199 | html("<div id='summary'>"); |
197 | cgit_print_archives(); | 200 | cgit_print_archives(); |
198 | html("<h2>"); | 201 | html("<h2>"); |
199 | html_txt(cgit_repo->name); | 202 | html_txt(cgit_repo->name); |
200 | html(" - "); | 203 | html(" - "); |
201 | html_txt(cgit_repo->desc); | 204 | html_txt(cgit_repo->desc); |
202 | html("</h2>"); | 205 | html("</h2>"); |
203 | if (cgit_repo->readme) | 206 | if (cgit_repo->readme) |
204 | html_include(cgit_repo->readme); | 207 | html_include(cgit_repo->readme); |
205 | html("</div>"); | 208 | html("</div>"); |
206 | 209 | if (cgit_summary_log > 0) | |
210 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); | ||
207 | html("<table class='list nowrap'>"); | 211 | html("<table class='list nowrap'>"); |
212 | if (cgit_summary_log > 0) | ||
213 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | ||
208 | cgit_print_branches(); | 214 | cgit_print_branches(); |
209 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 215 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
210 | cgit_print_tags(); | 216 | cgit_print_tags(); |
211 | html("</table>"); | 217 | html("</table>"); |
212 | } | 218 | } |