From d14d77fe95c3b6224b40df9b101dded0deea913c Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Feb 2008 11:53:40 +0100 Subject: Introduce struct cgit_context This struct will hold all the cgit runtime information currently found in a multitude of global variables. The first cleanup removes all querystring-related variables. Signed-off-by: Lars Hjemli --- ui-refs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index 295f5ba..ba513c1 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -16,9 +16,9 @@ void cgit_print_refs() html(""); - if (cgit_query_path && !strncmp(cgit_query_path, "heads", 5)) + if (ctx.qry.path && !strncmp(ctx.qry.path, "heads", 5)) cgit_print_branches(0); - else if (cgit_query_path && !strncmp(cgit_query_path, "tags", 4)) + else if (ctx.qry.path && !strncmp(ctx.qry.path, "tags", 4)) cgit_print_tags(0); else { cgit_print_branches(0); -- cgit v1.2.1 From b1f9b9c1459cb9a30ebf80721aff6ef788d1f891 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 23 Feb 2008 22:45:33 +0100 Subject: Introduce html.h All html-functions can be quite easily separated from the rest of cgit, so lets do it; the only issue was html_filemode which uses some git-defined macros so the function is moved into ui-shared.c::cgit_print_filemode(). Signed-off-by: Lars Hjemli --- ui-refs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index ba513c1..e2a16f4 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -7,9 +7,7 @@ */ #include "cgit.h" - - - +#include "html.h" void cgit_print_refs() { -- cgit v1.2.1 From c5984a9896b39748e61daf6e620483749654b102 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 16:38:47 +0100 Subject: Add separate header-files for each page/view Yet another step towards removing cgit.h. Signed-off-by: Lars Hjemli --- ui-refs.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index e2a16f4..fc82ca7 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -9,6 +9,178 @@ #include "cgit.h" #include "html.h" +static int header; + +static int cmp_age(int age1, int age2) +{ + if (age1 != 0 && age2 != 0) + return age2 - age1; + + if (age1 == 0 && age2 == 0) + return 0; + + if (age1 == 0) + return +1; + + return -1; +} + +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); +} + +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); +} + +static int print_branch(struct refinfo *ref) +{ + struct commitinfo *info = ref->commit; + char *name = (char *)ref->refname; + + if (!info) + return 1; + html("\n"); + return 0; +} + +static void print_tag_header() +{ + html("" + "" + "" + "\n"); + header = 1; +} + +static int print_tag(struct refinfo *ref) +{ + struct tag *tag; + struct taginfo *info; + char *url, *name = (char *)ref->refname; + + if (ref->object->type == OBJ_TAG) { + tag = (struct tag *)ref->object; + info = ref->tag; + if (!tag || !info) + return 1; + html("\n"); + } else { + if (!header) + print_tag_header(); + html("\n"); + } + return 0; +} + +static void print_refs_link(char *path) +{ + html(""); +} + +void cgit_print_branches(int maxcount) +{ + struct reflist list; + int i; + + html("" + "" + "" + "\n"); + + list.refs = NULL; + list.alloc = list.count = 0; + for_each_branch_ref(cgit_refs_cb, &list); + + 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 list.count) + maxcount = list.count; + print_tag_header(); + for(i=0; i Date: Mon, 24 Mar 2008 16:50:57 +0100 Subject: Add ui-shared.h This is finally a proper headerfile for the shared ui-functions which used to reside in cgit.h Signed-off-by: Lars Hjemli --- ui-refs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index fc82ca7..12533cd 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -8,6 +8,7 @@ #include "cgit.h" #include "html.h" +#include "ui-shared.h" static int header; -- cgit v1.2.1
"); + cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL); + html(""); + + if (ref->object->type == OBJ_COMMIT) { + cgit_print_age(info->commit->date, -1, NULL); + html(""); + html_txt(info->author); + html(""); + cgit_commit_link(info->subject, NULL, NULL, name, NULL); + } else { + html(""); + cgit_object_link(ref->object); + } + html("
TagAgeAuthorReference
"); + url = cgit_pageurl(ctx.qry.repo, "tag", + fmt("id=%s", name)); + html_link_open(url, NULL, NULL); + html_txt(name); + html_link_close(); + html(""); + if (info->tagger_date > 0) + cgit_print_age(info->tagger_date, -1, NULL); + html(""); + if (info->tagger) + html(info->tagger); + html(""); + cgit_object_link(tag->tagged); + html("
"); + html_txt(name); + html(""); + cgit_object_link(ref->object); + html("
"); + cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); + html("
BranchIdleAuthorHead commit