]>
git.cameronkatri.com Git - cgit.git/blob - ui-summary.c
1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
14 static int cmp_age(int age1
, int age2
)
16 if (age1
!= 0 && age2
!= 0)
19 if (age1
== 0 && age2
== 0)
28 static int cmp_ref_name(const void *a
, const void *b
)
30 struct refinfo
*r1
= *(struct refinfo
**)a
;
31 struct refinfo
*r2
= *(struct refinfo
**)b
;
33 return strcmp(r1
->refname
, r2
->refname
);
36 static int cmp_branch_age(const void *a
, const void *b
)
38 struct refinfo
*r1
= *(struct refinfo
**)a
;
39 struct refinfo
*r2
= *(struct refinfo
**)b
;
41 return cmp_age(r1
->commit
->committer_date
, r2
->commit
->committer_date
);
44 static int cmp_tag_age(const void *a
, const void *b
)
46 struct refinfo
*r1
= *(struct refinfo
**)a
;
47 struct refinfo
*r2
= *(struct refinfo
**)b
;
49 return cmp_age(r1
->tag
->tagger_date
, r2
->tag
->tagger_date
);
52 static int print_branch(struct refinfo
*ref
)
54 struct commitinfo
*info
= ref
->commit
;
55 char *name
= (char *)ref
->refname
;
60 cgit_log_link(name
, NULL
, NULL
, name
, NULL
, NULL
, 0, NULL
, NULL
);
63 if (ref
->object
->type
== OBJ_COMMIT
) {
64 cgit_print_age(info
->commit
->date
, -1, NULL
);
66 html_txt(info
->author
);
68 cgit_commit_link(info
->subject
, NULL
, NULL
, name
, NULL
);
70 html("</td><td></td><td>");
71 cgit_object_link(ref
->object
);
77 static void print_tag_header()
79 html("<tr class='nohover'><th class='left'>Tag</th>"
80 "<th class='left'>Age</th>"
81 "<th class='left'>Author</th>"
82 "<th class='left'>Reference</th></tr>\n");
86 static int print_tag(struct refinfo
*ref
)
90 char *url
, *name
= (char *)ref
->refname
;
92 if (ref
->object
->type
== OBJ_TAG
) {
93 tag
= (struct tag
*)ref
->object
;
98 url
= cgit_pageurl(ctx
.qry
.repo
, "tag",
100 html_link_open(url
, NULL
, NULL
);
104 if (info
->tagger_date
> 0)
105 cgit_print_age(info
->tagger_date
, -1, NULL
);
110 cgit_object_link(tag
->tagged
);
111 html("</td></tr>\n");
117 html("</td><td colspan='2'/><td>");
118 cgit_object_link(ref
->object
);
119 html("</td></tr>\n");
124 static void print_refs_link(char *path
)
126 html("<tr class='nohover'><td colspan='4'>");
127 cgit_refs_link("[...]", NULL
, NULL
, ctx
.qry
.head
, NULL
, path
);
131 void cgit_print_branches(int maxcount
)
136 html("<tr class='nohover'><th class='left'>Branch</th>"
137 "<th class='left'>Idle</th>"
138 "<th class='left'>Author</th>"
139 "<th class='left'>Head commit</th></tr>\n");
142 list
.alloc
= list
.count
= 0;
143 for_each_branch_ref(cgit_refs_cb
, &list
);
145 if (maxcount
== 0 || maxcount
> list
.count
)
146 maxcount
= list
.count
;
148 if (maxcount
< list
.count
) {
149 qsort(list
.refs
, list
.count
, sizeof(*list
.refs
), cmp_branch_age
);
150 qsort(list
.refs
, maxcount
, sizeof(*list
.refs
), cmp_ref_name
);
153 for(i
=0; i
<maxcount
; i
++)
154 print_branch(list
.refs
[i
]);
156 if (maxcount
< list
.count
)
157 print_refs_link("heads");
160 void cgit_print_tags(int maxcount
)
167 list
.alloc
= list
.count
= 0;
168 for_each_tag_ref(cgit_refs_cb
, &list
);
171 qsort(list
.refs
, list
.count
, sizeof(*list
.refs
), cmp_tag_age
);
173 maxcount
= list
.count
;
174 else if (maxcount
> list
.count
)
175 maxcount
= list
.count
;
177 for(i
=0; i
<maxcount
; i
++)
178 print_tag(list
.refs
[i
]);
180 if (maxcount
< list
.count
)
181 print_refs_link("tags");
184 void cgit_print_summary()
186 if (ctx
.repo
->readme
) {
187 html("<div id='summary'>");
188 html_include(ctx
.repo
->readme
);
191 if (ctx
.cfg
.summary_log
> 0)
192 cgit_print_log(ctx
.qry
.head
, 0, ctx
.cfg
.summary_log
, NULL
,
194 html("<table summary='repository info' class='list nowrap'>");
195 if (ctx
.cfg
.summary_log
> 0)
196 html("<tr class='nohover'><td colspan='4'> </td></tr>");
197 cgit_print_branches(ctx
.cfg
.summary_branches
);
198 html("<tr class='nohover'><td colspan='4'> </td></tr>");
199 cgit_print_tags(ctx
.cfg
.summary_tags
);