2006-12-11 15:55:07 +00:00
|
|
|
/* ui-summary.c: functions for generating repo summary page
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Lars Hjemli
|
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
|
|
|
|
2007-05-14 22:07:37 +00:00
|
|
|
static int header;
|
2007-05-11 21:44:42 +00:00
|
|
|
|
2007-10-27 08:06:03 +00:00
|
|
|
static int cmp_age(int age1, int age2)
|
2007-10-25 18:33:04 +00:00
|
|
|
{
|
2007-10-27 08:06:03 +00:00
|
|
|
if (age1 != 0 && age2 != 0)
|
|
|
|
return age2 - age1;
|
2007-10-25 18:33:04 +00:00
|
|
|
|
2007-10-27 08:06:03 +00:00
|
|
|
if (age1 == 0 && age2 == 0)
|
2007-10-25 18:33:04 +00:00
|
|
|
return 0;
|
|
|
|
|
2007-10-27 08:06:03 +00:00
|
|
|
if (age1 == 0)
|
2007-10-25 18:33:04 +00:00
|
|
|
return +1;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-27 08:13:42 +00:00
|
|
|
static int cmp_ref_name(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
struct refinfo *r1 = *(struct refinfo **)a;
|
|
|
|
struct refinfo *r2 = *(struct refinfo **)b;
|
|
|
|
|
|
|
|
return strcmp(r1->refname, r2->refname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmp_branch_age(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
struct refinfo *r1 = *(struct refinfo **)a;
|
|
|
|
struct refinfo *r2 = *(struct refinfo **)b;
|
|
|
|
|
|
|
|
return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
|
|
|
|
}
|
|
|
|
|
2007-10-27 08:06:03 +00:00
|
|
|
static int cmp_tag_age(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
struct refinfo *r1 = *(struct refinfo **)a;
|
|
|
|
struct refinfo *r2 = *(struct refinfo **)b;
|
|
|
|
|
|
|
|
return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date);
|
|
|
|
}
|
|
|
|
|
2007-10-27 11:34:17 +00:00
|
|
|
static int print_branch(struct refinfo *ref)
|
2006-12-11 15:55:07 +00:00
|
|
|
{
|
2007-10-27 11:34:17 +00:00
|
|
|
struct commitinfo *info = ref->commit;
|
2007-10-25 08:13:25 +00:00
|
|
|
char *name = (char *)ref->refname;
|
2006-12-11 15:55:07 +00:00
|
|
|
|
2007-10-27 11:34:17 +00:00
|
|
|
if (!info)
|
|
|
|
return 1;
|
|
|
|
html("<tr><td>");
|
|
|
|
cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
|
|
|
|
html("</td><td>");
|
|
|
|
cgit_print_age(info->commit->date, -1, NULL);
|
|
|
|
html("</td><td>");
|
|
|
|
html_txt(info->author);
|
|
|
|
html("</td><td>");
|
|
|
|
cgit_commit_link(info->subject, NULL, NULL, name, NULL);
|
|
|
|
html("</td></tr>\n");
|
|
|
|
return 0;
|
2007-01-17 00:10:39 +00:00
|
|
|
}
|
|
|
|
|
2007-05-14 22:07:37 +00:00
|
|
|
static void print_tag_header()
|
|
|
|
{
|
|
|
|
html("<tr class='nohover'><th class='left'>Tag</th>"
|
2007-05-22 21:15:36 +00:00
|
|
|
"<th class='left'>Age</th>"
|
2007-05-14 22:07:37 +00:00
|
|
|
"<th class='left'>Author</th>"
|
|
|
|
"<th class='left'>Reference</th></tr>\n");
|
|
|
|
header = 1;
|
|
|
|
}
|
|
|
|
|
2007-10-25 08:28:15 +00:00
|
|
|
static int print_tag(struct refinfo *ref)
|
2007-01-17 00:10:39 +00:00
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
struct taginfo *info;
|
2007-10-25 08:28:15 +00:00
|
|
|
char *url, *name = (char *)ref->refname;
|
2007-05-14 21:58:29 +00:00
|
|
|
|
2007-10-25 08:28:15 +00:00
|
|
|
if (ref->object->type == OBJ_TAG) {
|
2007-10-27 11:34:17 +00:00
|
|
|
tag = (struct tag *)ref->object;
|
|
|
|
info = ref->tag;
|
|
|
|
if (!tag || !info)
|
|
|
|
return 1;
|
2007-01-17 00:10:39 +00:00
|
|
|
html("<tr><td>");
|
2007-07-22 21:42:55 +00:00
|
|
|
url = cgit_pageurl(cgit_query_repo, "tag",
|
2007-10-25 08:28:15 +00:00
|
|
|
fmt("id=%s", name));
|
2007-01-17 00:10:39 +00:00
|
|
|
html_link_open(url, NULL, NULL);
|
2007-10-25 08:28:15 +00:00
|
|
|
html_txt(name);
|
2007-01-17 00:10:39 +00:00
|
|
|
html_link_close();
|
|
|
|
html("</td><td>");
|
|
|
|
if (info->tagger_date > 0)
|
2007-05-22 21:15:36 +00:00
|
|
|
cgit_print_age(info->tagger_date, -1, NULL);
|
2006-12-11 15:55:07 +00:00
|
|
|
html("</td><td>");
|
2007-01-17 00:10:39 +00:00
|
|
|
if (info->tagger)
|
|
|
|
html(info->tagger);
|
|
|
|
html("</td><td>");
|
2007-07-22 21:42:55 +00:00
|
|
|
cgit_object_link(tag->tagged);
|
2007-01-17 00:10:39 +00:00
|
|
|
html("</td></tr>\n");
|
|
|
|
} else {
|
2007-05-14 22:07:37 +00:00
|
|
|
if (!header)
|
|
|
|
print_tag_header();
|
2007-01-17 00:10:39 +00:00
|
|
|
html("<tr><td>");
|
2007-10-25 08:28:15 +00:00
|
|
|
html_txt(name);
|
2007-02-04 21:55:19 +00:00
|
|
|
html("</td><td colspan='2'/><td>");
|
2007-10-25 08:28:15 +00:00
|
|
|
cgit_object_link(ref->object);
|
2006-12-11 15:55:07 +00:00
|
|
|
html("</td></tr>\n");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-11 21:44:42 +00:00
|
|
|
static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
|
|
|
|
int flags, void *cb_data)
|
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
struct taginfo *info;
|
|
|
|
struct object *obj;
|
|
|
|
char buf[256], *url;
|
2007-05-14 23:05:39 +00:00
|
|
|
unsigned char fileid[20];
|
2007-05-11 21:44:42 +00:00
|
|
|
|
|
|
|
if (prefixcmp(refname, "refs/archives"))
|
|
|
|
return 0;
|
|
|
|
strncpy(buf, refname+14, sizeof(buf));
|
|
|
|
obj = parse_object(sha1);
|
|
|
|
if (!obj)
|
|
|
|
return 1;
|
|
|
|
if (obj->type == OBJ_TAG) {
|
|
|
|
tag = lookup_tag(sha1);
|
|
|
|
if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
|
|
|
|
return 0;
|
2007-05-14 23:05:39 +00:00
|
|
|
hashcpy(fileid, tag->tagged->sha1);
|
2007-05-11 21:44:42 +00:00
|
|
|
} else if (obj->type != OBJ_BLOB) {
|
|
|
|
return 0;
|
2007-05-14 23:05:39 +00:00
|
|
|
} else {
|
|
|
|
hashcpy(fileid, sha1);
|
2007-05-11 21:44:42 +00:00
|
|
|
}
|
2007-05-14 22:07:37 +00:00
|
|
|
if (!header) {
|
2007-05-23 20:46:54 +00:00
|
|
|
html("<table id='downloads'>");
|
2007-05-11 21:44:42 +00:00
|
|
|
html("<tr><th>Downloads</th></tr>");
|
2007-05-14 22:07:37 +00:00
|
|
|
header = 1;
|
2007-05-11 21:44:42 +00:00
|
|
|
}
|
|
|
|
html("<tr><td>");
|
|
|
|
url = cgit_pageurl(cgit_query_repo, "blob",
|
2007-05-25 23:15:10 +00:00
|
|
|
fmt("id=%s&path=%s", sha1_to_hex(fileid),
|
2007-05-11 21:44:42 +00:00
|
|
|
buf));
|
|
|
|
html_link_open(url, NULL, NULL);
|
|
|
|
html_txt(buf);
|
|
|
|
html_link_close();
|
2007-05-23 22:02:18 +00:00
|
|
|
html("</td></tr>");
|
2007-05-11 21:44:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-27 08:47:44 +00:00
|
|
|
static void print_refs_link(char *path)
|
|
|
|
{
|
|
|
|
html("<tr class='nohover'><td colspan='4'>");
|
|
|
|
cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path);
|
|
|
|
html("</td></tr>");
|
|
|
|
}
|
|
|
|
|
2007-10-27 08:25:40 +00:00
|
|
|
void cgit_print_branches(int maxcount)
|
2006-12-11 15:55:07 +00:00
|
|
|
{
|
2007-10-25 08:13:25 +00:00
|
|
|
struct reflist list;
|
|
|
|
int i;
|
|
|
|
|
2007-01-27 23:39:26 +00:00
|
|
|
html("<tr class='nohover'><th class='left'>Branch</th>"
|
2007-05-22 21:15:36 +00:00
|
|
|
"<th class='left'>Idle</th>"
|
2007-01-17 00:10:39 +00:00
|
|
|
"<th class='left'>Author</th>"
|
|
|
|
"<th class='left'>Head commit</th></tr>\n");
|
2007-10-25 08:13:25 +00:00
|
|
|
|
|
|
|
list.refs = NULL;
|
|
|
|
list.alloc = list.count = 0;
|
|
|
|
for_each_branch_ref(cgit_refs_cb, &list);
|
2007-10-27 08:13:42 +00:00
|
|
|
|
|
|
|
if (maxcount == 0 || maxcount > list.count)
|
|
|
|
maxcount = list.count;
|
|
|
|
|
|
|
|
if (maxcount < list.count) {
|
|
|
|
qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
|
|
|
|
qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<maxcount; i++)
|
2007-10-27 11:34:17 +00:00
|
|
|
print_branch(list.refs[i]);
|
2007-10-27 08:47:44 +00:00
|
|
|
|
|
|
|
if (maxcount < list.count)
|
|
|
|
print_refs_link("heads");
|
2007-01-17 00:10:39 +00:00
|
|
|
}
|
|
|
|
|
2007-10-27 08:25:40 +00:00
|
|
|
void cgit_print_tags(int maxcount)
|
2007-01-17 00:10:39 +00:00
|
|
|
{
|
2007-10-25 08:28:15 +00:00
|
|
|
struct reflist list;
|
|
|
|
int i;
|
|
|
|
|
2007-05-14 22:07:37 +00:00
|
|
|
header = 0;
|
2007-10-25 08:28:15 +00:00
|
|
|
list.refs = NULL;
|
|
|
|
list.alloc = list.count = 0;
|
|
|
|
for_each_tag_ref(cgit_refs_cb, &list);
|
|
|
|
if (list.count == 0)
|
|
|
|
return;
|
2007-10-25 18:33:04 +00:00
|
|
|
qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
|
2007-10-25 08:40:16 +00:00
|
|
|
if (!maxcount)
|
|
|
|
maxcount = list.count;
|
|
|
|
else if (maxcount > list.count)
|
|
|
|
maxcount = list.count;
|
2007-10-25 08:28:15 +00:00
|
|
|
print_tag_header();
|
2007-10-25 08:40:16 +00:00
|
|
|
for(i=0; i<maxcount; i++)
|
2007-10-25 08:28:15 +00:00
|
|
|
print_tag(list.refs[i]);
|
2007-10-27 08:47:44 +00:00
|
|
|
|
|
|
|
if (maxcount < list.count)
|
|
|
|
print_refs_link("tags");
|
2006-12-11 15:55:07 +00:00
|
|
|
}
|
|
|
|
|
2007-05-11 21:44:42 +00:00
|
|
|
static void cgit_print_archives()
|
|
|
|
{
|
2007-05-14 22:07:37 +00:00
|
|
|
header = 0;
|
2007-05-11 21:44:42 +00:00
|
|
|
for_each_ref(cgit_print_archive_cb, NULL);
|
2007-05-14 22:07:37 +00:00
|
|
|
if (header)
|
2007-05-11 21:44:42 +00:00
|
|
|
html("</table>");
|
|
|
|
}
|
|
|
|
|
2006-12-11 16:04:19 +00:00
|
|
|
void cgit_print_summary()
|
2006-12-11 15:55:07 +00:00
|
|
|
{
|
2007-05-23 20:46:54 +00:00
|
|
|
html("<div id='summary'>");
|
|
|
|
cgit_print_archives();
|
2007-05-11 21:44:42 +00:00
|
|
|
html("<h2>");
|
|
|
|
html_txt(cgit_repo->name);
|
|
|
|
html(" - ");
|
|
|
|
html_txt(cgit_repo->desc);
|
|
|
|
html("</h2>");
|
2007-05-23 20:46:54 +00:00
|
|
|
if (cgit_repo->readme)
|
|
|
|
html_include(cgit_repo->readme);
|
|
|
|
html("</div>");
|
2007-05-26 01:33:41 +00:00
|
|
|
if (cgit_summary_log > 0)
|
|
|
|
cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
|
2007-05-23 20:46:54 +00:00
|
|
|
html("<table class='list nowrap'>");
|
2007-05-26 01:33:41 +00:00
|
|
|
if (cgit_summary_log > 0)
|
|
|
|
html("<tr class='nohover'><td colspan='4'> </td></tr>");
|
2007-10-27 08:13:42 +00:00
|
|
|
cgit_print_branches(cgit_summary_branches);
|
2007-01-17 00:10:39 +00:00
|
|
|
html("<tr class='nohover'><td colspan='4'> </td></tr>");
|
2007-10-25 08:40:16 +00:00
|
|
|
cgit_print_tags(cgit_summary_tags);
|
2007-01-17 00:10:39 +00:00
|
|
|
html("</table>");
|
2006-12-11 15:55:07 +00:00
|
|
|
}
|