]> git.cameronkatri.com Git - cgit.git/blob - ui-repolist.c
Add ofs argument to cgit_log_link and use it in ui-log.c
[cgit.git] / ui-repolist.c
1 /* ui-repolist.c: functions for generating the repolist page
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9 #include "cgit.h"
10 #include <time.h>
11
12
13 time_t read_agefile(char *path)
14 {
15 FILE *f;
16 static char buf[64], buf2[64];
17
18 if (!(f = fopen(path, "r")))
19 return -1;
20 fgets(buf, sizeof(buf), f);
21 fclose(f);
22 if (parse_date(buf, buf2, sizeof(buf2)))
23 return strtoul(buf2, NULL, 10);
24 else
25 return 0;
26 }
27
28 static void print_modtime(struct repoinfo *repo)
29 {
30 char *path;
31 struct stat s;
32
33 path = fmt("%s/%s", repo->path, cgit_agefile);
34 if (stat(path, &s) == 0) {
35 cgit_print_age(read_agefile(path), -1, NULL);
36 return;
37 }
38
39 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
40 if (stat(path, &s) != 0)
41 return;
42 cgit_print_age(s.st_mtime, -1, NULL);
43 }
44
45 void cgit_print_repolist(struct cacheitem *item)
46 {
47 int i, columns = 4;
48 char *last_group = NULL;
49
50 if (cgit_enable_index_links)
51 columns++;
52
53 cgit_print_docstart(cgit_root_title, item);
54 cgit_print_pageheader(cgit_root_title, 0);
55
56 html("<table class='list nowrap'>");
57 if (cgit_index_header) {
58 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>",
59 columns);
60 html_include(cgit_index_header);
61 html("</td></tr>");
62 }
63 html("<tr class='nohover'>"
64 "<th class='left'>Name</th>"
65 "<th class='left'>Description</th>"
66 "<th class='left'>Owner</th>"
67 "<th class='left'>Idle</th>");
68 if (cgit_enable_index_links)
69 html("<th>Links</th>");
70 html("</tr>\n");
71
72 for (i=0; i<cgit_repolist.count; i++) {
73 cgit_repo = &cgit_repolist.repos[i];
74 if ((last_group == NULL && cgit_repo->group != NULL) ||
75 (last_group != NULL && cgit_repo->group == NULL) ||
76 (last_group != NULL && cgit_repo->group != NULL &&
77 strcmp(cgit_repo->group, last_group))) {
78 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
79 columns);
80 html_txt(cgit_repo->group);
81 html("</td></tr>");
82 last_group = cgit_repo->group;
83 }
84 htmlf("<tr><td class='%s'>",
85 cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
86 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
87 html_txt(cgit_repo->name);
88 html_link_close();
89 html("</td><td>");
90 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
91 html("</td><td>");
92 html_txt(cgit_repo->owner);
93 html("</td><td>");
94 print_modtime(cgit_repo);
95 html("</td>");
96 if (cgit_enable_index_links) {
97 html("<td>");
98 html_link_open(cgit_repourl(cgit_repo->url),
99 NULL, "button");
100 html("summary</a>");
101 cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0);
102 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
103 html("</td>");
104 }
105 html("</tr>\n");
106 }
107 html("</table>");
108 cgit_print_docend();
109 }