blob: c735368d78108725e9177cb87de691306060cda5 [file] [log] [blame]
Lars Hjemli74620f12006-12-11 16:48:03 +01001/* 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"
Lars Hjemli57f6a8b2007-05-22 23:25:25 +020010#include <time.h>
11
12
13time_t read_agefile(char *path)
14{
15 FILE *f;
16 static char buf[64], buf2[64];
Lars Hjemli57f6a8b2007-05-22 23:25:25 +020017
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
28static 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}
Lars Hjemli74620f12006-12-11 16:48:03 +010044
45void cgit_print_repolist(struct cacheitem *item)
46{
Lars Hjemli0d05bca2007-06-19 00:56:40 +020047 int i, columns = 4;
Lars Hjemli5877c492007-05-18 22:48:22 +020048 char *last_group = NULL;
Lars Hjemli74620f12006-12-11 16:48:03 +010049
Lars Hjemli0d05bca2007-06-19 00:56:40 +020050 if (cgit_enable_index_links)
51 columns++;
52
Lars Hjemli74620f12006-12-11 16:48:03 +010053 cgit_print_docstart(cgit_root_title, item);
Lars Hjemlie39d7382006-12-28 02:01:49 +010054 cgit_print_pageheader(cgit_root_title, 0);
Lars Hjemli74620f12006-12-11 16:48:03 +010055
Lars Hjemlic43f1242006-12-22 01:44:32 +010056 html("<table class='list nowrap'>");
Lars Hjemlide69ce02007-05-19 00:00:25 +020057 if (cgit_index_header) {
Lars Hjemli0d05bca2007-06-19 00:56:40 +020058 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>",
59 columns);
Lars Hjemlide69ce02007-05-19 00:00:25 +020060 html_include(cgit_index_header);
61 html("</td></tr>");
62 }
Lars Hjemli777faf72007-01-28 00:39:26 +010063 html("<tr class='nohover'>"
Lars Hjemlic43f1242006-12-22 01:44:32 +010064 "<th class='left'>Name</th>"
65 "<th class='left'>Description</th>"
Lars Hjemli8f6f8c32007-05-16 02:12:06 +020066 "<th class='left'>Owner</th>"
Lars Hjemli0d05bca2007-06-19 00:56:40 +020067 "<th class='left'>Idle</th>");
68 if (cgit_enable_index_links)
69 html("<th>Links</th>");
70 html("</tr>\n");
Lars Hjemli74620f12006-12-11 16:48:03 +010071
Lars Hjemlice1c7332007-02-03 15:02:55 +010072 for (i=0; i<cgit_repolist.count; i++) {
Lars Hjemli44947bf2007-06-17 01:23:08 +020073 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))) {
Lars Hjemli0d05bca2007-06-19 00:56:40 +020078 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
79 columns);
Lars Hjemli44947bf2007-06-17 01:23:08 +020080 html_txt(cgit_repo->group);
Lars Hjemli5877c492007-05-18 22:48:22 +020081 html("</td></tr>");
Lars Hjemli44947bf2007-06-17 01:23:08 +020082 last_group = cgit_repo->group;
Lars Hjemli5877c492007-05-18 22:48:22 +020083 }
Lars Hjemli0b8b6a32007-05-21 00:14:28 +020084 htmlf("<tr><td class='%s'>",
Lars Hjemli44947bf2007-06-17 01:23:08 +020085 cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
86 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
87 html_txt(cgit_repo->name);
Lars Hjemli74620f12006-12-11 16:48:03 +010088 html_link_close();
89 html("</td><td>");
Lars Hjemli44947bf2007-06-17 01:23:08 +020090 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
Lars Hjemli74620f12006-12-11 16:48:03 +010091 html("</td><td>");
Lars Hjemli44947bf2007-06-17 01:23:08 +020092 html_txt(cgit_repo->owner);
Lars Hjemli8f6f8c32007-05-16 02:12:06 +020093 html("</td><td>");
Lars Hjemli44947bf2007-06-17 01:23:08 +020094 print_modtime(cgit_repo);
Lars Hjemli0d05bca2007-06-19 00:56:40 +020095 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);
102 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
103 html("</td>");
104 }
105 html("</tr>\n");
Lars Hjemli74620f12006-12-11 16:48:03 +0100106 }
Lars Hjemli74620f12006-12-11 16:48:03 +0100107 html("</table>");
108 cgit_print_docend();
109}