about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLars Hjemli2007-02-04 22:55:19 +0100
committerLars Hjemli2007-02-04 22:55:19 +0100
commit8fb2f056961e577a039ae185d89ab8e2d2840b9e (patch)
treea009aca3c52dd134faa48181daede79bd930f9a4
parentRead repo-info from /etc/cgitrc (diff)
downloadcgit-8fb2f056961e577a039ae185d89ab8e2d2840b9e.tar.gz
cgit-8fb2f056961e577a039ae185d89ab8e2d2840b9e.zip
Add support for lightweight tags
There is nothing bad about a tag that has no tag-object, but the old code
didn't handle such tags correctly. Fix it.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-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
@@ -278,6 +278,10 @@ struct object {
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 */
diff --git a/ui-summary.c b/ui-summary.c index 5518d01..ff3ed4d 100644 --- a/ui-summary.c +++ b/ui-summary.c
@@ -47,16 +47,42 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
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)));
@@ -70,25 +96,13 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
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;