summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--git.h4
-rw-r--r--ui-summary.c52
2 files changed, 37 insertions, 19 deletions
diff --git a/git.h b/git.h
index 991eaa5..eca48d5 100644
--- a/git.h
+++ b/git.h
@@ -257,48 +257,52 @@ struct object_refs {
257struct object_array { 257struct object_array {
258 unsigned int nr; 258 unsigned int nr;
259 unsigned int alloc; 259 unsigned int alloc;
260 struct object_array_entry { 260 struct object_array_entry {
261 struct object *item; 261 struct object *item;
262 const char *name; 262 const char *name;
263 } *objects; 263 } *objects;
264}; 264};
265 265
266#define TYPE_BITS 3 266#define TYPE_BITS 3
267#define FLAG_BITS 27 267#define FLAG_BITS 27
268 268
269/* 269/*
270 * The object type is stored in 3 bits. 270 * The object type is stored in 3 bits.
271 */ 271 */
272struct object { 272struct object {
273 unsigned parsed : 1; 273 unsigned parsed : 1;
274 unsigned used : 1; 274 unsigned used : 1;
275 unsigned type : TYPE_BITS; 275 unsigned type : TYPE_BITS;
276 unsigned flags : FLAG_BITS; 276 unsigned flags : FLAG_BITS;
277 unsigned char sha1[20]; 277 unsigned char sha1[20];
278}; 278};
279 279
280 280
281/** Returns the object, having parsed it to find out what it is. **/
282struct object *parse_object(const unsigned char *sha1);
283
284
281/* 285/*
282 * from git:tree.h 286 * from git:tree.h
283 */ 287 */
284 288
285struct tree { 289struct tree {
286 struct object object; 290 struct object object;
287 void *buffer; 291 void *buffer;
288 unsigned long size; 292 unsigned long size;
289}; 293};
290 294
291 295
292struct tree *lookup_tree(const unsigned char *sha1); 296struct tree *lookup_tree(const unsigned char *sha1);
293int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); 297int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
294int parse_tree(struct tree *tree); 298int parse_tree(struct tree *tree);
295struct tree *parse_tree_indirect(const unsigned char *sha1); 299struct tree *parse_tree_indirect(const unsigned char *sha1);
296 300
297typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); 301typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
298 302
299extern int read_tree_recursive(struct tree *tree, 303extern int read_tree_recursive(struct tree *tree,
300 const char *base, int baselen, 304 const char *base, int baselen,
301 int stage, const char **match, 305 int stage, const char **match,
302 read_tree_fn_t fn); 306 read_tree_fn_t fn);
303 307
304extern int read_tree(struct tree *tree, int stage, const char **paths); 308extern int read_tree(struct tree *tree, int stage, const char **paths);
diff --git a/ui-summary.c b/ui-summary.c
index 5518d01..ff3ed4d 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -26,90 +26,104 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
26 html_txt(buf); 26 html_txt(buf);
27 html_link_close(); 27 html_link_close();
28 html("</td><td>"); 28 html("</td><td>");
29 cgit_print_date(commit->date); 29 cgit_print_date(commit->date);
30 html("</td><td>"); 30 html("</td><td>");
31 html_txt(info->author); 31 html_txt(info->author);
32 html("</td><td>"); 32 html("</td><td>");
33 url = cgit_pageurl(cgit_query_repo, "commit", 33 url = cgit_pageurl(cgit_query_repo, "commit",
34 fmt("id=%s", sha1_to_hex(sha1))); 34 fmt("id=%s", sha1_to_hex(sha1)));
35 html_link_open(url, NULL, NULL); 35 html_link_open(url, NULL, NULL);
36 html_ntxt(cgit_max_msg_len, info->subject); 36 html_ntxt(cgit_max_msg_len, info->subject);
37 html_link_close(); 37 html_link_close();
38 html("</td></tr>\n"); 38 html("</td></tr>\n");
39 cgit_free_commitinfo(info); 39 cgit_free_commitinfo(info);
40 } else { 40 } else {
41 html("<tr><td>"); 41 html("<tr><td>");
42 html_txt(buf); 42 html_txt(buf);
43 html("</td><td colspan='3'>"); 43 html("</td><td colspan='3'>");
44 htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); 44 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
45 html("</td></tr>\n"); 45 html("</td></tr>\n");
46 } 46 }
47 return 0; 47 return 0;
48} 48}
49 49
50
51static void cgit_print_object_ref(struct object *obj)
52{
53 char *page, *url;
54
55 if (obj->type == OBJ_COMMIT)
56 page = "commit";
57 else if (obj->type == OBJ_TREE)
58 page = "tree";
59 else
60 page = "view";
61
62 url = cgit_pageurl(cgit_query_repo, page,
63 fmt("id=%s", sha1_to_hex(obj->sha1)));
64 html_link_open(url, NULL, NULL);
65 htmlf("%s %s", type_names[obj->type],
66 sha1_to_hex(obj->sha1));
67 html_link_close();
68}
69
50static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, 70static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
51 int flags, void *cb_data) 71 int flags, void *cb_data)
52{ 72{
53 struct tag *tag; 73 struct tag *tag;
54 struct taginfo *info; 74 struct taginfo *info;
55 char buf[256], *page, *url; 75 struct object *obj;
56 76 char buf[256], *url;
77
57 strncpy(buf, refname, sizeof(buf)); 78 strncpy(buf, refname, sizeof(buf));
58 tag = lookup_tag(sha1); 79 obj = parse_object(sha1);
59 if (tag && !parse_tag(tag) && (info = cgit_parse_tag(tag))){ 80 if (!obj)
81 return 1;
82 if (obj->type == OBJ_TAG) {
83 tag = lookup_tag(sha1);
84 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
85 return 2;
60 html("<tr><td>"); 86 html("<tr><td>");
61 url = cgit_pageurl(cgit_query_repo, "view", 87 url = cgit_pageurl(cgit_query_repo, "view",
62 fmt("id=%s", sha1_to_hex(sha1))); 88 fmt("id=%s", sha1_to_hex(sha1)));
63 html_link_open(url, NULL, NULL); 89 html_link_open(url, NULL, NULL);
64 html_txt(buf); 90 html_txt(buf);
65 html_link_close(); 91 html_link_close();
66 html("</td><td>"); 92 html("</td><td>");
67 if (info->tagger_date > 0) 93 if (info->tagger_date > 0)
68 cgit_print_date(info->tagger_date); 94 cgit_print_date(info->tagger_date);
69 html("</td><td>"); 95 html("</td><td>");
70 if (info->tagger) 96 if (info->tagger)
71 html(info->tagger); 97 html(info->tagger);
72 html("</td><td>"); 98 html("</td><td>");
73 if (tag->tagged->type == OBJ_COMMIT) 99 cgit_print_object_ref(tag->tagged);
74 page = "commit";
75 else if (tag->tagged->type == OBJ_TREE)
76 page = "tree";
77 else
78 page = "view";
79
80 url = cgit_pageurl(cgit_query_repo, page,
81 fmt("id=%s", sha1_to_hex(tag->tagged->sha1)));
82 html_link_open(url, NULL, NULL);
83 htmlf("%s %s", type_names[tag->tagged->type],
84 sha1_to_hex(tag->tagged->sha1));
85 html_link_close();
86 html("</td></tr>\n"); 100 html("</td></tr>\n");
87 } else { 101 } else {
88 html("<tr><td>"); 102 html("<tr><td>");
89 html_txt(buf); 103 html_txt(buf);
90 html("</td><td colspan='3'>"); 104 html("</td><td colspan='2'/><td>");
91 htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); 105 cgit_print_object_ref(obj);
92 html("</td></tr>\n"); 106 html("</td></tr>\n");
93 } 107 }
94 return 0; 108 return 0;
95} 109}
96 110
97static void cgit_print_branches() 111static void cgit_print_branches()
98{ 112{
99 html("<tr class='nohover'><th class='left'>Branch</th>" 113 html("<tr class='nohover'><th class='left'>Branch</th>"
100 "<th class='left'>Updated</th>" 114 "<th class='left'>Updated</th>"
101 "<th class='left'>Author</th>" 115 "<th class='left'>Author</th>"
102 "<th class='left'>Head commit</th></tr>\n"); 116 "<th class='left'>Head commit</th></tr>\n");
103 for_each_branch_ref(cgit_print_branch_cb, NULL); 117 for_each_branch_ref(cgit_print_branch_cb, NULL);
104} 118}
105 119
106static void cgit_print_tags() 120static void cgit_print_tags()
107{ 121{
108 html("<tr class='nohover'><th class='left'>Tag</th>" 122 html("<tr class='nohover'><th class='left'>Tag</th>"
109 "<th class='left'>Created</th>" 123 "<th class='left'>Created</th>"
110 "<th class='left'>Author</th>" 124 "<th class='left'>Author</th>"
111 "<th class='left'>Reference</th></tr>\n"); 125 "<th class='left'>Reference</th></tr>\n");
112 for_each_tag_ref(cgit_print_tag_cb, NULL); 126 for_each_tag_ref(cgit_print_tag_cb, NULL);
113} 127}
114 128
115void cgit_print_summary() 129void cgit_print_summary()