all repos — cgit @ 426032f767763b46f462de51d1ebded34f671d79

a hyperfast web frontend for git written in c

ui-repolist.c (view raw)

  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
 13time_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
 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}
 44
 45void cgit_print_repolist(struct cacheitem *item)
 46{
 47	int i;
 48	char *last_group = NULL;
 49
 50	cgit_print_docstart(cgit_root_title, item);
 51	cgit_print_pageheader(cgit_root_title, 0);
 52
 53	html("<table class='list nowrap'>");
 54	if (cgit_index_header) {
 55		html("<tr class='nohover'><td colspan='5' class='include-block'>");
 56		html_include(cgit_index_header);
 57		html("</td></tr>");
 58	}
 59	html("<tr class='nohover'>"
 60	     "<th class='left'>Name</th>"
 61	     "<th class='left'>Description</th>"
 62	     "<th class='left'>Owner</th>"
 63	     "<th class='left'>Idle</th>"
 64	     "<th>Links</th></tr>\n");
 65
 66	for (i=0; i<cgit_repolist.count; i++) {
 67		cgit_repo = &cgit_repolist.repos[i];
 68		if ((last_group == NULL && cgit_repo->group != NULL) ||
 69		    (last_group != NULL && cgit_repo->group == NULL) ||
 70		    (last_group != NULL && cgit_repo->group != NULL &&
 71		     strcmp(cgit_repo->group, last_group))) {
 72			html("<tr class='nohover'><td colspan='4' class='repogroup'>");
 73			html_txt(cgit_repo->group);
 74			html("</td></tr>");
 75			last_group = cgit_repo->group;
 76		}
 77		htmlf("<tr><td class='%s'>",
 78		      cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
 79		html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
 80		html_txt(cgit_repo->name);
 81		html_link_close();
 82		html("</td><td>");
 83		html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
 84		html("</td><td>");
 85		html_txt(cgit_repo->owner);
 86		html("</td><td>");
 87		print_modtime(cgit_repo);
 88		html("</td><td>");
 89		html_link_open(cgit_repourl(cgit_repo->url),
 90			       "Summary", "button");
 91		html("S</a>");
 92		html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL),
 93			       "Log", "button");
 94		html("L</a>");
 95		cgit_tree_link("F", "Files", "button", NULL, NULL, NULL);
 96		html("</td></tr>\n");
 97	}
 98	html("</table>");
 99	cgit_print_docend();
100}