author | Lars Hjemli <hjemli@gmail.com> | 2007-10-28 14:36:18 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-28 14:38:19 (UTC) |
commit | cbcdbcf2bff23113fe81df8f11fe7843b8ed637e (patch) (unidiff) | |
tree | 1c434e9005aa946daa8f7aa49a9c9f3656349068 | |
parent | 68ca032dbe7379f78775fb03ef34a9ad2abc409f (diff) | |
download | cgit-cbcdbcf2bff23113fe81df8f11fe7843b8ed637e.zip cgit-cbcdbcf2bff23113fe81df8f11fe7843b8ed637e.tar.gz cgit-cbcdbcf2bff23113fe81df8f11fe7843b8ed637e.tar.bz2 |
Make print_branch() handle refs not pointing at commits
The master branch of stable/linux-2.6.20 currently references a tag
object, which makes print_branch() die with a segfault. This teaches
print_branch() to handle such cases more gracefully.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-summary.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/ui-summary.c b/ui-summary.c index 04a466a..ba90510 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -13,101 +13,107 @@ static int header; | |||
13 | static int cmp_age(int age1, int age2) | 13 | static int cmp_age(int age1, int age2) |
14 | { | 14 | { |
15 | if (age1 != 0 && age2 != 0) | 15 | if (age1 != 0 && age2 != 0) |
16 | return age2 - age1; | 16 | return age2 - age1; |
17 | 17 | ||
18 | if (age1 == 0 && age2 == 0) | 18 | if (age1 == 0 && age2 == 0) |
19 | return 0; | 19 | return 0; |
20 | 20 | ||
21 | if (age1 == 0) | 21 | if (age1 == 0) |
22 | return +1; | 22 | return +1; |
23 | 23 | ||
24 | return -1; | 24 | return -1; |
25 | } | 25 | } |
26 | 26 | ||
27 | static int cmp_ref_name(const void *a, const void *b) | 27 | static int cmp_ref_name(const void *a, const void *b) |
28 | { | 28 | { |
29 | struct refinfo *r1 = *(struct refinfo **)a; | 29 | struct refinfo *r1 = *(struct refinfo **)a; |
30 | struct refinfo *r2 = *(struct refinfo **)b; | 30 | struct refinfo *r2 = *(struct refinfo **)b; |
31 | 31 | ||
32 | return strcmp(r1->refname, r2->refname); | 32 | return strcmp(r1->refname, r2->refname); |
33 | } | 33 | } |
34 | 34 | ||
35 | static int cmp_branch_age(const void *a, const void *b) | 35 | static int cmp_branch_age(const void *a, const void *b) |
36 | { | 36 | { |
37 | struct refinfo *r1 = *(struct refinfo **)a; | 37 | struct refinfo *r1 = *(struct refinfo **)a; |
38 | struct refinfo *r2 = *(struct refinfo **)b; | 38 | struct refinfo *r2 = *(struct refinfo **)b; |
39 | 39 | ||
40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | 40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); |
41 | } | 41 | } |
42 | 42 | ||
43 | static int cmp_tag_age(const void *a, const void *b) | 43 | static int cmp_tag_age(const void *a, const void *b) |
44 | { | 44 | { |
45 | struct refinfo *r1 = *(struct refinfo **)a; | 45 | struct refinfo *r1 = *(struct refinfo **)a; |
46 | struct refinfo *r2 = *(struct refinfo **)b; | 46 | struct refinfo *r2 = *(struct refinfo **)b; |
47 | 47 | ||
48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | 48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); |
49 | } | 49 | } |
50 | 50 | ||
51 | static int print_branch(struct refinfo *ref) | 51 | static int print_branch(struct refinfo *ref) |
52 | { | 52 | { |
53 | struct commitinfo *info = ref->commit; | 53 | struct commitinfo *info = ref->commit; |
54 | char *name = (char *)ref->refname; | 54 | char *name = (char *)ref->refname; |
55 | 55 | ||
56 | if (!info) | 56 | if (!info) |
57 | return 1; | 57 | return 1; |
58 | html("<tr><td>"); | 58 | html("<tr><td>"); |
59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | 59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
60 | html("</td><td>"); | 60 | html("</td><td>"); |
61 | |||
62 | if (ref->object->type == OBJ_COMMIT) { | ||
61 | cgit_print_age(info->commit->date, -1, NULL); | 63 | cgit_print_age(info->commit->date, -1, NULL); |
62 | html("</td><td>"); | 64 | html("</td><td>"); |
63 | html_txt(info->author); | 65 | html_txt(info->author); |
64 | html("</td><td>"); | 66 | html("</td><td>"); |
65 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | 67 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); |
68 | } else { | ||
69 | html("</td><td></td><td>"); | ||
70 | cgit_object_link(ref->object); | ||
71 | } | ||
66 | html("</td></tr>\n"); | 72 | html("</td></tr>\n"); |
67 | return 0; | 73 | return 0; |
68 | } | 74 | } |
69 | 75 | ||
70 | static void print_tag_header() | 76 | static void print_tag_header() |
71 | { | 77 | { |
72 | html("<tr class='nohover'><th class='left'>Tag</th>" | 78 | html("<tr class='nohover'><th class='left'>Tag</th>" |
73 | "<th class='left'>Age</th>" | 79 | "<th class='left'>Age</th>" |
74 | "<th class='left'>Author</th>" | 80 | "<th class='left'>Author</th>" |
75 | "<th class='left'>Reference</th></tr>\n"); | 81 | "<th class='left'>Reference</th></tr>\n"); |
76 | header = 1; | 82 | header = 1; |
77 | } | 83 | } |
78 | 84 | ||
79 | static int print_tag(struct refinfo *ref) | 85 | static int print_tag(struct refinfo *ref) |
80 | { | 86 | { |
81 | struct tag *tag; | 87 | struct tag *tag; |
82 | struct taginfo *info; | 88 | struct taginfo *info; |
83 | char *url, *name = (char *)ref->refname; | 89 | char *url, *name = (char *)ref->refname; |
84 | 90 | ||
85 | if (ref->object->type == OBJ_TAG) { | 91 | if (ref->object->type == OBJ_TAG) { |
86 | tag = (struct tag *)ref->object; | 92 | tag = (struct tag *)ref->object; |
87 | info = ref->tag; | 93 | info = ref->tag; |
88 | if (!tag || !info) | 94 | if (!tag || !info) |
89 | return 1; | 95 | return 1; |
90 | html("<tr><td>"); | 96 | html("<tr><td>"); |
91 | url = cgit_pageurl(cgit_query_repo, "tag", | 97 | url = cgit_pageurl(cgit_query_repo, "tag", |
92 | fmt("id=%s", name)); | 98 | fmt("id=%s", name)); |
93 | html_link_open(url, NULL, NULL); | 99 | html_link_open(url, NULL, NULL); |
94 | html_txt(name); | 100 | html_txt(name); |
95 | html_link_close(); | 101 | html_link_close(); |
96 | html("</td><td>"); | 102 | html("</td><td>"); |
97 | if (info->tagger_date > 0) | 103 | if (info->tagger_date > 0) |
98 | cgit_print_age(info->tagger_date, -1, NULL); | 104 | cgit_print_age(info->tagger_date, -1, NULL); |
99 | html("</td><td>"); | 105 | html("</td><td>"); |
100 | if (info->tagger) | 106 | if (info->tagger) |
101 | html(info->tagger); | 107 | html(info->tagger); |
102 | html("</td><td>"); | 108 | html("</td><td>"); |
103 | cgit_object_link(tag->tagged); | 109 | cgit_object_link(tag->tagged); |
104 | html("</td></tr>\n"); | 110 | html("</td></tr>\n"); |
105 | } else { | 111 | } else { |
106 | if (!header) | 112 | if (!header) |
107 | print_tag_header(); | 113 | print_tag_header(); |
108 | html("<tr><td>"); | 114 | html("<tr><td>"); |
109 | html_txt(name); | 115 | html_txt(name); |
110 | html("</td><td colspan='2'/><td>"); | 116 | html("</td><td colspan='2'/><td>"); |
111 | cgit_object_link(ref->object); | 117 | cgit_object_link(ref->object); |
112 | html("</td></tr>\n"); | 118 | html("</td></tr>\n"); |
113 | } | 119 | } |