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