2007-10-27 10:36:53 +02:00
|
|
|
/* ui-refs.c: browse symbolic refs
|
|
|
|
*
|
2014-01-08 15:10:49 +01:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2007-10-27 10:36:53 +02:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2013-04-06 12:37:59 +02:00
|
|
|
#include "ui-refs.h"
|
2008-02-23 22:45:33 +01:00
|
|
|
#include "html.h"
|
2008-03-24 16:50:57 +01:00
|
|
|
#include "ui-shared.h"
|
2007-10-27 10:36:53 +02:00
|
|
|
|
2014-02-26 16:57:15 +01:00
|
|
|
static inline int cmp_age(int age1, int age2)
|
2008-03-24 16:38:47 +01:00
|
|
|
{
|
2014-02-26 16:57:15 +01:00
|
|
|
/* age1 and age2 are assumed to be non-negative */
|
|
|
|
return age2 - age1;
|
2008-03-24 16:38:47 +01: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);
|
|
|
|
}
|
|
|
|
|
2010-08-03 22:06:21 +02:00
|
|
|
static int get_ref_age(struct refinfo *ref)
|
|
|
|
{
|
|
|
|
if (!ref->object)
|
|
|
|
return 0;
|
|
|
|
switch (ref->object->type) {
|
|
|
|
case OBJ_TAG:
|
|
|
|
return ref->tag ? ref->tag->tagger_date : 0;
|
|
|
|
case OBJ_COMMIT:
|
|
|
|
return ref->commit ? ref->commit->committer_date : 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-24 16:38:47 +01:00
|
|
|
static int cmp_tag_age(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
struct refinfo *r1 = *(struct refinfo **)a;
|
|
|
|
struct refinfo *r2 = *(struct refinfo **)b;
|
2009-08-16 19:35:18 +02:00
|
|
|
|
2010-08-03 22:06:21 +02:00
|
|
|
return cmp_age(get_ref_age(r1), get_ref_age(r2));
|
2008-03-24 16:38:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int print_branch(struct refinfo *ref)
|
|
|
|
{
|
|
|
|
struct commitinfo *info = ref->commit;
|
|
|
|
char *name = (char *)ref->refname;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return 1;
|
|
|
|
html("<tr><td>");
|
2008-11-29 18:39:41 +01:00
|
|
|
cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL,
|
2015-08-12 16:55:28 +02:00
|
|
|
ctx.qry.showmsg, 0);
|
2008-03-24 16:38:47 +01:00
|
|
|
html("</td><td>");
|
|
|
|
|
|
|
|
if (ref->object->type == OBJ_COMMIT) {
|
2014-10-05 11:59:02 +02:00
|
|
|
cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL);
|
2008-03-24 16:38:47 +01:00
|
|
|
html("</td><td>");
|
2014-01-13 16:24:40 +01:00
|
|
|
cgit_open_filter(ctx.repo->email_filter, info->author_email, "refs");
|
2008-03-24 16:38:47 +01:00
|
|
|
html_txt(info->author);
|
2014-01-13 04:04:52 +01:00
|
|
|
cgit_close_filter(ctx.repo->email_filter);
|
2008-04-14 22:13:38 +02:00
|
|
|
html("</td><td colspan='2'>");
|
2016-01-19 20:33:05 +01:00
|
|
|
cgit_print_age(info->committer_date, info->committer_tz, -1);
|
2008-03-24 16:38:47 +01:00
|
|
|
} else {
|
|
|
|
html("</td><td></td><td>");
|
|
|
|
cgit_object_link(ref->object);
|
|
|
|
}
|
|
|
|
html("</td></tr>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
static void print_tag_header(void)
|
2008-03-24 16:38:47 +01:00
|
|
|
{
|
|
|
|
html("<tr class='nohover'><th class='left'>Tag</th>"
|
2008-12-01 21:56:07 +01:00
|
|
|
"<th class='left'>Download</th>"
|
2008-03-24 16:38:47 +01:00
|
|
|
"<th class='left'>Author</th>"
|
2008-04-14 22:13:38 +02:00
|
|
|
"<th class='left' colspan='2'>Age</th></tr>\n");
|
2008-03-24 16:38:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int print_tag(struct refinfo *ref)
|
|
|
|
{
|
2013-04-06 23:39:08 +02:00
|
|
|
struct tag *tag = NULL;
|
|
|
|
struct taginfo *info = NULL;
|
2008-10-05 21:19:05 +02:00
|
|
|
char *name = (char *)ref->refname;
|
2013-04-06 23:39:08 +02:00
|
|
|
struct object *obj = ref->object;
|
2008-03-24 16:38:47 +01:00
|
|
|
|
2013-04-06 23:39:08 +02:00
|
|
|
if (obj->type == OBJ_TAG) {
|
|
|
|
tag = (struct tag *)obj;
|
|
|
|
obj = tag->tagged;
|
2008-03-24 16:38:47 +01:00
|
|
|
info = ref->tag;
|
2015-10-09 00:23:59 +02:00
|
|
|
if (!info)
|
2008-03-24 16:38:47 +01:00
|
|
|
return 1;
|
2013-04-06 23:39:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
html("<tr><td>");
|
2015-01-15 23:18:14 +01:00
|
|
|
cgit_tag_link(name, NULL, NULL, name);
|
2013-04-06 23:39:08 +02:00
|
|
|
html("</td><td>");
|
|
|
|
if (ctx.repo->snapshots && (obj->type == OBJ_COMMIT))
|
2018-03-31 16:11:05 +02:00
|
|
|
cgit_print_snapshot_links(ctx.repo, name, " ");
|
2013-04-06 23:39:08 +02:00
|
|
|
else
|
|
|
|
cgit_object_link(obj);
|
|
|
|
html("</td><td>");
|
|
|
|
if (info) {
|
2014-01-13 04:04:52 +01:00
|
|
|
if (info->tagger) {
|
2014-01-13 16:24:40 +01:00
|
|
|
cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "refs");
|
2014-01-12 20:45:15 +01:00
|
|
|
html_txt(info->tagger);
|
2014-01-13 04:04:52 +01:00
|
|
|
cgit_close_filter(ctx.repo->email_filter);
|
|
|
|
}
|
2013-04-06 23:39:08 +02:00
|
|
|
} else if (ref->object->type == OBJ_COMMIT) {
|
2014-01-13 16:24:40 +01:00
|
|
|
cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email, "refs");
|
2014-01-12 20:45:15 +01:00
|
|
|
html_txt(ref->commit->author);
|
2014-01-13 04:04:52 +01:00
|
|
|
cgit_close_filter(ctx.repo->email_filter);
|
2013-04-06 23:39:08 +02:00
|
|
|
}
|
|
|
|
html("</td><td colspan='2'>");
|
|
|
|
if (info) {
|
2008-04-14 22:13:38 +02:00
|
|
|
if (info->tagger_date > 0)
|
2016-01-19 20:33:05 +01:00
|
|
|
cgit_print_age(info->tagger_date, info->tagger_tz, -1);
|
2013-04-06 23:39:08 +02:00
|
|
|
} else if (ref->object->type == OBJ_COMMIT) {
|
2016-01-19 20:33:05 +01:00
|
|
|
cgit_print_age(ref->commit->commit->date, 0, -1);
|
2008-03-24 16:38:47 +01:00
|
|
|
}
|
2013-04-06 23:39:08 +02:00
|
|
|
html("</td></tr>\n");
|
|
|
|
|
2008-03-24 16:38:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:25:01 +01:00
|
|
|
static void print_refs_link(const char *path)
|
2008-03-24 16:38:47 +01:00
|
|
|
{
|
2013-03-05 15:42:14 +01:00
|
|
|
html("<tr class='nohover'><td colspan='5'>");
|
2008-03-24 16:38:47 +01:00
|
|
|
cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path);
|
|
|
|
html("</td></tr>");
|
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_print_branches(int maxcount)
|
|
|
|
{
|
|
|
|
struct reflist list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
html("<tr class='nohover'><th class='left'>Branch</th>"
|
2008-04-14 22:13:38 +02:00
|
|
|
"<th class='left'>Commit message</th>"
|
2008-03-24 16:38:47 +01:00
|
|
|
"<th class='left'>Author</th>"
|
2008-04-14 22:13:38 +02:00
|
|
|
"<th class='left' colspan='2'>Age</th></tr>\n");
|
2008-03-24 16:38:47 +01:00
|
|
|
|
|
|
|
list.refs = NULL;
|
|
|
|
list.alloc = list.count = 0;
|
|
|
|
for_each_branch_ref(cgit_refs_cb, &list);
|
2009-11-07 19:10:58 +01:00
|
|
|
if (ctx.repo->enable_remote_branches)
|
|
|
|
for_each_remote_ref(cgit_refs_cb, &list);
|
2008-03-24 16:38:47 +01:00
|
|
|
|
|
|
|
if (maxcount == 0 || maxcount > list.count)
|
|
|
|
maxcount = list.count;
|
|
|
|
|
2013-04-08 16:57:12 +02:00
|
|
|
qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
|
|
|
|
if (ctx.repo->branch_sort == 0)
|
2008-03-24 16:38:47 +01:00
|
|
|
qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
|
|
|
|
|
2013-03-04 05:21:33 +01:00
|
|
|
for (i = 0; i < maxcount; i++)
|
2008-03-24 16:38:47 +01:00
|
|
|
print_branch(list.refs[i]);
|
|
|
|
|
|
|
|
if (maxcount < list.count)
|
|
|
|
print_refs_link("heads");
|
2013-03-04 13:25:33 +01:00
|
|
|
|
|
|
|
cgit_free_reflist_inner(&list);
|
2008-03-24 16:38:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_print_tags(int maxcount)
|
|
|
|
{
|
|
|
|
struct reflist list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
list.refs = NULL;
|
|
|
|
list.alloc = list.count = 0;
|
|
|
|
for_each_tag_ref(cgit_refs_cb, &list);
|
|
|
|
if (list.count == 0)
|
|
|
|
return;
|
|
|
|
qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
|
|
|
|
if (!maxcount)
|
|
|
|
maxcount = list.count;
|
|
|
|
else if (maxcount > list.count)
|
|
|
|
maxcount = list.count;
|
|
|
|
print_tag_header();
|
2013-03-04 05:21:33 +01:00
|
|
|
for (i = 0; i < maxcount; i++)
|
2008-03-24 16:38:47 +01:00
|
|
|
print_tag(list.refs[i]);
|
|
|
|
|
|
|
|
if (maxcount < list.count)
|
|
|
|
print_refs_link("tags");
|
2013-03-04 13:25:33 +01:00
|
|
|
|
|
|
|
cgit_free_reflist_inner(&list);
|
2008-03-24 16:38:47 +01:00
|
|
|
}
|
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
void cgit_print_refs(void)
|
2007-10-27 10:36:53 +02:00
|
|
|
{
|
2015-08-14 13:47:16 +02:00
|
|
|
cgit_print_layout_start();
|
2007-10-27 10:36:53 +02:00
|
|
|
html("<table class='list nowrap'>");
|
|
|
|
|
2014-05-29 17:35:46 +02:00
|
|
|
if (ctx.qry.path && starts_with(ctx.qry.path, "heads"))
|
2007-10-27 10:36:53 +02:00
|
|
|
cgit_print_branches(0);
|
2014-05-29 17:35:46 +02:00
|
|
|
else if (ctx.qry.path && starts_with(ctx.qry.path, "tags"))
|
2007-10-27 10:36:53 +02:00
|
|
|
cgit_print_tags(0);
|
|
|
|
else {
|
|
|
|
cgit_print_branches(0);
|
2013-03-05 15:42:14 +01:00
|
|
|
html("<tr class='nohover'><td colspan='5'> </td></tr>");
|
2007-10-27 10:36:53 +02:00
|
|
|
cgit_print_tags(0);
|
|
|
|
}
|
|
|
|
html("</table>");
|
2015-08-14 13:47:16 +02:00
|
|
|
cgit_print_layout_end();
|
2007-10-27 10:36:53 +02:00
|
|
|
}
|