summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--Makefile20
-rw-r--r--cgit.c28
-rw-r--r--cgit.css100
-rw-r--r--cgit.h3
-rw-r--r--cgitrc.5.txt21
-rw-r--r--cmd.c7
-rw-r--r--shared.c1
-rwxr-xr-xtests/t0107-snapshot.sh22
-rw-r--r--ui-log.c38
-rw-r--r--ui-refs.c4
-rw-r--r--ui-shared.c22
-rw-r--r--ui-shared.h5
-rw-r--r--ui-snapshot.c10
-rw-r--r--ui-stats.c410
-rw-r--r--ui-stats.h27
-rw-r--r--ui-tag.c14
-rw-r--r--ui-tree.c3
17 files changed, 690 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index 3c7ec07..a52285e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,34 @@
CGIT_VERSION = v0.8.1
CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
+CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /etc/cgitrc
CACHE_ROOT = /var/cache/cgit
SHA1_HEADER = <openssl/sha.h>
GIT_VER = 1.6.1
GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
+INSTALL = install
# Define NO_STRCASESTR if you don't have strcasestr.
#
# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin).
#
#-include config.mak
#
# Platform specific tweaks
#
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
ifeq ($(uname_O),Cygwin)
NO_STRCASESTR = YesPlease
NEEDS_LIBICONV = YesPlease
endif
#
# Let the user override the above settings.
#
@@ -67,86 +69,88 @@ endif
EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
OBJECTS =
OBJECTS += cache.o
OBJECTS += cgit.o
OBJECTS += cmd.o
OBJECTS += configfile.o
OBJECTS += html.o
OBJECTS += parsing.o
OBJECTS += scan-tree.o
OBJECTS += shared.o
OBJECTS += ui-atom.o
OBJECTS += ui-blob.o
OBJECTS += ui-clone.o
OBJECTS += ui-commit.o
OBJECTS += ui-diff.o
OBJECTS += ui-log.o
OBJECTS += ui-patch.o
OBJECTS += ui-plain.o
OBJECTS += ui-refs.o
OBJECTS += ui-repolist.o
OBJECTS += ui-shared.o
OBJECTS += ui-snapshot.o
+OBJECTS += ui-stats.o
OBJECTS += ui-summary.o
OBJECTS += ui-tag.o
OBJECTS += ui-tree.o
ifdef NEEDS_LIBICONV
EXTLIBS += -liconv
endif
.PHONY: all libgit test install uninstall clean force-version get-git
all: cgit
VERSION: force-version
@./gen-version.sh "$(CGIT_VERSION)"
-include VERSION
CFLAGS += -g -Wall -Igit
CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
ifdef NO_ICONV
CFLAGS += -DNO_ICONV
endif
ifdef NO_STRCASESTR
CFLAGS += -DNO_STRCASESTR
endif
cgit: $(OBJECTS) libgit
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
cgit.o: VERSION
-include $(OBJECTS:.o=.d)
libgit:
- $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a
- $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a
+ $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a
+ $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a
test: all
$(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
install: all
- mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
- install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
- install -m 0644 cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css
- install -m 0644 cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png
+ $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH)
+ $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
+ $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
+ $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
+ $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
uninstall:
rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
- rm -f $(CGIT_SCRIPT_PATH)/cgit.css
- rm -f $(CGIT_SCRIPT_PATH)/cgit.png
+ rm -f $(CGIT_DATA_PATH)/cgit.css
+ rm -f $(CGIT_DATA_PATH)/cgit.png
clean:
rm -f cgit VERSION *.o *.d
get-git:
curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git
diff --git a/cgit.c b/cgit.c
index 166fbc6..608cab6 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,80 +1,83 @@
/* cgit.c: cgi for the git scm
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "cache.h"
#include "cmd.h"
#include "configfile.h"
#include "html.h"
#include "ui-shared.h"
+#include "ui-stats.h"
#include "scan-tree.h"
const char *cgit_version = CGIT_VERSION;
void config_cb(const char *name, const char *value)
{
if (!strcmp(name, "root-title"))
ctx.cfg.root_title = xstrdup(value);
else if (!strcmp(name, "root-desc"))
ctx.cfg.root_desc = xstrdup(value);
else if (!strcmp(name, "root-readme"))
ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css"))
ctx.cfg.css = xstrdup(value);
else if (!strcmp(name, "favicon"))
ctx.cfg.favicon = xstrdup(value);
else if (!strcmp(name, "footer"))
ctx.cfg.footer = xstrdup(value);
else if (!strcmp(name, "logo"))
ctx.cfg.logo = xstrdup(value);
else if (!strcmp(name, "index-header"))
ctx.cfg.index_header = xstrdup(value);
else if (!strcmp(name, "index-info"))
ctx.cfg.index_info = xstrdup(value);
else if (!strcmp(name, "logo-link"))
ctx.cfg.logo_link = xstrdup(value);
else if (!strcmp(name, "module-link"))
ctx.cfg.module_link = xstrdup(value);
else if (!strcmp(name, "virtual-root")) {
ctx.cfg.virtual_root = trim_end(value, '/');
if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
ctx.cfg.virtual_root = "";
} else if (!strcmp(name, "nocache"))
ctx.cfg.nocache = atoi(value);
else if (!strcmp(name, "snapshots"))
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
else if (!strcmp(name, "enable-index-links"))
ctx.cfg.enable_index_links = atoi(value);
else if (!strcmp(name, "enable-log-filecount"))
ctx.cfg.enable_log_filecount = atoi(value);
else if (!strcmp(name, "enable-log-linecount"))
ctx.cfg.enable_log_linecount = atoi(value);
+ else if (!strcmp(name, "max-stats"))
+ ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
else if (!strcmp(name, "cache-size"))
ctx.cfg.cache_size = atoi(value);
else if (!strcmp(name, "cache-root"))
ctx.cfg.cache_root = xstrdup(value);
else if (!strcmp(name, "cache-root-ttl"))
ctx.cfg.cache_root_ttl = atoi(value);
else if (!strcmp(name, "cache-repo-ttl"))
ctx.cfg.cache_repo_ttl = atoi(value);
else if (!strcmp(name, "cache-static-ttl"))
ctx.cfg.cache_static_ttl = atoi(value);
else if (!strcmp(name, "cache-dynamic-ttl"))
ctx.cfg.cache_dynamic_ttl = atoi(value);
else if (!strcmp(name, "max-message-length"))
ctx.cfg.max_msg_len = atoi(value);
else if (!strcmp(name, "max-repodesc-length"))
ctx.cfg.max_repodesc_len = atoi(value);
else if (!strcmp(name, "max-repo-count"))
ctx.cfg.max_repo_count = atoi(value);
else if (!strcmp(name, "max-commit-count"))
ctx.cfg.max_commit_count = atoi(value);
else if (!strcmp(name, "summary-log"))
ctx.cfg.summary_log = atoi(value);
else if (!strcmp(name, "summary-branches"))
ctx.cfg.summary_branches = atoi(value);
@@ -91,117 +94,122 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "local-time"))
ctx.cfg.local_time = atoi(value);
else if (!strcmp(name, "repo.group"))
ctx.cfg.repo_group = xstrdup(value);
else if (!strcmp(name, "repo.url"))
ctx.repo = cgit_add_repo(value);
else if (!strcmp(name, "repo.name"))
ctx.repo->name = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.path"))
ctx.repo->path = trim_end(value, '/');
else if (ctx.repo && !strcmp(name, "repo.clone-url"))
ctx.repo->clone_url = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.desc"))
ctx.repo->desc = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.owner"))
ctx.repo->owner = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.defbranch"))
ctx.repo->defbranch = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.snapshots"))
ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
+ else if (ctx.repo && !strcmp(name, "repo.max-stats"))
+ ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
else if (ctx.repo && !strcmp(name, "repo.module-link"))
ctx.repo->module_link= xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
if (*value == '/')
ctx.repo->readme = xstrdup(value);
else
ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
} else if (!strcmp(name, "include"))
parse_configfile(value, config_cb);
}
static void querystring_cb(const char *name, const char *value)
{
if (!strcmp(name,"r")) {
ctx.qry.repo = xstrdup(value);
ctx.repo = cgit_get_repoinfo(value);
} else if (!strcmp(name, "p")) {
ctx.qry.page = xstrdup(value);
} else if (!strcmp(name, "url")) {
ctx.qry.url = xstrdup(value);
cgit_parse_url(value);
} else if (!strcmp(name, "qt")) {
ctx.qry.grep = xstrdup(value);
} else if (!strcmp(name, "q")) {
ctx.qry.search = xstrdup(value);
} else if (!strcmp(name, "h")) {
ctx.qry.head = xstrdup(value);
ctx.qry.has_symref = 1;
} else if (!strcmp(name, "id")) {
ctx.qry.sha1 = xstrdup(value);
ctx.qry.has_sha1 = 1;
} else if (!strcmp(name, "id2")) {
ctx.qry.sha2 = xstrdup(value);
ctx.qry.has_sha1 = 1;
} else if (!strcmp(name, "ofs")) {
ctx.qry.ofs = atoi(value);
} else if (!strcmp(name, "path")) {
ctx.qry.path = trim_end(value, '/');
} else if (!strcmp(name, "name")) {
ctx.qry.name = xstrdup(value);
} else if (!strcmp(name, "mimetype")) {
ctx.qry.mimetype = xstrdup(value);
} else if (!strcmp(name, "s")){
ctx.qry.sort = xstrdup(value);
} else if (!strcmp(name, "showmsg")) {
ctx.qry.showmsg = atoi(value);
+ } else if (!strcmp(name, "period")) {
+ ctx.qry.period = xstrdup(value);
}
}
static void prepare_context(struct cgit_context *ctx)
{
memset(ctx, 0, sizeof(ctx));
ctx->cfg.agefile = "info/web/last-modified";
ctx->cfg.nocache = 0;
ctx->cfg.cache_size = 0;
ctx->cfg.cache_dynamic_ttl = 5;
ctx->cfg.cache_max_create_time = 5;
ctx->cfg.cache_repo_ttl = 5;
ctx->cfg.cache_root = CGIT_CACHE_ROOT;
ctx->cfg.cache_root_ttl = 5;
ctx->cfg.cache_static_ttl = -1;
ctx->cfg.css = "/cgit.css";
ctx->cfg.logo = "/git-logo.png";
ctx->cfg.local_time = 0;
ctx->cfg.max_repo_count = 50;
ctx->cfg.max_commit_count = 50;
ctx->cfg.max_lock_attempts = 5;
ctx->cfg.max_msg_len = 80;
ctx->cfg.max_repodesc_len = 80;
+ ctx->cfg.max_stats = 0;
ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
ctx->cfg.renamelimit = -1;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
ctx->cfg.summary_branches = 10;
ctx->cfg.summary_log = 10;
ctx->cfg.summary_tags = 10;
ctx->page.mimetype = "text/html";
ctx->page.charset = PAGE_ENCODING;
ctx->page.filename = NULL;
ctx->page.size = 0;
ctx->page.modified = time(NULL);
ctx->page.expires = ctx->page.modified;
}
struct refmatch {
char *req_ref;
char *first_ref;
int match;
};
int find_current_ref(const char *refname, const unsigned char *sha1,
@@ -272,49 +280,48 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
return 1;
}
if (get_sha1(ctx->qry.head, sha1)) {
tmp = xstrdup(ctx->qry.head);
ctx->qry.head = ctx->repo->defbranch;
cgit_print_http_headers(ctx);
cgit_print_docstart(ctx);
cgit_print_pageheader(ctx);
cgit_print_error(fmt("Invalid branch: %s", tmp));
cgit_print_docend();
return 1;
}
return 0;
}
static void process_request(void *cbdata)
{
struct cgit_context *ctx = cbdata;
struct cgit_cmd *cmd;
cmd = cgit_get_cmd(ctx);
if (!cmd) {
ctx->page.title = "cgit error";
- ctx->repo = NULL;
cgit_print_http_headers(ctx);
cgit_print_docstart(ctx);
cgit_print_pageheader(ctx);
cgit_print_error("Invalid request");
cgit_print_docend();
return;
}
if (cmd->want_repo && !ctx->repo) {
cgit_print_http_headers(ctx);
cgit_print_docstart(ctx);
cgit_print_pageheader(ctx);
cgit_print_error(fmt("No repository selected"));
cgit_print_docend();
return;
}
if (ctx->repo && prepare_repo_cmd(ctx))
return;
if (cmd->want_layout) {
cgit_print_http_headers(ctx);
cgit_print_docstart(ctx);
cgit_print_pageheader(ctx);
@@ -418,59 +425,60 @@ static int calc_ttl()
}
int main(int argc, const char **argv)
{
const char *cgit_config_env = getenv("CGIT_CONFIG");
const char *path;
char *qry;
int err, ttl;
prepare_context(&ctx);
cgit_repolist.length = 0;
cgit_repolist.count = 0;
cgit_repolist.repos = NULL;
if (getenv("SCRIPT_NAME"))
ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
if (getenv("QUERY_STRING"))
ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
cgit_parse_args(argc, argv);
parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
config_cb);
ctx.repo = NULL;
http_parse_querystring(ctx.qry.raw, querystring_cb);
- /* If virtual-root isn't specified in cgitrc and no url
- * parameter is specified on the querystring, lets pretend
- * that virtualroot equals SCRIPT_NAME and use PATH_INFO as
- * url. This allows cgit to work with virtual urls without
- * the need for rewriterules in the webserver (as long as
- * PATH_INFO is included in the cache lookup key).
+ /* If virtual-root isn't specified in cgitrc, lets pretend
+ * that virtual-root equals SCRIPT_NAME.
*/
- if (!ctx.cfg.virtual_root && !ctx.qry.url) {
+ if (!ctx.cfg.virtual_root)
ctx.cfg.virtual_root = ctx.cfg.script_name;
+
+ /* If no url parameter is specified on the querystring, lets
+ * use PATH_INFO as url. This allows cgit to work with virtual
+ * urls without the need for rewriterules in the webserver (as
+ * long as PATH_INFO is included in the cache lookup key).
+ */
path = getenv("PATH_INFO");
- if (path) {
+ if (!ctx.qry.url && path) {
if (path[0] == '/')
path++;
ctx.qry.url = xstrdup(path);
if (ctx.qry.raw) {
qry = ctx.qry.raw;
ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
free(qry);
} else
ctx.qry.raw = ctx.qry.url;
cgit_parse_url(ctx.qry.url);
}
- }
ttl = calc_ttl();
ctx.page.expires += ttl*60;
if (ctx.cfg.nocache)
ctx.cfg.cache_size = 0;
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
ctx.qry.raw, ttl, process_request, &ctx);
if (err)
cgit_print_error(fmt("Error processing page: %s (%d)",
strerror(err), err));
return err;
}
diff --git a/cgit.css b/cgit.css
index 068c37b..f844efa 100644
--- a/cgit.css
+++ b/cgit.css
@@ -455,24 +455,124 @@ span.age-hours {
color: #080;
}
span.age-days {
color: #040;
}
span.age-weeks {
color: #444;
}
span.age-months {
color: #888;
}
span.age-years {
color: #bbb;
}
div.footer {
margin-top: 0.5em;
text-align: center;
font-size: 80%;
color: #ccc;
}
+a.branch-deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #88ff88;
+ border: solid 1px #007700;
+}
+a.tag-deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #ffff88;
+ border: solid 1px #777700;
+}
+a.remote-deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #ccccff;
+ border: solid 1px #000077;
+}
+a.deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #ff8888;
+ border: solid 1px #770000;
+}
+table.stats {
+ border: solid 1px black;
+ border-collapse: collapse;
+}
+
+table.stats th {
+ text-align: left;
+ padding: 1px 0.5em;
+ background-color: #eee;
+ border: solid 1px black;
+}
+
+table.stats td {
+ text-align: right;
+ padding: 1px 0.5em;
+ border: solid 1px black;
+}
+
+table.stats td.total {
+ font-weight: bold;
+ text-align: left;
+}
+
+table.stats td.sum {
+ color: #c00;
+ font-weight: bold;
+/* background-color: #eee; */
+}
+
+table.stats td.left {
+ text-align: left;
+}
+
+table.vgraph {
+ border-collapse: separate;
+ border: solid 1px black;
+ height: 200px;
+}
+
+table.vgraph th {
+ background-color: #eee;
+ font-weight: bold;
+ border: solid 1px white;
+ padding: 1px 0.5em;
+}
+
+table.vgraph td {
+ vertical-align: bottom;
+ padding: 0px 10px;
+}
+
+table.vgraph div.bar {
+ background-color: #eee;
+}
+
+table.hgraph {
+ border: solid 1px black;
+ width: 800px;
+}
+
+table.hgraph th {
+ background-color: #eee;
+ font-weight: bold;
+ border: solid 1px black;
+ padding: 1px 0.5em;
+}
+
+table.hgraph td {
+ vertical-align: center;
+ padding: 2px 2px;
+}
+
+table.hgraph div.bar {
+ background-color: #eee;
+ height: 1em;
+}
diff --git a/cgit.h b/cgit.h
index cb2f176..4fe94c6 100644
--- a/cgit.h
+++ b/cgit.h
@@ -40,48 +40,49 @@
/*
* Default encoding
*/
#define PAGE_ENCODING "UTF-8"
typedef void (*configfn)(const char *name, const char *value);
typedef void (*filepair_fn)(struct diff_filepair *pair);
typedef void (*linediff_fn)(char *line, int len);
struct cgit_repo {
char *url;
char *name;
char *path;
char *desc;
char *owner;
char *defbranch;
char *group;
char *module_link;
char *readme;
char *clone_url;
int snapshots;
int enable_log_filecount;
int enable_log_linecount;
+ int max_stats;
time_t mtime;
};
struct cgit_repolist {
int length;
int count;
struct cgit_repo *repos;
};
struct commitinfo {
struct commit *commit;
char *author;
char *author_email;
unsigned long author_date;
char *committer;
char *committer_email;
unsigned long committer_date;
char *subject;
char *msg;
char *msg_encoding;
};
struct taginfo {
char *tagger;
@@ -99,88 +100,90 @@ struct refinfo {
};
};
struct reflist {
struct refinfo **refs;
int alloc;
int count;
};
struct cgit_query {
int has_symref;
int has_sha1;
char *raw;
char *repo;
char *page;
char *search;
char *grep;
char *head;
char *sha1;
char *sha2;
char *path;
char *name;
char *mimetype;
char *url;
+ char *period;
int ofs;
int nohead;
char *sort;
int showmsg;
};
struct cgit_config {
char *agefile;
char *cache_root;
char *clone_prefix;
char *css;
char *favicon;
char *footer;
char *index_header;
char *index_info;
char *logo;
char *logo_link;
char *module_link;
char *repo_group;
char *robots;
char *root_title;
char *root_desc;
char *root_readme;
char *script_name;
char *virtual_root;
int cache_size;
int cache_dynamic_ttl;
int cache_max_create_time;
int cache_repo_ttl;
int cache_root_ttl;
int cache_static_ttl;
int enable_index_links;
int enable_log_filecount;
int enable_log_linecount;
int local_time;
int max_repo_count;
int max_commit_count;
int max_lock_attempts;
int max_msg_len;
int max_repodesc_len;
+ int max_stats;
int nocache;
int renamelimit;
int snapshots;
int summary_branches;
int summary_log;
int summary_tags;
};
struct cgit_page {
time_t modified;
time_t expires;
size_t size;
char *mimetype;
char *charset;
char *filename;
char *title;
};
struct cgit_context {
struct cgit_query qry;
struct cgit_config cfg;
struct cgit_repo *repo;
struct cgit_page page;
};
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 7887b02..09f56a6 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -108,48 +108,53 @@ logo
Url which specifies the source of an image which will be used as a logo
on all cgit pages.
logo-link
Url loaded when clicking on the cgit logo image. If unspecified the
calculated url of the repository index page will be used. Default
value: none.
max-commit-count
Specifies the number of entries to list per page in "log" view. Default
value: "50".
max-message-length
Specifies the maximum number of commit message characters to display in
"log" view. Default value: "80".
max-repo-count
Specifies the number of entries to list per page on the repository
index page. Default value: "50".
max-repodesc-length
Specifies the maximum number of repo description characters to display
on the repository index page. Default value: "80".
+max-stats
+ Set the default maximum statistics period. Valid values are "week",
+ "month", "quarter" and "year". If unspecified, statistics are
+ disabled. Default value: none. See also: "repo.max-stats".
+
module-link
Text which will be used as the formatstring for a hyperlink when a
submodule is printed in a directory listing. The arguments for the
formatstring are the path and SHA1 of the submodule commit. Default
value: "./?repo=%s&page=commit&id=%s"
nocache
If set to the value "1" caching will be disabled. This settings is
deprecated, and will not be honored starting with cgit-1.0. Default
value: "0".
renamelimit
Maximum number of files to consider when detecting renames. The value
"-1" uses the compiletime value in git (for further info, look at
`man git-diff`). Default value: "-1".
repo.group
A value for the current repository group, which all repositories
specified after this setting will inherit. Default value: none.
robots
Text used as content for the "robots" meta-tag. Default value:
"index, nofollow".
@@ -197,48 +202,53 @@ virtual-root
same kind of virtual urls, so this option will probably be deprecated.
REPOSITORY SETTINGS
-------------------
repo.clone-url
A list of space-separated urls which can be used to clone this repo.
Default value: none.
repo.defbranch
The name of the default branch for this repository. If no such branch
exists in the repository, the first branch name (when sorted) is used
as default instead. Default value: "master".
repo.desc
The value to show as repository description. Default value: none.
repo.enable-log-filecount
A flag which can be used to disable the global setting
`enable-log-filecount'. Default value: none.
repo.enable-log-linecount
A flag which can be used to disable the global setting
`enable-log-linecount'. Default value: none.
+repo.max-stats
+ Override the default maximum statistics period. Valid values are equal
+ to the values specified for the global "max-stats" setting. Default
+ value: none.
+
repo.name
The value to show as repository name. Default value: <repo.url>.
repo.owner
A value used to identify the owner of the repository. Default value:
none.
repo.path
An absolute path to the repository directory. For non-bare repositories
this is the .git-directory. Default value: none.
repo.readme
A path (relative to <repo.path>) which specifies a file to include
verbatim as the "About" page for this repo. Default value: none.
repo.snapshots
A mask of allowed snapshot-formats for this repo, restricted by the
"snapshots" global setting. Default value: <snapshots>.
repo.url
The relative url used to access the repository. This must be the first
setting specified for each repo. Default value: none.
@@ -255,62 +265,66 @@ clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git
# Specify the css url
css=/css/cgit.css
# Show extra links for each repository on the index page
enable-index-links=1
# Show number of affected files per commit on the log pages
enable-log-filecount=1
# Show number of added/removed lines per commit on the log pages
enable-log-linecount=1
# Add a cgit favicon
favicon=/favicon.ico
# Use a custom logo
logo=/img/mylogo.png
+# Enable statistics per week, month and quarter
+max-stats=quarter
+
+
# Set the title and heading of the repository index page
root-title=foobar.com git repositories
# Set a subheading for the repository index page
root-desc=tracking the foobar development
# Include some more info about foobar.com on the index page
root-readme=/var/www/htdocs/about.html
-# Allow download of tar.gz, tar.bz and zip-files
-snapshots=tar.gz tar.bz zip
+# Allow download of tar.gz, tar.bz2 and zip-files
+snapshots=tar.gz tar.bz2 zip
##
## List of repositories.
## PS: Any repositories listed when repo.group is unset will not be
## displayed under a group heading
## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos')
## and included like this:
## include=/etc/cgitrepos
##
repo.url=foo
repo.path=/pub/git/foo.git
repo.desc=the master foo repository
repo.owner=fooman@foobar.com
repo.readme=info/web/about.html
repo.url=bar
repo.path=/pub/git/bar.git
repo.desc=the bars for your foo
repo.owner=barman@foobar.com
repo.readme=info/web/about.html
@@ -327,41 +341,44 @@ repo.desc=a set of extensions for bar users
repo.url=wiz
repo.path=/pub/git/wiz.git
repo.desc=the wizard of foo
# Add some mirrored repositories
repo.group=mirrors
repo.url=git
repo.path=/pub/git/git.git
repo.desc=the dscm
repo.url=linux
repo.path=/pub/git/linux.git
repo.desc=the kernel
# Disable adhoc downloads of this repo
repo.snapshots=0
# Disable line-counts for this repo
repo.enable-log-linecount=0
+# Restrict the max statistics period for this repo
+repo.max-stats=month
+
BUGS
----
Comments currently cannot appear on the same line as a setting; the comment
will be included as part of the value. E.g. this line:
robots=index # allow indexing
will generate the following html element:
<meta name='robots' content='index # allow indexing'/>
AUTHOR
------
Lars Hjemli <hjemli@gmail.com>
diff --git a/cmd.c b/cmd.c
index 8914fa5..cf97da7 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,47 +1,48 @@
/* cmd.c: the cgit command dispatcher
*
* Copyright (C) 2008 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "cmd.h"
#include "cache.h"
#include "ui-shared.h"
#include "ui-atom.h"
#include "ui-blob.h"
#include "ui-clone.h"
#include "ui-commit.h"
#include "ui-diff.h"
#include "ui-log.h"
#include "ui-patch.h"
#include "ui-plain.h"
#include "ui-refs.h"
#include "ui-repolist.h"
#include "ui-snapshot.h"
+#include "ui-stats.h"
#include "ui-summary.h"
#include "ui-tag.h"
#include "ui-tree.h"
static void HEAD_fn(struct cgit_context *ctx)
{
cgit_clone_head(ctx);
}
static void atom_fn(struct cgit_context *ctx)
{
cgit_print_atom(ctx->qry.head, ctx->qry.path, 10);
}
static void about_fn(struct cgit_context *ctx)
{
if (ctx->repo)
cgit_print_repo_readme();
else
cgit_print_site_readme();
}
static void blob_fn(struct cgit_context *ctx)
{
@@ -87,78 +88,84 @@ static void repolist_fn(struct cgit_context *ctx)
cgit_print_repolist();
}
static void patch_fn(struct cgit_context *ctx)
{
cgit_print_patch(ctx->qry.sha1);
}
static void plain_fn(struct cgit_context *ctx)
{
cgit_print_plain(ctx);
}
static void refs_fn(struct cgit_context *ctx)
{
cgit_print_refs();
}
static void snapshot_fn(struct cgit_context *ctx)
{
cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path,
ctx->repo->snapshots, ctx->qry.nohead);
}
+static void stats_fn(struct cgit_context *ctx)
+{
+ cgit_show_stats(ctx);
+}
+
static void summary_fn(struct cgit_context *ctx)
{
cgit_print_summary();
}
static void tag_fn(struct cgit_context *ctx)
{
cgit_print_tag(ctx->qry.sha1);
}
static void tree_fn(struct cgit_context *ctx)
{
cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
}
#define def_cmd(name, want_repo, want_layout) \
{#name, name##_fn, want_repo, want_layout}
struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
{
static struct cgit_cmd cmds[] = {
def_cmd(HEAD, 1, 0),
def_cmd(atom, 1, 0),
def_cmd(about, 0, 1),
def_cmd(blob, 1, 0),
def_cmd(commit, 1, 1),
def_cmd(diff, 1, 1),
def_cmd(info, 1, 0),
def_cmd(log, 1, 1),
def_cmd(ls_cache, 0, 0),
def_cmd(objects, 1, 0),
def_cmd(patch, 1, 0),
def_cmd(plain, 1, 0),
def_cmd(refs, 1, 1),
def_cmd(repolist, 0, 0),
def_cmd(snapshot, 1, 0),
+ def_cmd(stats, 1, 1),
def_cmd(summary, 1, 1),
def_cmd(tag, 1, 1),
def_cmd(tree, 1, 1),
};
int i;
if (ctx->qry.page == NULL) {
if (ctx->repo)
ctx->qry.page = "summary";
else
ctx->qry.page = "repolist";
}
for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
if (!strcmp(ctx->qry.page, cmds[i].name))
return &cmds[i];
return NULL;
}
diff --git a/shared.c b/shared.c
index a764c4d..578a544 100644
--- a/shared.c
+++ b/shared.c
@@ -37,48 +37,49 @@ struct cgit_repo *cgit_add_repo(const char *url)
{
struct cgit_repo *ret;
if (++cgit_repolist.count > cgit_repolist.length) {
if (cgit_repolist.length == 0)
cgit_repolist.length = 8;
else
cgit_repolist.length *= 2;
cgit_repolist.repos = xrealloc(cgit_repolist.repos,
cgit_repolist.length *
sizeof(struct cgit_repo));
}
ret = &cgit_repolist.repos[cgit_repolist.count-1];
ret->url = trim_end(url, '/');
ret->name = ret->url;
ret->path = NULL;
ret->desc = "[no description]";
ret->owner = NULL;
ret->group = ctx.cfg.repo_group;
ret->defbranch = "master";
ret->snapshots = ctx.cfg.snapshots;
ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
+ ret->max_stats = ctx.cfg.max_stats;
ret->module_link = ctx.cfg.module_link;
ret->readme = NULL;
ret->mtime = -1;
return ret;
}
struct cgit_repo *cgit_get_repoinfo(const char *url)
{
int i;
struct cgit_repo *repo;
for (i=0; i<cgit_repolist.count; i++) {
repo = &cgit_repolist.repos[i];
if (!strcmp(repo->url, url))
return repo;
}
return NULL;
}
void *cgit_free_commitinfo(struct commitinfo *info)
{
free(info->author);
free(info->author_email);
free(info->committer);
diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
index d97c465..8ab4912 100755
--- a/tests/t0107-snapshot.sh
+++ b/tests/t0107-snapshot.sh
@@ -1,39 +1,39 @@
#!/bin/sh
. ./setup.sh
prepare_tests "Verify snapshot"
-run_test 'get foo/snapshot/test.tar.gz' '
- cgit_url "foo/snapshot/test.tar.gz" >trash/tmp
+run_test 'get foo/snapshot/master.tar.gz' '
+ cgit_url "foo/snapshot/master.tar.gz" >trash/tmp
'
run_test 'check html headers' '
head -n 1 trash/tmp |
- grep -e "Content-Type: application/x-tar" &&
+ grep -e "Content-Type: application/x-gzip" &&
head -n 2 trash/tmp |
- grep -e "Content-Disposition: inline; filename=.test.tar.gz."
+ grep -e "Content-Disposition: inline; filename=.master.tar.gz."
'
run_test 'strip off the header lines' '
- tail -n +6 trash/tmp > trash/test.tar.gz
+ tail -n +6 trash/tmp > trash/master.tar.gz
'
-run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz'
+run_test 'verify gzip format' 'gunzip --test trash/master.tar.gz'
run_test 'untar' '
- rm -rf trash/foo &&
- tar -xf trash/test.tar.gz -C trash
+ rm -rf trash/master &&
+ tar -xf trash/master.tar.gz -C trash
'
run_test 'count files' '
- c=$(ls -1 trash/foo/ | wc -l) &&
+ c=$(ls -1 trash/master/ | wc -l) &&
test $c = 5
'
run_test 'verify untarred file-5' '
- grep -e "^5$" trash/foo/file-5 &&
- test $(cat trash/foo/file-5 | wc -l) = 1
+ grep -e "^5$" trash/master/file-5 &&
+ test $(cat trash/master/file-5 | wc -l) = 1
'
tests_done
diff --git a/ui-log.c b/ui-log.c
index 2f90778..3202848 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -10,66 +10,99 @@
#include "html.h"
#include "ui-shared.h"
int files, add_lines, rem_lines;
void count_lines(char *line, int size)
{
if (size <= 0)
return;
if (line[0] == '+')
add_lines++;
else if (line[0] == '-')
rem_lines++;
}
void inspect_files(struct diff_filepair *pair)
{
files++;
if (ctx.repo->enable_log_linecount)
cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
}
+void show_commit_decorations(struct commit *commit)
+{
+ struct name_decoration *deco;
+ static char buf[1024];
+
+ buf[sizeof(buf) - 1] = 0;
+ deco = lookup_decoration(&name_decoration, &commit->object);
+ while (deco) {
+ if (!prefixcmp(deco->name, "refs/heads/")) {
+ strncpy(buf, deco->name + 11, sizeof(buf) - 1);
+ cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
+ 0, NULL, NULL, ctx.qry.showmsg);
+ }
+ else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
+ strncpy(buf, deco->name + 15, sizeof(buf) - 1);
+ cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
+ }
+ else if (!prefixcmp(deco->name, "refs/remotes/")) {
+ strncpy(buf, deco->name + 13, sizeof(buf) - 1);
+ cgit_log_link(buf, NULL, "remote-deco", NULL,
+ sha1_to_hex(commit->object.sha1), NULL,
+ 0, NULL, NULL, ctx.qry.showmsg);
+ }
+ else {
+ strncpy(buf, deco->name, sizeof(buf) - 1);
+ cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
+ sha1_to_hex(commit->object.sha1));
+ }
+ deco = deco->next;
+ }
+}
+
void print_commit(struct commit *commit)
{
struct commitinfo *info;
char *tmp;
int cols = 2;
info = cgit_parse_commit(commit);
htmlf("<tr%s><td>",
ctx.qry.showmsg ? " class='logheader'" : "");
tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
html_link_open(tmp, NULL, NULL);
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
html_link_close();
htmlf("</td><td%s>",
ctx.qry.showmsg ? " class='logsubject'" : "");
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
sha1_to_hex(commit->object.sha1));
+ show_commit_decorations(commit);
html("</td><td>");
html_txt(info->author);
if (ctx.repo->enable_log_filecount) {
files = 0;
add_lines = 0;
rem_lines = 0;
cgit_diff_commit(commit, inspect_files);
html("</td><td>");
htmlf("%d", files);
if (ctx.repo->enable_log_linecount) {
html("</td><td>");
htmlf("-%d/+%d", rem_lines, add_lines);
}
}
html("</td></tr>\n");
if (ctx.qry.showmsg) {
if (ctx.repo->enable_log_filecount) {
cols++;
if (ctx.repo->enable_log_linecount)
cols++;
}
htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
cols);
html_txt(info->msg);
@@ -98,60 +131,63 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
int argc = 2;
int i, columns = 3;
if (!tip)
tip = ctx.qry.head;
argv[1] = disambiguate_ref(tip);
if (grep && pattern && (!strcmp(grep, "grep") ||
!strcmp(grep, "author") ||
!strcmp(grep, "committer")))
argv[argc++] = fmt("--%s=%s", grep, pattern);
if (path) {
argv[argc++] = "--";
argv[argc++] = path;
}
init_revisions(&rev, NULL);
rev.abbrev = DEFAULT_ABBREV;
rev.commit_format = CMIT_FMT_DEFAULT;
rev.verbose_header = 1;
rev.show_root_diff = 0;
setup_revisions(argc, argv, &rev, NULL);
+ load_ref_decorations();
+ rev.show_decorations = 1;
rev.grep_filter.regflags |= REG_ICASE;
compile_grep_patterns(&rev.grep_filter);
prepare_revision_walk(&rev);
if (pager)
html("<table class='list nowrap'>");
html("<tr class='nohover'><th class='left'>Age</th>"
"<th class='left'>Commit message");
if (pager) {
html(" (");
- cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
+ cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
+ NULL, ctx.qry.head, ctx.qry.sha1,
ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
html(")");
}
html("</th><th class='left'>Author</th>");
if (ctx.repo->enable_log_filecount) {
html("<th class='left'>Files</th>");
columns++;
if (ctx.repo->enable_log_linecount) {
html("<th class='left'>Lines</th>");
columns++;
}
}
html("</tr>\n");
if (ofs<0)
ofs = 0;
for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
free(commit->buffer);
commit->buffer = NULL;
free_commit_list(commit->parents);
commit->parents = NULL;
}
diff --git a/ui-refs.c b/ui-refs.c
index d61ee7c..25da00a 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -118,51 +118,51 @@ static int print_tag(struct refinfo *ref)
if (ref->object->type == OBJ_TAG) {
tag = (struct tag *)ref->object;
info = ref->tag;
if (!tag || !info)
return 1;
html("<tr><td>");
cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
html("</td><td>");
if (ctx.repo->snapshots && (tag->tagged->type == OBJ_COMMIT))
print_tag_downloads(ctx.repo, name);
else
cgit_object_link(tag->tagged);
html("</td><td>");
if (info->tagger)
html(info->tagger);
html("</td><td colspan='2'>");
if (info->tagger_date > 0)
cgit_print_age(info->tagger_date, -1, NULL);
html("</td></tr>\n");
} else {
if (!header)
print_tag_header();
html("<tr><td>");
- html_txt(name);
+ cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
html("</td><td>");
- if (ctx.repo->snapshots && (tag->tagged->type == OBJ_COMMIT))
+ if (ctx.repo->snapshots && (ref->object->type == OBJ_COMMIT))
print_tag_downloads(ctx.repo, name);
else
cgit_object_link(ref->object);
html("</td></tr>\n");
}
return 0;
}
static void print_refs_link(char *path)
{
html("<tr class='nohover'><td colspan='4'>");
cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path);
html("</td></tr>");
}
void cgit_print_branches(int maxcount)
{
struct reflist list;
int i;
html("<tr class='nohover'><th class='left'>Branch</th>"
"<th class='left'>Commit message</th>"
"<th class='left'>Author</th>"
"<th class='left' colspan='2'>Age</th></tr>\n");
diff --git a/ui-shared.c b/ui-shared.c
index 95dfeb4..4f28512 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -348,48 +348,54 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
delim = repolink(title, class, "diff", head, path);
if (new_rev && strcmp(new_rev, ctx.qry.head)) {
html(delim);
html("id=");
html_url_arg(new_rev);
delim = "&amp;";
}
if (old_rev) {
html(delim);
html("id2=");
html_url_arg(old_rev);
}
html("'>");
html_txt(name);
html("</a>");
}
void cgit_patch_link(char *name, char *title, char *class, char *head,
char *rev)
{
reporevlink("patch", name, title, class, head, rev, NULL);
}
+void cgit_stats_link(char *name, char *title, char *class, char *head,
+ char *path)
+{
+ reporevlink("stats", name, title, class, head, NULL, path);
+}
+
void cgit_object_link(struct object *obj)
{
char *page, *shortrev, *fullrev, *name;
fullrev = sha1_to_hex(obj->sha1);
shortrev = xstrdup(fullrev);
shortrev[10] = '\0';
if (obj->type == OBJ_COMMIT) {
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
ctx.qry.head, fullrev);
return;
} else if (obj->type == OBJ_TREE)
page = "tree";
else if (obj->type == OBJ_TAG)
page = "tag";
else
page = "blob";
name = fmt("%s %s...", typename(obj->type), shortrev);
reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
}
void cgit_print_date(time_t secs, char *format, int local_time)
{
char buf[64];
@@ -536,153 +542,161 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
return 1;
if (obj->type == OBJ_TAG) {
tag = lookup_tag(sha1);
if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
return 0;
hashcpy(fileid, tag->tagged->sha1);
} else if (obj->type != OBJ_BLOB) {
return 0;
} else {
hashcpy(fileid, sha1);
}
if (!*header) {
html("<h1>download</h1>\n");
*header = 1;
}
url = cgit_pageurl(ctx.qry.repo, "blob",
fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
buf));
html_link_open(url, NULL, "menu");
html_txt(strlpart(buf, 20));
html_link_close();
return 0;
}
-void add_hidden_formfields(int incl_head, int incl_search, char *page)
+void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
{
char *url;
if (!ctx.cfg.virtual_root) {
url = fmt("%s/%s", ctx.qry.repo, page);
if (ctx.qry.path)
url = fmt("%s/%s", url, ctx.qry.path);
html_hidden("url", url);
}
if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
strcmp(ctx.qry.head, ctx.repo->defbranch))
html_hidden("h", ctx.qry.head);
if (ctx.qry.sha1)
html_hidden("id", ctx.qry.sha1);
if (ctx.qry.sha2)
html_hidden("id2", ctx.qry.sha2);
if (ctx.qry.showmsg)
html_hidden("showmsg", "1");
if (incl_search) {
if (ctx.qry.grep)
html_hidden("qt", ctx.qry.grep);
if (ctx.qry.search)
html_hidden("q", ctx.qry.search);
}
}
+const char *fallback_cmd = "repolist";
+
char *hc(struct cgit_cmd *cmd, const char *page)
{
- return (strcmp(cmd->name, page) ? NULL : "active");
+ return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
}
void cgit_print_pageheader(struct cgit_context *ctx)
{
struct cgit_cmd *cmd = cgit_get_cmd(ctx);
+ if (!cmd && ctx->repo)
+ fallback_cmd = "summary";
+
html("<table id='header'>\n");
html("<tr>\n");
html("<td class='logo' rowspan='2'><a href='");
if (ctx->cfg.logo_link)
html_attr(ctx->cfg.logo_link);
else
html_attr(cgit_rooturl());
html("'><img src='");
html_attr(ctx->cfg.logo);
html("' alt='cgit logo'/></a></td>\n");
html("<td class='main'>");
if (ctx->repo) {
cgit_index_link("index", NULL, NULL, NULL, 0);
html(" : ");
cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
html("</td><td class='form'>");
html("<form method='get' action=''>\n");
- add_hidden_formfields(0, 1, ctx->qry.page);
+ cgit_add_hidden_formfields(0, 1, ctx->qry.page);
html("<select name='h' onchange='this.form.submit();'>\n");
for_each_branch_ref(print_branch_option, ctx->qry.head);
html("</select> ");
html("<input type='submit' name='' value='switch'/>");
html("</form>");
} else
html_txt(ctx->cfg.root_title);
html("</td></tr>\n");
html("<tr><td class='sub'>");
if (ctx->repo) {
html_txt(ctx->repo->desc);
html("</td><td class='sub right'>");
html_txt(ctx->repo->owner);
} else {
if (ctx->cfg.root_desc)
html_txt(ctx->cfg.root_desc);
else if (ctx->cfg.index_info)
html_include(ctx->cfg.index_info);
}
html("</td></tr></table>\n");
html("<table class='tabs'><tr><td>\n");
if (ctx->repo) {
cgit_summary_link("summary", NULL, hc(cmd, "summary"),
ctx->qry.head);
cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
ctx->qry.sha1, NULL);
cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
ctx->qry.sha1, NULL);
cgit_commit_link("commit", NULL, hc(cmd, "commit"),
ctx->qry.head, ctx->qry.sha1);
cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
ctx->qry.sha1, ctx->qry.sha2, NULL);
+ if (ctx->repo->max_stats)
+ cgit_stats_link("stats", NULL, hc(cmd, "stats"),
+ ctx->qry.head, NULL);
if (ctx->repo->readme)
reporevlink("about", "about", NULL,
hc(cmd, "about"), ctx->qry.head, NULL,
NULL);
html("</td><td class='form'>");
html("<form class='right' method='get' action='");
if (ctx->cfg.virtual_root)
html_url_path(cgit_fileurl(ctx->qry.repo, "log",
ctx->qry.path, NULL));
html("'>\n");
- add_hidden_formfields(1, 0, "log");
+ cgit_add_hidden_formfields(1, 0, "log");
html("<select name='qt'>\n");
html_option("grep", "log msg", ctx->qry.grep);
html_option("author", "author", ctx->qry.grep);
html_option("committer", "committer", ctx->qry.grep);
html("</select>\n");
html("<input class='txt' type='text' size='10' name='q' value='");
html_attr(ctx->qry.search);
html("'/>\n");
html("<input type='submit' value='search'/>\n");
html("</form>\n");
} else {
site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
if (ctx->cfg.root_readme)
site_link("about", "about", NULL, hc(cmd, "about"),
NULL, 0);
html("</td><td class='form'>");
html("<form method='get' action='");
html_attr(cgit_rooturl());
html("'>\n");
html("<input type='text' name='q' size='10' value='");
html_attr(ctx->qry.search);
html("'/>\n");
html("<input type='submit' value='search'/>\n");
html("</form>");
diff --git a/ui-shared.h b/ui-shared.h
index 2ab53ae..5a3821f 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -9,38 +9,41 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_index_link(char *name, char *title, char *class,
char *pattern, int ofs);
extern void cgit_summary_link(char *name, char *title, char *class, char *head);
extern void cgit_tag_link(char *name, char *title, char *class, char *head,
char *rev);
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_plain_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_log_link(char *name, char *title, char *class, char *head,
char *rev, char *path, int ofs, char *grep,
char *pattern, int showmsg);
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
char *rev);
extern void cgit_patch_link(char *name, char *title, char *class, char *head,
char *rev);
extern void cgit_refs_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_snapshot_link(char *name, char *title, char *class,
char *head, char *rev, char *archivename);
extern void cgit_diff_link(char *name, char *title, char *class, char *head,
char *new_rev, char *old_rev, char *path);
+extern void cgit_stats_link(char *name, char *title, char *class, char *head,
+ char *path);
extern void cgit_object_link(struct object *obj);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(time_t secs, char *format, int local_time);
extern void cgit_print_age(time_t t, time_t max_relative, char *format);
extern void cgit_print_http_headers(struct cgit_context *ctx);
extern void cgit_print_docstart(struct cgit_context *ctx);
extern void cgit_print_docend();
extern void cgit_print_pageheader(struct cgit_context *ctx);
extern void cgit_print_filemode(unsigned short mode);
extern void cgit_print_snapshot_links(const char *repo, const char *head,
const char *hex, int snapshots);
-
+extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
+ char *page);
#endif /* UI_SHARED_H */
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 6f09151..f25613e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -37,50 +37,50 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f
chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor");
chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT");
chk_zero(close(stdout2), "Closing uncompressed STDOUT");
chk_zero(close(rw[1]), "Closing write end of pipe in parent");
chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process");
if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) )
cgit_print_error("Failed to compress archive");
return rv;
}
static int write_tar_gzip_archive(struct archiver_args *args)
{
return write_compressed_tar_archive(args,"gzip");
}
static int write_tar_bzip2_archive(struct archiver_args *args)
{
return write_compressed_tar_archive(args,"bzip2");
}
const struct cgit_snapshot_format cgit_snapshot_formats[] = {
{ ".zip", "application/x-zip", write_zip_archive, 0x1 },
- { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 },
- { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 },
+ { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x2 },
+ { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x4 },
{ ".tar", "application/x-tar", write_tar_archive, 0x8 },
{}
};
static const struct cgit_snapshot_format *get_format(const char *filename)
{
const struct cgit_snapshot_format *fmt;
int fl, sl;
fl = strlen(filename);
for(fmt = cgit_snapshot_formats; fmt->suffix; fmt++) {
sl = strlen(fmt->suffix);
if (sl >= fl)
continue;
if (!strcmp(fmt->suffix, filename + fl - sl))
return fmt;
}
return NULL;
}
static int make_snapshot(const struct cgit_snapshot_format *format,
const char *hex, const char *prefix,
const char *filename)
{
@@ -154,39 +154,41 @@ static const char *get_ref_from_filename(const char *url, const char *filename,
return snapshot;
return NULL;
}
void cgit_print_snapshot(const char *head, const char *hex,
const char *filename, int snapshots, int dwim)
{
const struct cgit_snapshot_format* f;
char *prefix = NULL;
f = get_format(filename);
if (!f) {
ctx.page.mimetype = "text/html";
cgit_print_http_headers(&ctx);
cgit_print_docstart(&ctx);
cgit_print_pageheader(&ctx);
cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
cgit_print_docend();
return;
}
if (!hex && dwim) {
hex = get_ref_from_filename(ctx.repo->url, filename, f);
- if (hex != NULL) {
+ if (hex == NULL) {
+ html_status(404, "Not found", 0);
+ return;
+ }
prefix = xstrdup(filename);
prefix[strlen(filename) - strlen(f->suffix)] = '\0';
}
- }
if (!hex)
hex = head;
if (!prefix)
prefix = xstrdup(cgit_repobasename(ctx.repo->url));
make_snapshot(f, hex, prefix, filename);
free(prefix);
}
diff --git a/ui-stats.c b/ui-stats.c
new file mode 100644
index 0000000..9fc06d3
--- a/dev/null
+++ b/ui-stats.c
@@ -0,0 +1,410 @@
+#include <string-list.h>
+
+#include "cgit.h"
+#include "html.h"
+#include "ui-shared.h"
+#include "ui-stats.h"
+
+#define MONTHS 6
+
+struct authorstat {
+ long total;
+ struct string_list list;
+};
+
+#define DAY_SECS (60 * 60 * 24)
+#define WEEK_SECS (DAY_SECS * 7)
+
+static void trunc_week(struct tm *tm)
+{
+ time_t t = timegm(tm);
+ t -= ((tm->tm_wday + 6) % 7) * DAY_SECS;
+ gmtime_r(&t, tm);
+}
+
+static void dec_week(struct tm *tm)
+{
+ time_t t = timegm(tm);
+ t -= WEEK_SECS;
+ gmtime_r(&t, tm);
+}
+
+static void inc_week(struct tm *tm)
+{
+ time_t t = timegm(tm);
+ t += WEEK_SECS;
+ gmtime_r(&t, tm);
+}
+
+static char *pretty_week(struct tm *tm)
+{
+ static char buf[10];
+
+ strftime(buf, sizeof(buf), "W%V %G", tm);
+ return buf;
+}
+
+static void trunc_month(struct tm *tm)
+{
+ tm->tm_mday = 1;
+}
+
+static void dec_month(struct tm *tm)
+{
+ tm->tm_mon--;
+ if (tm->tm_mon < 0) {
+ tm->tm_year--;
+ tm->tm_mon = 11;
+ }
+}
+
+static void inc_month(struct tm *tm)
+{
+ tm->tm_mon++;
+ if (tm->tm_mon > 11) {
+ tm->tm_year++;
+ tm->tm_mon = 0;
+ }
+}
+
+static char *pretty_month(struct tm *tm)
+{
+ static const char *months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900);
+}
+
+static void trunc_quarter(struct tm *tm)
+{
+ trunc_month(tm);
+ while(tm->tm_mon % 3 != 0)
+ dec_month(tm);
+}
+
+static void dec_quarter(struct tm *tm)
+{
+ dec_month(tm);
+ dec_month(tm);
+ dec_month(tm);
+}
+
+static void inc_quarter(struct tm *tm)
+{
+ inc_month(tm);
+ inc_month(tm);
+ inc_month(tm);
+}
+
+static char *pretty_quarter(struct tm *tm)
+{
+ return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900);
+}
+
+static void trunc_year(struct tm *tm)
+{
+ trunc_month(tm);
+ tm->tm_mon = 0;
+}
+
+static void dec_year(struct tm *tm)
+{
+ tm->tm_year--;
+}
+
+static void inc_year(struct tm *tm)
+{
+ tm->tm_year++;
+}
+
+static char *pretty_year(struct tm *tm)
+{
+ return fmt("%d", tm->tm_year + 1900);
+}
+
+struct cgit_period periods[] = {
+ {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week},
+ {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month},
+ {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
+ {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year},
+};
+
+/* Given a period code or name, return a period index (1, 2, 3 or 4)
+ * and update the period pointer to the correcsponding struct.
+ * If no matching code is found, return 0.
+ */
+int cgit_find_stats_period(const char *expr, struct cgit_period **period)
+{
+ int i;
+ char code = '\0';
+
+ if (!expr)
+ return 0;
+
+ if (strlen(expr) == 1)
+ code = expr[0];
+
+ for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++)
+ if (periods[i].code == code || !strcmp(periods[i].name, expr)) {
+ if (period)
+ *period = &periods[i];
+ return i+1;
+ }
+ return 0;
+}
+
+static void add_commit(struct string_list *authors, struct commit *commit,
+ struct cgit_period *period)
+{
+ struct commitinfo *info;
+ struct string_list_item *author, *item;
+ struct authorstat *authorstat;
+ struct string_list *items;
+ char *tmp;
+ struct tm *date;
+ time_t t;
+
+ info = cgit_parse_commit(commit);
+ tmp = xstrdup(info->author);
+ author = string_list_insert(tmp, authors);
+ if (!author->util)
+ author->util = xcalloc(1, sizeof(struct authorstat));
+ else
+ free(tmp);
+ authorstat = author->util;
+ items = &authorstat->list;
+ t = info->committer_date;
+ date = gmtime(&t);
+ period->trunc(date);
+ tmp = xstrdup(period->pretty(date));
+ item = string_list_insert(tmp, items);
+ if (item->util)
+ free(tmp);
+ item->util++;
+ authorstat->total++;
+ cgit_free_commitinfo(info);
+}
+
+static int cmp_total_commits(const void *a1, const void *a2)
+{
+ const struct string_list_item *i1 = a1;
+ const struct string_list_item *i2 = a2;
+ const struct authorstat *auth1 = i1->util;
+ const struct authorstat *auth2 = i2->util;
+
+ return auth2->total - auth1->total;
+}
+
+/* Walk the commit DAG and collect number of commits per author per
+ * timeperiod into a nested string_list collection.
+ */
+struct string_list collect_stats(struct cgit_context *ctx,
+ struct cgit_period *period)
+{
+ struct string_list authors;
+ struct rev_info rev;
+ struct commit *commit;
+ const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL};
+ int argc = 3;
+ time_t now;
+ long i;
+ struct tm *tm;
+ char tmp[11];
+
+ time(&now);
+ tm = gmtime(&now);
+ period->trunc(tm);
+ for (i = 1; i < period->count; i++)
+ period->dec(tm);
+ strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm);
+ argv[2] = xstrdup(fmt("--since=%s", tmp));
+ if (ctx->qry.path) {
+ argv[3] = "--";
+ argv[4] = ctx->qry.path;
+ argc += 2;
+ }
+ init_revisions(&rev, NULL);
+ rev.abbrev = DEFAULT_ABBREV;
+ rev.commit_format = CMIT_FMT_DEFAULT;
+ rev.no_merges = 1;
+ rev.verbose_header = 1;
+ rev.show_root_diff = 0;
+ setup_revisions(argc, argv, &rev, NULL);
+ prepare_revision_walk(&rev);
+ memset(&authors, 0, sizeof(authors));
+ while ((commit = get_revision(&rev)) != NULL) {
+ add_commit(&authors, commit, period);
+ free(commit->buffer);
+ free_commit_list(commit->parents);
+ }
+ return authors;
+}
+
+void print_combined_authorrow(struct string_list *authors, int from, int to,
+ const char *name, const char *leftclass, const char *centerclass,
+ const char *rightclass, struct cgit_period *period)
+{
+ struct string_list_item *author;
+ struct authorstat *authorstat;
+ struct string_list *items;
+ struct string_list_item *date;
+ time_t now;
+ long i, j, total, subtotal;
+ struct tm *tm;
+ char *tmp;
+
+ time(&now);
+ tm = gmtime(&now);
+ period->trunc(tm);
+ for (i = 1; i < period->count; i++)
+ period->dec(tm);
+
+ total = 0;
+ htmlf("<tr><td class='%s'>%s</td>", leftclass,
+ fmt(name, to - from + 1));
+ for (j = 0; j < period->count; j++) {
+ tmp = period->pretty(tm);
+ period->inc(tm);
+ subtotal = 0;
+ for (i = from; i <= to; i++) {
+ author = &authors->items[i];
+ authorstat = author->util;
+ items = &authorstat->list;
+ date = string_list_lookup(tmp, items);
+ if (date)
+ subtotal += (size_t)date->util;
+ }
+ htmlf("<td class='%s'>%d</td>", centerclass, subtotal);
+ total += subtotal;
+ }
+ htmlf("<td class='%s'>%d</td></tr>", rightclass, total);
+}
+
+void print_authors(struct string_list *authors, int top,
+ struct cgit_period *period)
+{
+ struct string_list_item *author;
+ struct authorstat *authorstat;
+ struct string_list *items;
+ struct string_list_item *date;
+ time_t now;
+ long i, j, total;
+ struct tm *tm;
+ char *tmp;
+
+ time(&now);
+ tm = gmtime(&now);
+ period->trunc(tm);
+ for (i = 1; i < period->count; i++)
+ period->dec(tm);
+
+ html("<table class='stats'><tr><th>Author</th>");
+ for (j = 0; j < period->count; j++) {
+ tmp = period->pretty(tm);
+ htmlf("<th>%s</th>", tmp);
+ period->inc(tm);
+ }
+ html("<th>Total</th></tr>\n");
+
+ if (top <= 0 || top > authors->nr)
+ top = authors->nr;
+
+ for (i = 0; i < top; i++) {
+ author = &authors->items[i];
+ html("<tr><td class='left'>");
+ html_txt(author->string);
+ html("</td>");
+ authorstat = author->util;
+ items = &authorstat->list;
+ total = 0;
+ for (j = 0; j < period->count; j++)
+ period->dec(tm);
+ for (j = 0; j < period->count; j++) {
+ tmp = period->pretty(tm);
+ period->inc(tm);
+ date = string_list_lookup(tmp, items);
+ if (!date)
+ html("<td>0</td>");
+ else {
+ htmlf("<td>%d</td>", date->util);
+ total += (size_t)date->util;
+ }
+ }
+ htmlf("<td class='sum'>%d</td></tr>", total);
+ }
+
+ if (top < authors->nr)
+ print_combined_authorrow(authors, top, authors->nr - 1,
+ "Others (%d)", "left", "", "sum", period);
+
+ print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
+ "total", "sum", "sum", period);
+ html("</table>");
+}
+
+/* Create a sorted string_list with one entry per author. The util-field
+ * for each author is another string_list which is used to calculate the
+ * number of commits per time-interval.
+ */
+void cgit_show_stats(struct cgit_context *ctx)
+{
+ struct string_list authors;
+ struct cgit_period *period;
+ int top, i;
+ const char *code = "w";
+
+ if (ctx->qry.period)
+ code = ctx->qry.period;
+
+ i = cgit_find_stats_period(code, &period);
+ if (!i) {
+ cgit_print_error(fmt("Unknown statistics type: %c", code));
+ return;
+ }
+ if (i > ctx->repo->max_stats) {
+ cgit_print_error(fmt("Statistics type disabled: %s",
+ period->name));
+ return;
+ }
+ authors = collect_stats(ctx, period);
+ qsort(authors.items, authors.nr, sizeof(struct string_list_item),
+ cmp_total_commits);
+
+ top = ctx->qry.ofs;
+ if (!top)
+ top = 10;
+ htmlf("<h2>Commits per author per %s", period->name);
+ if (ctx->qry.path) {
+ html(" (path '");
+ html_txt(ctx->qry.path);
+ html("')");
+ }
+ html("</h2>");
+
+ html("<form method='get' action='' style='float: right; text-align: right;'>");
+ cgit_add_hidden_formfields(1, 0, "stats");
+ if (ctx->repo->max_stats > 1) {
+ html("Period: ");
+ html("<select name='period' onchange='this.form.submit();'>");
+ for (i = 0; i < ctx->repo->max_stats; i++)
+ htmlf("<option value='%c'%s>%s</option>",
+ periods[i].code,
+ period == &periods[i] ? " selected" : "",
+ periods[i].name);
+ html("</select><br/><br/>");
+ }
+ html("Authors: ");
+ html("");
+ html("<select name='ofs' onchange='this.form.submit();'>");
+ htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : "");
+ htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : "");
+ htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : "");
+ htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : "");
+ htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : "");
+ html("</select>");
+ html("<noscript>&nbsp;&nbsp;<input type='submit' value='Reload'/></noscript>");
+ html("</form>");
+ print_authors(&authors, top, period);
+}
+
diff --git a/ui-stats.h b/ui-stats.h
new file mode 100644
index 0000000..4f13dba
--- a/dev/null
+++ b/ui-stats.h
@@ -0,0 +1,27 @@
+#ifndef UI_STATS_H
+#define UI_STATS_H
+
+#include "cgit.h"
+
+struct cgit_period {
+ const char code;
+ const char *name;
+ int max_periods;
+ int count;
+
+ /* Convert a tm value to the first day in the period */
+ void (*trunc)(struct tm *tm);
+
+ /* Update tm value to start of next/previous period */
+ void (*dec)(struct tm *tm);
+ void (*inc)(struct tm *tm);
+
+ /* Pretty-print a tm value */
+ char *(*pretty)(struct tm *tm);
+};
+
+extern int cgit_find_stats_period(const char *expr, struct cgit_period **period);
+
+extern void cgit_show_stats(struct cgit_context *ctx);
+
+#endif /* UI_STATS_H */
diff --git a/ui-tag.c b/ui-tag.c
index 3aea87d..0e056e0 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -32,48 +32,58 @@ static void print_tag_content(char *buf)
void cgit_print_tag(char *revname)
{
unsigned char sha1[20];
struct object *obj;
struct tag *tag;
struct taginfo *info;
if (get_sha1(revname, sha1)) {
cgit_print_error(fmt("Bad tag reference: %s", revname));
return;
}
obj = parse_object(sha1);
if (!obj) {
cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1)));
return;
}
if (obj->type == OBJ_TAG) {
tag = lookup_tag(sha1);
if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
cgit_print_error(fmt("Bad tag object: %s", revname));
return;
}
html("<table class='commit-info'>\n");
- htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n",
- revname, sha1_to_hex(sha1));
+ htmlf("<tr><td>Tag name</td><td>");
+ html_txt(revname);
+ htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
if (info->tagger_date > 0) {
html("<tr><td>Tag date</td><td>");
cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
}
if (info->tagger) {
html("<tr><td>Tagged by</td><td>");
html_txt(info->tagger);
if (info->tagger_email) {
html(" ");
html_txt(info->tagger_email);
}
html("</td></tr>\n");
}
html("<tr><td>Tagged object</td><td>");
cgit_object_link(tag->tagged);
html("</td></tr>\n");
html("</table>\n");
print_tag_content(info->msg);
+ } else {
+ html("<table class='commit-info'>\n");
+ htmlf("<tr><td>Tag name</td><td>");
+ html_txt(revname);
+ html("</td></tr>\n");
+ html("<tr><td>Tagged object</td><td>");
+ cgit_object_link(obj);
+ html("</td></tr>\n");
+ html("</table>\n");
}
return;
}
diff --git a/ui-tree.c b/ui-tree.c
index 2a8625c..c26ba4c 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -89,48 +89,51 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
html("<tr><td class='ls-mode'>");
cgit_print_filemode(mode);
html("</td><td>");
if (S_ISGITLINK(mode)) {
htmlf("<a class='ls-mod' href='");
html_attr(fmt(ctx.repo->module_link,
name,
sha1_to_hex(sha1)));
html("'>");
html_txt(name);
html("</a>");
} else if (S_ISDIR(mode)) {
cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
curr_rev, fullpath);
} else {
cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head,
curr_rev, fullpath);
}
htmlf("</td><td class='ls-size'>%li</td>", size);
html("<td>");
cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
fullpath, 0, NULL, NULL, ctx.qry.showmsg);
+ if (ctx.repo->max_stats)
+ cgit_stats_link("stats", NULL, "button", ctx.qry.head,
+ fullpath);
html("</td></tr>\n");
free(name);
return 0;
}
static void ls_head()
{
html("<table summary='tree listing' class='list'>\n");
html("<tr class='nohover'>");
html("<th class='left'>Mode</th>");
html("<th class='left'>Name</th>");
html("<th class='right'>Size</th>");
html("<th/>");
html("</tr>\n");
header = 1;
}
static void ls_tail()
{
if (!header)
return;
html("</table>\n");
header = 0;
}