1 /* ui-repolist.c: functions for generating the repolist page
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
13 time_t read_agefile(char *path)
16 static char buf[64], buf2[64];
18 if (!(f = fopen(path, "r")))
20 fgets(buf, sizeof(buf), f);
22 if (parse_date(buf, buf2, sizeof(buf2)))
23 return strtoul(buf2, NULL, 10);
28 static void print_modtime(struct repoinfo *repo)
33 path = fmt("%s/%s", repo->path, cgit_agefile);
34 if (stat(path, &s) == 0) {
35 cgit_print_age(read_agefile(path), -1, NULL);
39 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
40 if (stat(path, &s) != 0)
42 cgit_print_age(s.st_mtime, -1, NULL);
45 void cgit_print_repolist(struct cacheitem *item)
47 struct repoinfo *repo;
49 char *last_group = NULL;
51 cgit_print_docstart(cgit_root_title, item);
52 cgit_print_pageheader(cgit_root_title, 0);
54 html("<table class='list nowrap'>");
55 if (cgit_index_header) {
56 html("<tr class='nohover'><td colspan='5' class='include-block'>");
57 html_include(cgit_index_header);
60 html("<tr class='nohover'>"
61 "<th class='left'>Name</th>"
62 "<th class='left'>Description</th>"
63 "<th class='left'>Owner</th>"
64 "<th class='left'>Idle</th>"
65 "<th>Links</th></tr>\n");
67 for (i=0; i<cgit_repolist.count; i++) {
68 repo = &cgit_repolist.repos[i];
69 if ((last_group == NULL && repo->group != NULL) ||
70 (last_group != NULL && repo->group == NULL) ||
71 (last_group != NULL && repo->group!= NULL &&
72 strcmp(repo->group, last_group))) {
73 html("<tr class='nohover'><td colspan='4' class='repogroup'>");
74 html_txt(repo->group);
76 last_group = repo->group;
78 htmlf("<tr><td class='%s'>",
79 repo->group ? "sublevel-repo" : "toplevel-repo");
80 html_link_open(cgit_repourl(repo->url), repo->desc, NULL);
84 html_ntxt(cgit_max_repodesc_len, repo->desc);
86 html_txt(repo->owner);
90 html_link_open(cgit_repourl(repo->url),
93 html_link_open(cgit_pageurl(repo->name, "log", NULL),
96 html_link_open(cgit_pageurl(repo->name, "tree", NULL),