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