summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2010-08-22 11:29:57 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-08-22 11:29:57 (UTC)
commit6d7552bc072599313ef423d69156d824c075572a (patch) (unidiff)
tree3189efeb6ca80dc6dcf0811ff2d8011e2b3e8c7b
parent379e80e3a83481d3639c5d312eeddcce57c486b2 (diff)
downloadcgit-6d7552bc072599313ef423d69156d824c075572a.zip
cgit-6d7552bc072599313ef423d69156d824c075572a.tar.gz
cgit-6d7552bc072599313ef423d69156d824c075572a.tar.bz2
Use GIT-1.7.2.2
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile4
-rw-r--r--cgit.c2
m---------git0
-rw-r--r--ui-commit.c2
-rw-r--r--ui-log.c2
-rw-r--r--ui-plain.c2
-rw-r--r--ui-stats.c8
7 files changed, 10 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 3e5a38d..2a15469 100644
--- a/Makefile
+++ b/Makefile
@@ -1,183 +1,183 @@
1CGIT_VERSION = v0.8.3.3 1CGIT_VERSION = v0.8.3.3
2CGIT_SCRIPT_NAME = cgit.cgi 2CGIT_SCRIPT_NAME = cgit.cgi
3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit 3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) 4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
5CGIT_CONFIG = /etc/cgitrc 5CGIT_CONFIG = /etc/cgitrc
6CACHE_ROOT = /var/cache/cgit 6CACHE_ROOT = /var/cache/cgit
7SHA1_HEADER = <openssl/sha.h> 7SHA1_HEADER = <openssl/sha.h>
8GIT_VER = 1.7.0 8GIT_VER = 1.7.2.2
9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
10INSTALL = install 10INSTALL = install
11 11
12# Define NO_STRCASESTR if you don't have strcasestr. 12# Define NO_STRCASESTR if you don't have strcasestr.
13# 13#
14# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 14# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1
15# implementation (slower). 15# implementation (slower).
16# 16#
17# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). 17# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin).
18# 18#
19 19
20#-include config.mak 20#-include config.mak
21 21
22# 22#
23# Platform specific tweaks 23# Platform specific tweaks
24# 24#
25 25
26uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 26uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
27uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') 27uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
28uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') 28uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
29 29
30ifeq ($(uname_O),Cygwin) 30ifeq ($(uname_O),Cygwin)
31 NO_STRCASESTR = YesPlease 31 NO_STRCASESTR = YesPlease
32 NEEDS_LIBICONV = YesPlease 32 NEEDS_LIBICONV = YesPlease
33endif 33endif
34 34
35# 35#
36# Let the user override the above settings. 36# Let the user override the above settings.
37# 37#
38-include cgit.conf 38-include cgit.conf
39 39
40# 40#
41# Define a way to invoke make in subdirs quietly, shamelessly ripped 41# Define a way to invoke make in subdirs quietly, shamelessly ripped
42# from git.git 42# from git.git
43# 43#
44QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir 44QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
45QUIET_SUBDIR1 = 45QUIET_SUBDIR1 =
46 46
47ifneq ($(findstring $(MAKEFLAGS),w),w) 47ifneq ($(findstring $(MAKEFLAGS),w),w)
48PRINT_DIR = --no-print-directory 48PRINT_DIR = --no-print-directory
49else # "make -w" 49else # "make -w"
50NO_SUBDIR = : 50NO_SUBDIR = :
51endif 51endif
52 52
53ifndef V 53ifndef V
54 QUIET_CC = @echo ' ' CC $@; 54 QUIET_CC = @echo ' ' CC $@;
55 QUIET_MM = @echo ' ' MM $@; 55 QUIET_MM = @echo ' ' MM $@;
56 QUIET_SUBDIR0 = +@subdir= 56 QUIET_SUBDIR0 = +@subdir=
57 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ 57 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
58 $(MAKE) $(PRINT_DIR) -C $$subdir 58 $(MAKE) $(PRINT_DIR) -C $$subdir
59endif 59endif
60 60
61# 61#
62# Define a pattern rule for automatic dependency building 62# Define a pattern rule for automatic dependency building
63# 63#
64%.d: %.c 64%.d: %.c
65 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ 65 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
66 66
67# 67#
68# Define a pattern rule for silent object building 68# Define a pattern rule for silent object building
69# 69#
70%.o: %.c 70%.o: %.c
71 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< 71 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
72 72
73 73
74EXTLIBS = git/libgit.a git/xdiff/lib.a -lz 74EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread
75OBJECTS = 75OBJECTS =
76OBJECTS += cache.o 76OBJECTS += cache.o
77OBJECTS += cgit.o 77OBJECTS += cgit.o
78OBJECTS += cmd.o 78OBJECTS += cmd.o
79OBJECTS += configfile.o 79OBJECTS += configfile.o
80OBJECTS += html.o 80OBJECTS += html.o
81OBJECTS += parsing.o 81OBJECTS += parsing.o
82OBJECTS += scan-tree.o 82OBJECTS += scan-tree.o
83OBJECTS += shared.o 83OBJECTS += shared.o
84OBJECTS += ui-atom.o 84OBJECTS += ui-atom.o
85OBJECTS += ui-blob.o 85OBJECTS += ui-blob.o
86OBJECTS += ui-clone.o 86OBJECTS += ui-clone.o
87OBJECTS += ui-commit.o 87OBJECTS += ui-commit.o
88OBJECTS += ui-diff.o 88OBJECTS += ui-diff.o
89OBJECTS += ui-log.o 89OBJECTS += ui-log.o
90OBJECTS += ui-patch.o 90OBJECTS += ui-patch.o
91OBJECTS += ui-plain.o 91OBJECTS += ui-plain.o
92OBJECTS += ui-refs.o 92OBJECTS += ui-refs.o
93OBJECTS += ui-repolist.o 93OBJECTS += ui-repolist.o
94OBJECTS += ui-shared.o 94OBJECTS += ui-shared.o
95OBJECTS += ui-snapshot.o 95OBJECTS += ui-snapshot.o
96OBJECTS += ui-ssdiff.o 96OBJECTS += ui-ssdiff.o
97OBJECTS += ui-stats.o 97OBJECTS += ui-stats.o
98OBJECTS += ui-summary.o 98OBJECTS += ui-summary.o
99OBJECTS += ui-tag.o 99OBJECTS += ui-tag.o
100OBJECTS += ui-tree.o 100OBJECTS += ui-tree.o
101 101
102ifdef NEEDS_LIBICONV 102ifdef NEEDS_LIBICONV
103 EXTLIBS += -liconv 103 EXTLIBS += -liconv
104endif 104endif
105 105
106 106
107.PHONY: all libgit test install uninstall clean force-version get-git \ 107.PHONY: all libgit test install uninstall clean force-version get-git \
108 doc man-doc html-doc clean-doc 108 doc man-doc html-doc clean-doc
109 109
110all: cgit 110all: cgit
111 111
112VERSION: force-version 112VERSION: force-version
113 @./gen-version.sh "$(CGIT_VERSION)" 113 @./gen-version.sh "$(CGIT_VERSION)"
114-include VERSION 114-include VERSION
115 115
116 116
117CFLAGS += -g -Wall -Igit 117CFLAGS += -g -Wall -Igit
118CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 118CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
119CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' 119CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
120CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' 120CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
121CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' 121CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
122CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' 122CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
123 123
124ifdef NO_ICONV 124ifdef NO_ICONV
125 CFLAGS += -DNO_ICONV 125 CFLAGS += -DNO_ICONV
126endif 126endif
127ifdef NO_STRCASESTR 127ifdef NO_STRCASESTR
128 CFLAGS += -DNO_STRCASESTR 128 CFLAGS += -DNO_STRCASESTR
129endif 129endif
130ifdef NO_OPENSSL 130ifdef NO_OPENSSL
131 CFLAGS += -DNO_OPENSSL 131 CFLAGS += -DNO_OPENSSL
132 GIT_OPTIONS += NO_OPENSSL=1 132 GIT_OPTIONS += NO_OPENSSL=1
133else 133else
134 EXTLIBS += -lcrypto 134 EXTLIBS += -lcrypto
135endif 135endif
136 136
137cgit: $(OBJECTS) libgit 137cgit: $(OBJECTS) libgit
138 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) 138 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
139 139
140cgit.o: VERSION 140cgit.o: VERSION
141 141
142ifneq "$(MAKECMDGOALS)" "clean" 142ifneq "$(MAKECMDGOALS)" "clean"
143 -include $(OBJECTS:.o=.d) 143 -include $(OBJECTS:.o=.d)
144endif 144endif
145 145
146libgit: 146libgit:
147 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a 147 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a
148 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a 148 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a
149 149
150test: all 150test: all
151 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all 151 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
152 152
153install: all 153install: all
154 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) 154 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH)
155 $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 155 $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
156 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) 156 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
157 $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css 157 $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
158 $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png 158 $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
159 159
160uninstall: 160uninstall:
161 rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 161 rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
162 rm -f $(CGIT_DATA_PATH)/cgit.css 162 rm -f $(CGIT_DATA_PATH)/cgit.css
163 rm -f $(CGIT_DATA_PATH)/cgit.png 163 rm -f $(CGIT_DATA_PATH)/cgit.png
164 164
165doc: man-doc html-doc pdf-doc 165doc: man-doc html-doc pdf-doc
166 166
167man-doc: cgitrc.5.txt 167man-doc: cgitrc.5.txt
168 a2x -f manpage cgitrc.5.txt 168 a2x -f manpage cgitrc.5.txt
169 169
170html-doc: cgitrc.5.txt 170html-doc: cgitrc.5.txt
171 a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt 171 a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt
172 172
173pdf-doc: cgitrc.5.txt 173pdf-doc: cgitrc.5.txt
174 a2x -f pdf cgitrc.5.txt 174 a2x -f pdf cgitrc.5.txt
175 175
176clean: clean-doc 176clean: clean-doc
177 rm -f cgit VERSION *.o *.d 177 rm -f cgit VERSION *.o *.d
178 178
179clean-doc: 179clean-doc:
180 rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo 180 rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo
181 181
182get-git: 182get-git:
183 curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git 183 curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git
diff --git a/cgit.c b/cgit.c
index 4f2c752..d6146e2 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,217 +1,217 @@
1/* cgit.c: cgi for the git scm 1/* cgit.c: cgi for the git scm
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> 4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
5 * 5 *
6 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text) 7 * (see COPYING for full license text)
8 */ 8 */
9 9
10#include "cgit.h" 10#include "cgit.h"
11#include "cache.h" 11#include "cache.h"
12#include "cmd.h" 12#include "cmd.h"
13#include "configfile.h" 13#include "configfile.h"
14#include "html.h" 14#include "html.h"
15#include "ui-shared.h" 15#include "ui-shared.h"
16#include "ui-stats.h" 16#include "ui-stats.h"
17#include "scan-tree.h" 17#include "scan-tree.h"
18 18
19const char *cgit_version = CGIT_VERSION; 19const char *cgit_version = CGIT_VERSION;
20 20
21void add_mimetype(const char *name, const char *value) 21void add_mimetype(const char *name, const char *value)
22{ 22{
23 struct string_list_item *item; 23 struct string_list_item *item;
24 24
25 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); 25 item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name));
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, int extra_args) 29struct cgit_filter *new_filter(const char *cmd, int extra_args)
30{ 30{
31 struct cgit_filter *f; 31 struct cgit_filter *f;
32 32
33 if (!cmd || !cmd[0]) 33 if (!cmd || !cmd[0])
34 return NULL; 34 return NULL;
35 35
36 f = xmalloc(sizeof(struct cgit_filter)); 36 f = xmalloc(sizeof(struct cgit_filter));
37 f->cmd = xstrdup(cmd); 37 f->cmd = xstrdup(cmd);
38 f->argv = xmalloc((2 + extra_args) * sizeof(char *)); 38 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
39 f->argv[0] = f->cmd; 39 f->argv[0] = f->cmd;
40 f->argv[1] = NULL; 40 f->argv[1] = NULL;
41 return f; 41 return f;
42} 42}
43 43
44static void process_cached_repolist(const char *path); 44static void process_cached_repolist(const char *path);
45 45
46void repo_config(struct cgit_repo *repo, const char *name, const char *value) 46void repo_config(struct cgit_repo *repo, const char *name, const char *value)
47{ 47{
48 if (!strcmp(name, "name")) 48 if (!strcmp(name, "name"))
49 repo->name = xstrdup(value); 49 repo->name = xstrdup(value);
50 else if (!strcmp(name, "clone-url")) 50 else if (!strcmp(name, "clone-url"))
51 repo->clone_url = xstrdup(value); 51 repo->clone_url = xstrdup(value);
52 else if (!strcmp(name, "desc")) 52 else if (!strcmp(name, "desc"))
53 repo->desc = xstrdup(value); 53 repo->desc = xstrdup(value);
54 else if (!strcmp(name, "owner")) 54 else if (!strcmp(name, "owner"))
55 repo->owner = xstrdup(value); 55 repo->owner = xstrdup(value);
56 else if (!strcmp(name, "defbranch")) 56 else if (!strcmp(name, "defbranch"))
57 repo->defbranch = xstrdup(value); 57 repo->defbranch = xstrdup(value);
58 else if (!strcmp(name, "snapshots")) 58 else if (!strcmp(name, "snapshots"))
59 repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); 59 repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
60 else if (!strcmp(name, "enable-log-filecount")) 60 else if (!strcmp(name, "enable-log-filecount"))
61 repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 61 repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
62 else if (!strcmp(name, "enable-log-linecount")) 62 else if (!strcmp(name, "enable-log-linecount"))
63 repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 63 repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
64 else if (!strcmp(name, "enable-remote-branches")) 64 else if (!strcmp(name, "enable-remote-branches"))
65 repo->enable_remote_branches = atoi(value); 65 repo->enable_remote_branches = atoi(value);
66 else if (!strcmp(name, "enable-subject-links")) 66 else if (!strcmp(name, "enable-subject-links"))
67 repo->enable_subject_links = atoi(value); 67 repo->enable_subject_links = atoi(value);
68 else if (!strcmp(name, "max-stats")) 68 else if (!strcmp(name, "max-stats"))
69 repo->max_stats = cgit_find_stats_period(value, NULL); 69 repo->max_stats = cgit_find_stats_period(value, NULL);
70 else if (!strcmp(name, "module-link")) 70 else if (!strcmp(name, "module-link"))
71 repo->module_link= xstrdup(value); 71 repo->module_link= xstrdup(value);
72 else if (!strcmp(name, "section")) 72 else if (!strcmp(name, "section"))
73 repo->section = xstrdup(value); 73 repo->section = xstrdup(value);
74 else if (!strcmp(name, "readme") && value != NULL) { 74 else if (!strcmp(name, "readme") && value != NULL) {
75 char *colon; 75 char *colon;
76 if (*value == '/' || ((colon = strchr(value, ':')) != NULL && colon != value && *(colon + 1) != '\0')) 76 if (*value == '/' || ((colon = strchr(value, ':')) != NULL && colon != value && *(colon + 1) != '\0'))
77 repo->readme = xstrdup(value); 77 repo->readme = xstrdup(value);
78 else 78 else
79 repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); 79 repo->readme = xstrdup(fmt("%s/%s", repo->path, value));
80 } else if (ctx.cfg.enable_filter_overrides) { 80 } else if (ctx.cfg.enable_filter_overrides) {
81 if (!strcmp(name, "about-filter")) 81 if (!strcmp(name, "about-filter"))
82 repo->about_filter = new_filter(value, 0); 82 repo->about_filter = new_filter(value, 0);
83 else if (!strcmp(name, "commit-filter")) 83 else if (!strcmp(name, "commit-filter"))
84 repo->commit_filter = new_filter(value, 0); 84 repo->commit_filter = new_filter(value, 0);
85 else if (!strcmp(name, "source-filter")) 85 else if (!strcmp(name, "source-filter"))
86 repo->source_filter = new_filter(value, 1); 86 repo->source_filter = new_filter(value, 1);
87 } 87 }
88} 88}
89 89
90void config_cb(const char *name, const char *value) 90void config_cb(const char *name, const char *value)
91{ 91{
92 if (!strcmp(name, "section") || !strcmp(name, "repo.group")) 92 if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
93 ctx.cfg.section = xstrdup(value); 93 ctx.cfg.section = xstrdup(value);
94 else if (!strcmp(name, "repo.url")) 94 else if (!strcmp(name, "repo.url"))
95 ctx.repo = cgit_add_repo(value); 95 ctx.repo = cgit_add_repo(value);
96 else if (ctx.repo && !strcmp(name, "repo.path")) 96 else if (ctx.repo && !strcmp(name, "repo.path"))
97 ctx.repo->path = trim_end(value, '/'); 97 ctx.repo->path = trim_end(value, '/');
98 else if (ctx.repo && !prefixcmp(name, "repo.")) 98 else if (ctx.repo && !prefixcmp(name, "repo."))
99 repo_config(ctx.repo, name + 5, value); 99 repo_config(ctx.repo, name + 5, value);
100 else if (!strcmp(name, "root-title")) 100 else if (!strcmp(name, "root-title"))
101 ctx.cfg.root_title = xstrdup(value); 101 ctx.cfg.root_title = xstrdup(value);
102 else if (!strcmp(name, "root-desc")) 102 else if (!strcmp(name, "root-desc"))
103 ctx.cfg.root_desc = xstrdup(value); 103 ctx.cfg.root_desc = xstrdup(value);
104 else if (!strcmp(name, "root-readme")) 104 else if (!strcmp(name, "root-readme"))
105 ctx.cfg.root_readme = xstrdup(value); 105 ctx.cfg.root_readme = xstrdup(value);
106 else if (!strcmp(name, "css")) 106 else if (!strcmp(name, "css"))
107 ctx.cfg.css = xstrdup(value); 107 ctx.cfg.css = xstrdup(value);
108 else if (!strcmp(name, "favicon")) 108 else if (!strcmp(name, "favicon"))
109 ctx.cfg.favicon = xstrdup(value); 109 ctx.cfg.favicon = xstrdup(value);
110 else if (!strcmp(name, "footer")) 110 else if (!strcmp(name, "footer"))
111 ctx.cfg.footer = xstrdup(value); 111 ctx.cfg.footer = xstrdup(value);
112 else if (!strcmp(name, "head-include")) 112 else if (!strcmp(name, "head-include"))
113 ctx.cfg.head_include = xstrdup(value); 113 ctx.cfg.head_include = xstrdup(value);
114 else if (!strcmp(name, "header")) 114 else if (!strcmp(name, "header"))
115 ctx.cfg.header = xstrdup(value); 115 ctx.cfg.header = xstrdup(value);
116 else if (!strcmp(name, "logo")) 116 else if (!strcmp(name, "logo"))
117 ctx.cfg.logo = xstrdup(value); 117 ctx.cfg.logo = xstrdup(value);
118 else if (!strcmp(name, "index-header")) 118 else if (!strcmp(name, "index-header"))
119 ctx.cfg.index_header = xstrdup(value); 119 ctx.cfg.index_header = xstrdup(value);
120 else if (!strcmp(name, "index-info")) 120 else if (!strcmp(name, "index-info"))
121 ctx.cfg.index_info = xstrdup(value); 121 ctx.cfg.index_info = xstrdup(value);
122 else if (!strcmp(name, "logo-link")) 122 else if (!strcmp(name, "logo-link"))
123 ctx.cfg.logo_link = xstrdup(value); 123 ctx.cfg.logo_link = xstrdup(value);
124 else if (!strcmp(name, "module-link")) 124 else if (!strcmp(name, "module-link"))
125 ctx.cfg.module_link = xstrdup(value); 125 ctx.cfg.module_link = xstrdup(value);
126 else if (!strcmp(name, "virtual-root")) { 126 else if (!strcmp(name, "virtual-root")) {
127 ctx.cfg.virtual_root = trim_end(value, '/'); 127 ctx.cfg.virtual_root = trim_end(value, '/');
128 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 128 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
129 ctx.cfg.virtual_root = ""; 129 ctx.cfg.virtual_root = "";
130 } else if (!strcmp(name, "nocache")) 130 } else if (!strcmp(name, "nocache"))
131 ctx.cfg.nocache = atoi(value); 131 ctx.cfg.nocache = atoi(value);
132 else if (!strcmp(name, "noplainemail")) 132 else if (!strcmp(name, "noplainemail"))
133 ctx.cfg.noplainemail = atoi(value); 133 ctx.cfg.noplainemail = atoi(value);
134 else if (!strcmp(name, "noheader")) 134 else if (!strcmp(name, "noheader"))
135 ctx.cfg.noheader = atoi(value); 135 ctx.cfg.noheader = atoi(value);
136 else if (!strcmp(name, "snapshots")) 136 else if (!strcmp(name, "snapshots"))
137 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 137 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
138 else if (!strcmp(name, "enable-filter-overrides")) 138 else if (!strcmp(name, "enable-filter-overrides"))
139 ctx.cfg.enable_filter_overrides = atoi(value); 139 ctx.cfg.enable_filter_overrides = atoi(value);
140 else if (!strcmp(name, "enable-gitweb-owner")) 140 else if (!strcmp(name, "enable-gitweb-owner"))
141 ctx.cfg.enable_gitweb_owner = atoi(value); 141 ctx.cfg.enable_gitweb_owner = atoi(value);
142 else if (!strcmp(name, "enable-index-links")) 142 else if (!strcmp(name, "enable-index-links"))
143 ctx.cfg.enable_index_links = atoi(value); 143 ctx.cfg.enable_index_links = atoi(value);
144 else if (!strcmp(name, "enable-log-filecount")) 144 else if (!strcmp(name, "enable-log-filecount"))
145 ctx.cfg.enable_log_filecount = atoi(value); 145 ctx.cfg.enable_log_filecount = atoi(value);
146 else if (!strcmp(name, "enable-log-linecount")) 146 else if (!strcmp(name, "enable-log-linecount"))
147 ctx.cfg.enable_log_linecount = atoi(value); 147 ctx.cfg.enable_log_linecount = atoi(value);
148 else if (!strcmp(name, "enable-remote-branches")) 148 else if (!strcmp(name, "enable-remote-branches"))
149 ctx.cfg.enable_remote_branches = atoi(value); 149 ctx.cfg.enable_remote_branches = atoi(value);
150 else if (!strcmp(name, "enable-subject-links")) 150 else if (!strcmp(name, "enable-subject-links"))
151 ctx.cfg.enable_subject_links = atoi(value); 151 ctx.cfg.enable_subject_links = atoi(value);
152 else if (!strcmp(name, "enable-tree-linenumbers")) 152 else if (!strcmp(name, "enable-tree-linenumbers"))
153 ctx.cfg.enable_tree_linenumbers = atoi(value); 153 ctx.cfg.enable_tree_linenumbers = atoi(value);
154 else if (!strcmp(name, "max-stats")) 154 else if (!strcmp(name, "max-stats"))
155 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); 155 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
156 else if (!strcmp(name, "cache-size")) 156 else if (!strcmp(name, "cache-size"))
157 ctx.cfg.cache_size = atoi(value); 157 ctx.cfg.cache_size = atoi(value);
158 else if (!strcmp(name, "cache-root")) 158 else if (!strcmp(name, "cache-root"))
159 ctx.cfg.cache_root = xstrdup(expand_macros(value)); 159 ctx.cfg.cache_root = xstrdup(expand_macros(value));
160 else if (!strcmp(name, "cache-root-ttl")) 160 else if (!strcmp(name, "cache-root-ttl"))
161 ctx.cfg.cache_root_ttl = atoi(value); 161 ctx.cfg.cache_root_ttl = atoi(value);
162 else if (!strcmp(name, "cache-repo-ttl")) 162 else if (!strcmp(name, "cache-repo-ttl"))
163 ctx.cfg.cache_repo_ttl = atoi(value); 163 ctx.cfg.cache_repo_ttl = atoi(value);
164 else if (!strcmp(name, "cache-scanrc-ttl")) 164 else if (!strcmp(name, "cache-scanrc-ttl"))
165 ctx.cfg.cache_scanrc_ttl = atoi(value); 165 ctx.cfg.cache_scanrc_ttl = atoi(value);
166 else if (!strcmp(name, "cache-static-ttl")) 166 else if (!strcmp(name, "cache-static-ttl"))
167 ctx.cfg.cache_static_ttl = atoi(value); 167 ctx.cfg.cache_static_ttl = atoi(value);
168 else if (!strcmp(name, "cache-dynamic-ttl")) 168 else if (!strcmp(name, "cache-dynamic-ttl"))
169 ctx.cfg.cache_dynamic_ttl = atoi(value); 169 ctx.cfg.cache_dynamic_ttl = atoi(value);
170 else if (!strcmp(name, "about-filter")) 170 else if (!strcmp(name, "about-filter"))
171 ctx.cfg.about_filter = new_filter(value, 0); 171 ctx.cfg.about_filter = new_filter(value, 0);
172 else if (!strcmp(name, "commit-filter")) 172 else if (!strcmp(name, "commit-filter"))
173 ctx.cfg.commit_filter = new_filter(value, 0); 173 ctx.cfg.commit_filter = new_filter(value, 0);
174 else if (!strcmp(name, "embedded")) 174 else if (!strcmp(name, "embedded"))
175 ctx.cfg.embedded = atoi(value); 175 ctx.cfg.embedded = atoi(value);
176 else if (!strcmp(name, "max-atom-items")) 176 else if (!strcmp(name, "max-atom-items"))
177 ctx.cfg.max_atom_items = atoi(value); 177 ctx.cfg.max_atom_items = atoi(value);
178 else if (!strcmp(name, "max-message-length")) 178 else if (!strcmp(name, "max-message-length"))
179 ctx.cfg.max_msg_len = atoi(value); 179 ctx.cfg.max_msg_len = atoi(value);
180 else if (!strcmp(name, "max-repodesc-length")) 180 else if (!strcmp(name, "max-repodesc-length"))
181 ctx.cfg.max_repodesc_len = atoi(value); 181 ctx.cfg.max_repodesc_len = atoi(value);
182 else if (!strcmp(name, "max-blob-size")) 182 else if (!strcmp(name, "max-blob-size"))
183 ctx.cfg.max_blob_size = atoi(value); 183 ctx.cfg.max_blob_size = atoi(value);
184 else if (!strcmp(name, "max-repo-count")) 184 else if (!strcmp(name, "max-repo-count"))
185 ctx.cfg.max_repo_count = atoi(value); 185 ctx.cfg.max_repo_count = atoi(value);
186 else if (!strcmp(name, "max-commit-count")) 186 else if (!strcmp(name, "max-commit-count"))
187 ctx.cfg.max_commit_count = atoi(value); 187 ctx.cfg.max_commit_count = atoi(value);
188 else if (!strcmp(name, "project-list")) 188 else if (!strcmp(name, "project-list"))
189 ctx.cfg.project_list = xstrdup(expand_macros(value)); 189 ctx.cfg.project_list = xstrdup(expand_macros(value));
190 else if (!strcmp(name, "scan-path")) 190 else if (!strcmp(name, "scan-path"))
191 if (!ctx.cfg.nocache && ctx.cfg.cache_size) 191 if (!ctx.cfg.nocache && ctx.cfg.cache_size)
192 process_cached_repolist(expand_macros(value)); 192 process_cached_repolist(expand_macros(value));
193 else if (ctx.cfg.project_list) 193 else if (ctx.cfg.project_list)
194 scan_projects(expand_macros(value), 194 scan_projects(expand_macros(value),
195 ctx.cfg.project_list, repo_config); 195 ctx.cfg.project_list, repo_config);
196 else 196 else
197 scan_tree(expand_macros(value), repo_config); 197 scan_tree(expand_macros(value), repo_config);
198 else if (!strcmp(name, "source-filter")) 198 else if (!strcmp(name, "source-filter"))
199 ctx.cfg.source_filter = new_filter(value, 1); 199 ctx.cfg.source_filter = new_filter(value, 1);
200 else if (!strcmp(name, "summary-log")) 200 else if (!strcmp(name, "summary-log"))
201 ctx.cfg.summary_log = atoi(value); 201 ctx.cfg.summary_log = atoi(value);
202 else if (!strcmp(name, "summary-branches")) 202 else if (!strcmp(name, "summary-branches"))
203 ctx.cfg.summary_branches = atoi(value); 203 ctx.cfg.summary_branches = atoi(value);
204 else if (!strcmp(name, "summary-tags")) 204 else if (!strcmp(name, "summary-tags"))
205 ctx.cfg.summary_tags = atoi(value); 205 ctx.cfg.summary_tags = atoi(value);
206 else if (!strcmp(name, "side-by-side-diffs")) 206 else if (!strcmp(name, "side-by-side-diffs"))
207 ctx.cfg.ssdiff = atoi(value); 207 ctx.cfg.ssdiff = atoi(value);
208 else if (!strcmp(name, "agefile")) 208 else if (!strcmp(name, "agefile"))
209 ctx.cfg.agefile = xstrdup(value); 209 ctx.cfg.agefile = xstrdup(value);
210 else if (!strcmp(name, "renamelimit")) 210 else if (!strcmp(name, "renamelimit"))
211 ctx.cfg.renamelimit = atoi(value); 211 ctx.cfg.renamelimit = atoi(value);
212 else if (!strcmp(name, "remove-suffix")) 212 else if (!strcmp(name, "remove-suffix"))
213 ctx.cfg.remove_suffix = atoi(value); 213 ctx.cfg.remove_suffix = atoi(value);
214 else if (!strcmp(name, "robots")) 214 else if (!strcmp(name, "robots"))
215 ctx.cfg.robots = xstrdup(value); 215 ctx.cfg.robots = xstrdup(value);
216 else if (!strcmp(name, "clone-prefix")) 216 else if (!strcmp(name, "clone-prefix"))
217 ctx.cfg.clone_prefix = xstrdup(value); 217 ctx.cfg.clone_prefix = xstrdup(value);
diff --git a/git b/git
Subproject e923eaeb901ff056421b9007adcbbce271caa7b Subproject 8c67c392e1620fc3b749aa9e0b8da13bd84226f
diff --git a/ui-commit.c b/ui-commit.c
index 45af450..2b4f677 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -1,146 +1,146 @@
1/* ui-commit.c: generate commit view 1/* ui-commit.c: generate commit view
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12#include "ui-diff.h" 12#include "ui-diff.h"
13#include "ui-log.h" 13#include "ui-log.h"
14 14
15void cgit_print_commit(char *hex, const char *prefix) 15void cgit_print_commit(char *hex, const char *prefix)
16{ 16{
17 struct commit *commit, *parent; 17 struct commit *commit, *parent;
18 struct commitinfo *info, *parent_info; 18 struct commitinfo *info, *parent_info;
19 struct commit_list *p; 19 struct commit_list *p;
20 struct strbuf notes = STRBUF_INIT; 20 struct strbuf notes = STRBUF_INIT;
21 unsigned char sha1[20]; 21 unsigned char sha1[20];
22 char *tmp, *tmp2; 22 char *tmp, *tmp2;
23 int parents = 0; 23 int parents = 0;
24 24
25 if (!hex) 25 if (!hex)
26 hex = ctx.qry.head; 26 hex = ctx.qry.head;
27 27
28 if (get_sha1(hex, sha1)) { 28 if (get_sha1(hex, sha1)) {
29 cgit_print_error(fmt("Bad object id: %s", hex)); 29 cgit_print_error(fmt("Bad object id: %s", hex));
30 return; 30 return;
31 } 31 }
32 commit = lookup_commit_reference(sha1); 32 commit = lookup_commit_reference(sha1);
33 if (!commit) { 33 if (!commit) {
34 cgit_print_error(fmt("Bad commit reference: %s", hex)); 34 cgit_print_error(fmt("Bad commit reference: %s", hex));
35 return; 35 return;
36 } 36 }
37 info = cgit_parse_commit(commit); 37 info = cgit_parse_commit(commit);
38 38
39 get_commit_notes(commit, &notes, PAGE_ENCODING, 0); 39 format_note(NULL, sha1, &notes, PAGE_ENCODING, 0);
40 40
41 load_ref_decorations(DECORATE_FULL_REFS); 41 load_ref_decorations(DECORATE_FULL_REFS);
42 42
43 html("<table summary='commit info' class='commit-info'>\n"); 43 html("<table summary='commit info' class='commit-info'>\n");
44 html("<tr><th>author</th><td>"); 44 html("<tr><th>author</th><td>");
45 html_txt(info->author); 45 html_txt(info->author);
46 if (!ctx.cfg.noplainemail) { 46 if (!ctx.cfg.noplainemail) {
47 html(" "); 47 html(" ");
48 html_txt(info->author_email); 48 html_txt(info->author_email);
49 } 49 }
50 html("</td><td class='right'>"); 50 html("</td><td class='right'>");
51 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); 51 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
52 html("</td></tr>\n"); 52 html("</td></tr>\n");
53 html("<tr><th>committer</th><td>"); 53 html("<tr><th>committer</th><td>");
54 html_txt(info->committer); 54 html_txt(info->committer);
55 if (!ctx.cfg.noplainemail) { 55 if (!ctx.cfg.noplainemail) {
56 html(" "); 56 html(" ");
57 html_txt(info->committer_email); 57 html_txt(info->committer_email);
58 } 58 }
59 html("</td><td class='right'>"); 59 html("</td><td class='right'>");
60 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); 60 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
61 html("</td></tr>\n"); 61 html("</td></tr>\n");
62 html("<tr><th>commit</th><td colspan='2' class='sha1'>"); 62 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
63 tmp = sha1_to_hex(commit->object.sha1); 63 tmp = sha1_to_hex(commit->object.sha1);
64 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0); 64 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
65 html(" ("); 65 html(" (");
66 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); 66 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
67 html(") ("); 67 html(") (");
68 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) 68 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
69 cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1); 69 cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
70 else 70 else
71 cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1); 71 cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
72 html(")</td></tr>\n"); 72 html(")</td></tr>\n");
73 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 73 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
74 tmp = xstrdup(hex); 74 tmp = xstrdup(hex);
75 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, 75 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
76 ctx.qry.head, tmp, NULL); 76 ctx.qry.head, tmp, NULL);
77 if (prefix) { 77 if (prefix) {
78 html(" /"); 78 html(" /");
79 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix); 79 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
80 } 80 }
81 html("</td></tr>\n"); 81 html("</td></tr>\n");
82 for (p = commit->parents; p ; p = p->next) { 82 for (p = commit->parents; p ; p = p->next) {
83 parent = lookup_commit_reference(p->item->object.sha1); 83 parent = lookup_commit_reference(p->item->object.sha1);
84 if (!parent) { 84 if (!parent) {
85 html("<tr><td colspan='3'>"); 85 html("<tr><td colspan='3'>");
86 cgit_print_error("Error reading parent commit"); 86 cgit_print_error("Error reading parent commit");
87 html("</td></tr>"); 87 html("</td></tr>");
88 continue; 88 continue;
89 } 89 }
90 html("<tr><th>parent</th>" 90 html("<tr><th>parent</th>"
91 "<td colspan='2' class='sha1'>"); 91 "<td colspan='2' class='sha1'>");
92 tmp = tmp2 = sha1_to_hex(p->item->object.sha1); 92 tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
93 if (ctx.repo->enable_subject_links) { 93 if (ctx.repo->enable_subject_links) {
94 parent_info = cgit_parse_commit(parent); 94 parent_info = cgit_parse_commit(parent);
95 tmp2 = parent_info->subject; 95 tmp2 = parent_info->subject;
96 } 96 }
97 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0); 97 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
98 html(" ("); 98 html(" (");
99 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, 99 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
100 sha1_to_hex(p->item->object.sha1), prefix, 0); 100 sha1_to_hex(p->item->object.sha1), prefix, 0);
101 html(")</td></tr>"); 101 html(")</td></tr>");
102 parents++; 102 parents++;
103 } 103 }
104 if (ctx.repo->snapshots) { 104 if (ctx.repo->snapshots) {
105 html("<tr><th>download</th><td colspan='2' class='sha1'>"); 105 html("<tr><th>download</th><td colspan='2' class='sha1'>");
106 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, 106 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
107 hex, ctx.repo->snapshots); 107 hex, ctx.repo->snapshots);
108 html("</td></tr>"); 108 html("</td></tr>");
109 } 109 }
110 html("</table>\n"); 110 html("</table>\n");
111 html("<div class='commit-subject'>"); 111 html("<div class='commit-subject'>");
112 if (ctx.repo->commit_filter) 112 if (ctx.repo->commit_filter)
113 cgit_open_filter(ctx.repo->commit_filter); 113 cgit_open_filter(ctx.repo->commit_filter);
114 html_txt(info->subject); 114 html_txt(info->subject);
115 if (ctx.repo->commit_filter) 115 if (ctx.repo->commit_filter)
116 cgit_close_filter(ctx.repo->commit_filter); 116 cgit_close_filter(ctx.repo->commit_filter);
117 show_commit_decorations(commit); 117 show_commit_decorations(commit);
118 html("</div>"); 118 html("</div>");
119 html("<div class='commit-msg'>"); 119 html("<div class='commit-msg'>");
120 if (ctx.repo->commit_filter) 120 if (ctx.repo->commit_filter)
121 cgit_open_filter(ctx.repo->commit_filter); 121 cgit_open_filter(ctx.repo->commit_filter);
122 html_txt(info->msg); 122 html_txt(info->msg);
123 if (ctx.repo->commit_filter) 123 if (ctx.repo->commit_filter)
124 cgit_close_filter(ctx.repo->commit_filter); 124 cgit_close_filter(ctx.repo->commit_filter);
125 html("</div>"); 125 html("</div>");
126 if (notes.len != 0) { 126 if (notes.len != 0) {
127 html("<div class='notes-header'>Notes</div>"); 127 html("<div class='notes-header'>Notes</div>");
128 html("<div class='notes'>"); 128 html("<div class='notes'>");
129 if (ctx.repo->commit_filter) 129 if (ctx.repo->commit_filter)
130 cgit_open_filter(ctx.repo->commit_filter); 130 cgit_open_filter(ctx.repo->commit_filter);
131 html_txt(notes.buf); 131 html_txt(notes.buf);
132 if (ctx.repo->commit_filter) 132 if (ctx.repo->commit_filter)
133 cgit_close_filter(ctx.repo->commit_filter); 133 cgit_close_filter(ctx.repo->commit_filter);
134 html("</div>"); 134 html("</div>");
135 html("<div class='notes-footer'></div>"); 135 html("<div class='notes-footer'></div>");
136 } 136 }
137 if (parents < 3) { 137 if (parents < 3) {
138 if (parents) 138 if (parents)
139 tmp = sha1_to_hex(commit->parents->item->object.sha1); 139 tmp = sha1_to_hex(commit->parents->item->object.sha1);
140 else 140 else
141 tmp = NULL; 141 tmp = NULL;
142 cgit_print_diff(ctx.qry.sha1, tmp, prefix); 142 cgit_print_diff(ctx.qry.sha1, tmp, prefix);
143 } 143 }
144 strbuf_release(&notes); 144 strbuf_release(&notes);
145 cgit_free_commitinfo(info); 145 cgit_free_commitinfo(info);
146} 146}
diff --git a/ui-log.c b/ui-log.c
index 7f38d2a..0536b23 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,253 +1,253 @@
1/* ui-log.c: functions for log output 1/* ui-log.c: functions for log output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13int files, add_lines, rem_lines; 13int files, add_lines, rem_lines;
14 14
15void count_lines(char *line, int size) 15void count_lines(char *line, int size)
16{ 16{
17 if (size <= 0) 17 if (size <= 0)
18 return; 18 return;
19 19
20 if (line[0] == '+') 20 if (line[0] == '+')
21 add_lines++; 21 add_lines++;
22 22
23 else if (line[0] == '-') 23 else if (line[0] == '-')
24 rem_lines++; 24 rem_lines++;
25} 25}
26 26
27void inspect_files(struct diff_filepair *pair) 27void inspect_files(struct diff_filepair *pair)
28{ 28{
29 unsigned long old_size = 0; 29 unsigned long old_size = 0;
30 unsigned long new_size = 0; 30 unsigned long new_size = 0;
31 int binary = 0; 31 int binary = 0;
32 32
33 files++; 33 files++;
34 if (ctx.repo->enable_log_linecount) 34 if (ctx.repo->enable_log_linecount)
35 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 35 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
36 &new_size, &binary, 0, ctx.qry.ignorews, 36 &new_size, &binary, 0, ctx.qry.ignorews,
37 count_lines); 37 count_lines);
38} 38}
39 39
40void show_commit_decorations(struct commit *commit) 40void show_commit_decorations(struct commit *commit)
41{ 41{
42 struct name_decoration *deco; 42 struct name_decoration *deco;
43 static char buf[1024]; 43 static char buf[1024];
44 44
45 buf[sizeof(buf) - 1] = 0; 45 buf[sizeof(buf) - 1] = 0;
46 deco = lookup_decoration(&name_decoration, &commit->object); 46 deco = lookup_decoration(&name_decoration, &commit->object);
47 while (deco) { 47 while (deco) {
48 if (!prefixcmp(deco->name, "refs/heads/")) { 48 if (!prefixcmp(deco->name, "refs/heads/")) {
49 strncpy(buf, deco->name + 11, sizeof(buf) - 1); 49 strncpy(buf, deco->name + 11, sizeof(buf) - 1);
50 cgit_log_link(buf, NULL, "branch-deco", buf, NULL, 50 cgit_log_link(buf, NULL, "branch-deco", buf, NULL,
51 ctx.qry.vpath, 0, NULL, NULL, 51 ctx.qry.vpath, 0, NULL, NULL,
52 ctx.qry.showmsg); 52 ctx.qry.showmsg);
53 } 53 }
54 else if (!prefixcmp(deco->name, "tag: refs/tags/")) { 54 else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
55 strncpy(buf, deco->name + 15, sizeof(buf) - 1); 55 strncpy(buf, deco->name + 15, sizeof(buf) - 1);
56 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); 56 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
57 } 57 }
58 else if (!prefixcmp(deco->name, "refs/tags/")) { 58 else if (!prefixcmp(deco->name, "refs/tags/")) {
59 strncpy(buf, deco->name + 10, sizeof(buf) - 1); 59 strncpy(buf, deco->name + 10, sizeof(buf) - 1);
60 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); 60 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
61 } 61 }
62 else if (!prefixcmp(deco->name, "refs/remotes/")) { 62 else if (!prefixcmp(deco->name, "refs/remotes/")) {
63 strncpy(buf, deco->name + 13, sizeof(buf) - 1); 63 strncpy(buf, deco->name + 13, sizeof(buf) - 1);
64 cgit_log_link(buf, NULL, "remote-deco", NULL, 64 cgit_log_link(buf, NULL, "remote-deco", NULL,
65 sha1_to_hex(commit->object.sha1), 65 sha1_to_hex(commit->object.sha1),
66 ctx.qry.vpath, 0, NULL, NULL, 66 ctx.qry.vpath, 0, NULL, NULL,
67 ctx.qry.showmsg); 67 ctx.qry.showmsg);
68 } 68 }
69 else { 69 else {
70 strncpy(buf, deco->name, sizeof(buf) - 1); 70 strncpy(buf, deco->name, sizeof(buf) - 1);
71 cgit_commit_link(buf, NULL, "deco", ctx.qry.head, 71 cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
72 sha1_to_hex(commit->object.sha1), 72 sha1_to_hex(commit->object.sha1),
73 ctx.qry.vpath, 0); 73 ctx.qry.vpath, 0);
74 } 74 }
75 deco = deco->next; 75 deco = deco->next;
76 } 76 }
77} 77}
78 78
79void print_commit(struct commit *commit) 79void print_commit(struct commit *commit)
80{ 80{
81 struct commitinfo *info; 81 struct commitinfo *info;
82 char *tmp; 82 char *tmp;
83 int cols = 2; 83 int cols = 2;
84 84
85 info = cgit_parse_commit(commit); 85 info = cgit_parse_commit(commit);
86 htmlf("<tr%s><td>", 86 htmlf("<tr%s><td>",
87 ctx.qry.showmsg ? " class='logheader'" : ""); 87 ctx.qry.showmsg ? " class='logheader'" : "");
88 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 88 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
89 tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); 89 tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp);
90 html_link_open(tmp, NULL, NULL); 90 html_link_open(tmp, NULL, NULL);
91 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 91 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
92 html_link_close(); 92 html_link_close();
93 htmlf("</td><td%s>", 93 htmlf("</td><td%s>",
94 ctx.qry.showmsg ? " class='logsubject'" : ""); 94 ctx.qry.showmsg ? " class='logsubject'" : "");
95 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 95 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
96 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); 96 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
97 show_commit_decorations(commit); 97 show_commit_decorations(commit);
98 html("</td><td>"); 98 html("</td><td>");
99 html_txt(info->author); 99 html_txt(info->author);
100 if (ctx.repo->enable_log_filecount) { 100 if (ctx.repo->enable_log_filecount) {
101 files = 0; 101 files = 0;
102 add_lines = 0; 102 add_lines = 0;
103 rem_lines = 0; 103 rem_lines = 0;
104 cgit_diff_commit(commit, inspect_files); 104 cgit_diff_commit(commit, inspect_files);
105 html("</td><td>"); 105 html("</td><td>");
106 htmlf("%d", files); 106 htmlf("%d", files);
107 if (ctx.repo->enable_log_linecount) { 107 if (ctx.repo->enable_log_linecount) {
108 html("</td><td>"); 108 html("</td><td>");
109 htmlf("-%d/+%d", rem_lines, add_lines); 109 htmlf("-%d/+%d", rem_lines, add_lines);
110 } 110 }
111 } 111 }
112 html("</td></tr>\n"); 112 html("</td></tr>\n");
113 if (ctx.qry.showmsg) { 113 if (ctx.qry.showmsg) {
114 struct strbuf notes = STRBUF_INIT; 114 struct strbuf notes = STRBUF_INIT;
115 get_commit_notes(commit, &notes, PAGE_ENCODING, 0); 115 format_note(NULL, commit->object.sha1, &notes, PAGE_ENCODING, 0);
116 116
117 if (ctx.repo->enable_log_filecount) { 117 if (ctx.repo->enable_log_filecount) {
118 cols++; 118 cols++;
119 if (ctx.repo->enable_log_linecount) 119 if (ctx.repo->enable_log_linecount)
120 cols++; 120 cols++;
121 } 121 }
122 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", 122 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
123 cols); 123 cols);
124 html_txt(info->msg); 124 html_txt(info->msg);
125 html("</td></tr>\n"); 125 html("</td></tr>\n");
126 if (notes.len != 0) { 126 if (notes.len != 0) {
127 html("<tr class='nohover'>"); 127 html("<tr class='nohover'>");
128 html("<td class='lognotes-label'>Notes:</td>"); 128 html("<td class='lognotes-label'>Notes:</td>");
129 htmlf("<td colspan='%d' class='lognotes'>", 129 htmlf("<td colspan='%d' class='lognotes'>",
130 cols); 130 cols);
131 html_txt(notes.buf); 131 html_txt(notes.buf);
132 html("</td></tr>\n"); 132 html("</td></tr>\n");
133 } 133 }
134 strbuf_release(&notes); 134 strbuf_release(&notes);
135 } 135 }
136 cgit_free_commitinfo(info); 136 cgit_free_commitinfo(info);
137} 137}
138 138
139static const char *disambiguate_ref(const char *ref) 139static const char *disambiguate_ref(const char *ref)
140{ 140{
141 unsigned char sha1[20]; 141 unsigned char sha1[20];
142 const char *longref; 142 const char *longref;
143 143
144 longref = fmt("refs/heads/%s", ref); 144 longref = fmt("refs/heads/%s", ref);
145 if (get_sha1(longref, sha1) == 0) 145 if (get_sha1(longref, sha1) == 0)
146 return longref; 146 return longref;
147 147
148 return ref; 148 return ref;
149} 149}
150 150
151void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, 151void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
152 char *path, int pager) 152 char *path, int pager)
153{ 153{
154 struct rev_info rev; 154 struct rev_info rev;
155 struct commit *commit; 155 struct commit *commit;
156 const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; 156 const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
157 int argc = 2; 157 int argc = 2;
158 int i, columns = 3; 158 int i, columns = 3;
159 159
160 if (!tip) 160 if (!tip)
161 tip = ctx.qry.head; 161 tip = ctx.qry.head;
162 162
163 argv[1] = disambiguate_ref(tip); 163 argv[1] = disambiguate_ref(tip);
164 164
165 if (grep && pattern) { 165 if (grep && pattern) {
166 if (!strcmp(grep, "grep") || !strcmp(grep, "author") || 166 if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
167 !strcmp(grep, "committer")) 167 !strcmp(grep, "committer"))
168 argv[argc++] = fmt("--%s=%s", grep, pattern); 168 argv[argc++] = fmt("--%s=%s", grep, pattern);
169 if (!strcmp(grep, "range")) 169 if (!strcmp(grep, "range"))
170 argv[1] = pattern; 170 argv[1] = pattern;
171 } 171 }
172 172
173 if (path) { 173 if (path) {
174 argv[argc++] = "--"; 174 argv[argc++] = "--";
175 argv[argc++] = path; 175 argv[argc++] = path;
176 } 176 }
177 init_revisions(&rev, NULL); 177 init_revisions(&rev, NULL);
178 rev.abbrev = DEFAULT_ABBREV; 178 rev.abbrev = DEFAULT_ABBREV;
179 rev.commit_format = CMIT_FMT_DEFAULT; 179 rev.commit_format = CMIT_FMT_DEFAULT;
180 rev.verbose_header = 1; 180 rev.verbose_header = 1;
181 rev.show_root_diff = 0; 181 rev.show_root_diff = 0;
182 setup_revisions(argc, argv, &rev, NULL); 182 setup_revisions(argc, argv, &rev, NULL);
183 load_ref_decorations(DECORATE_FULL_REFS); 183 load_ref_decorations(DECORATE_FULL_REFS);
184 rev.show_decorations = 1; 184 rev.show_decorations = 1;
185 rev.grep_filter.regflags |= REG_ICASE; 185 rev.grep_filter.regflags |= REG_ICASE;
186 compile_grep_patterns(&rev.grep_filter); 186 compile_grep_patterns(&rev.grep_filter);
187 prepare_revision_walk(&rev); 187 prepare_revision_walk(&rev);
188 188
189 if (pager) 189 if (pager)
190 html("<table class='list nowrap'>"); 190 html("<table class='list nowrap'>");
191 191
192 html("<tr class='nohover'><th class='left'>Age</th>" 192 html("<tr class='nohover'><th class='left'>Age</th>"
193 "<th class='left'>Commit message"); 193 "<th class='left'>Commit message");
194 if (pager) { 194 if (pager) {
195 html(" ("); 195 html(" (");
196 cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, 196 cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
197 NULL, ctx.qry.head, ctx.qry.sha1, 197 NULL, ctx.qry.head, ctx.qry.sha1,
198 ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, 198 ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep,
199 ctx.qry.search, ctx.qry.showmsg ? 0 : 1); 199 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
200 html(")"); 200 html(")");
201 } 201 }
202 html("</th><th class='left'>Author</th>"); 202 html("</th><th class='left'>Author</th>");
203 if (ctx.repo->enable_log_filecount) { 203 if (ctx.repo->enable_log_filecount) {
204 html("<th class='left'>Files</th>"); 204 html("<th class='left'>Files</th>");
205 columns++; 205 columns++;
206 if (ctx.repo->enable_log_linecount) { 206 if (ctx.repo->enable_log_linecount) {
207 html("<th class='left'>Lines</th>"); 207 html("<th class='left'>Lines</th>");
208 columns++; 208 columns++;
209 } 209 }
210 } 210 }
211 html("</tr>\n"); 211 html("</tr>\n");
212 212
213 if (ofs<0) 213 if (ofs<0)
214 ofs = 0; 214 ofs = 0;
215 215
216 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 216 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
217 free(commit->buffer); 217 free(commit->buffer);
218 commit->buffer = NULL; 218 commit->buffer = NULL;
219 free_commit_list(commit->parents); 219 free_commit_list(commit->parents);
220 commit->parents = NULL; 220 commit->parents = NULL;
221 } 221 }
222 222
223 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 223 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
224 print_commit(commit); 224 print_commit(commit);
225 free(commit->buffer); 225 free(commit->buffer);
226 commit->buffer = NULL; 226 commit->buffer = NULL;
227 free_commit_list(commit->parents); 227 free_commit_list(commit->parents);
228 commit->parents = NULL; 228 commit->parents = NULL;
229 } 229 }
230 if (pager) { 230 if (pager) {
231 htmlf("</table><div class='pager'>", 231 htmlf("</table><div class='pager'>",
232 columns); 232 columns);
233 if (ofs > 0) { 233 if (ofs > 0) {
234 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, 234 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
235 ctx.qry.sha1, ctx.qry.vpath, 235 ctx.qry.sha1, ctx.qry.vpath,
236 ofs - cnt, ctx.qry.grep, 236 ofs - cnt, ctx.qry.grep,
237 ctx.qry.search, ctx.qry.showmsg); 237 ctx.qry.search, ctx.qry.showmsg);
238 html("&nbsp;"); 238 html("&nbsp;");
239 } 239 }
240 if ((commit = get_revision(&rev)) != NULL) { 240 if ((commit = get_revision(&rev)) != NULL) {
241 cgit_log_link("[next]", NULL, NULL, ctx.qry.head, 241 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
242 ctx.qry.sha1, ctx.qry.vpath, 242 ctx.qry.sha1, ctx.qry.vpath,
243 ofs + cnt, ctx.qry.grep, 243 ofs + cnt, ctx.qry.grep,
244 ctx.qry.search, ctx.qry.showmsg); 244 ctx.qry.search, ctx.qry.showmsg);
245 } 245 }
246 html("</div>"); 246 html("</div>");
247 } else if ((commit = get_revision(&rev)) != NULL) { 247 } else if ((commit = get_revision(&rev)) != NULL) {
248 html("<tr class='nohover'><td colspan='3'>"); 248 html("<tr class='nohover'><td colspan='3'>");
249 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, 249 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL,
250 ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); 250 ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg);
251 html("</td></tr>\n"); 251 html("</td></tr>\n");
252 } 252 }
253} 253}
diff --git a/ui-plain.c b/ui-plain.c
index da76406..1b2b672 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -1,146 +1,146 @@
1/* ui-plain.c: functions for output of plain blobs by path 1/* ui-plain.c: functions for output of plain blobs by path
2 * 2 *
3 * Copyright (C) 2008 Lars Hjemli 3 * Copyright (C) 2008 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13int match_baselen; 13int match_baselen;
14int match; 14int match;
15 15
16static void print_object(const unsigned char *sha1, const char *path) 16static void print_object(const unsigned char *sha1, const char *path)
17{ 17{
18 enum object_type type; 18 enum object_type type;
19 char *buf, *ext; 19 char *buf, *ext;
20 unsigned long size; 20 unsigned long size;
21 struct string_list_item *mime; 21 struct string_list_item *mime;
22 22
23 type = sha1_object_info(sha1, &size); 23 type = sha1_object_info(sha1, &size);
24 if (type == OBJ_BAD) { 24 if (type == OBJ_BAD) {
25 html_status(404, "Not found", 0); 25 html_status(404, "Not found", 0);
26 return; 26 return;
27 } 27 }
28 28
29 buf = read_sha1_file(sha1, &type, &size); 29 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) { 30 if (!buf) {
31 html_status(404, "Not found", 0); 31 html_status(404, "Not found", 0);
32 return; 32 return;
33 } 33 }
34 ctx.page.mimetype = NULL; 34 ctx.page.mimetype = NULL;
35 ext = strrchr(path, '.'); 35 ext = strrchr(path, '.');
36 if (ext && *(++ext)) { 36 if (ext && *(++ext)) {
37 mime = string_list_lookup(ext, &ctx.cfg.mimetypes); 37 mime = string_list_lookup(&ctx.cfg.mimetypes, ext);
38 if (mime) 38 if (mime)
39 ctx.page.mimetype = (char *)mime->util; 39 ctx.page.mimetype = (char *)mime->util;
40 } 40 }
41 if (!ctx.page.mimetype) { 41 if (!ctx.page.mimetype) {
42 if (buffer_is_binary(buf, size)) 42 if (buffer_is_binary(buf, size))
43 ctx.page.mimetype = "application/octet-stream"; 43 ctx.page.mimetype = "application/octet-stream";
44 else 44 else
45 ctx.page.mimetype = "text/plain"; 45 ctx.page.mimetype = "text/plain";
46 } 46 }
47 ctx.page.filename = fmt("%s", path); 47 ctx.page.filename = fmt("%s", path);
48 ctx.page.size = size; 48 ctx.page.size = size;
49 ctx.page.etag = sha1_to_hex(sha1); 49 ctx.page.etag = sha1_to_hex(sha1);
50 cgit_print_http_headers(&ctx); 50 cgit_print_http_headers(&ctx);
51 html_raw(buf, size); 51 html_raw(buf, size);
52 match = 1; 52 match = 1;
53} 53}
54 54
55static void print_dir(const unsigned char *sha1, const char *path, 55static void print_dir(const unsigned char *sha1, const char *path,
56 const char *base) 56 const char *base)
57{ 57{
58 char *fullpath; 58 char *fullpath;
59 if (path[0] || base[0]) 59 if (path[0] || base[0])
60 fullpath = fmt("/%s%s/", base, path); 60 fullpath = fmt("/%s%s/", base, path);
61 else 61 else
62 fullpath = "/"; 62 fullpath = "/";
63 ctx.page.etag = sha1_to_hex(sha1); 63 ctx.page.etag = sha1_to_hex(sha1);
64 cgit_print_http_headers(&ctx); 64 cgit_print_http_headers(&ctx);
65 htmlf("<html><head><title>%s</title></head>\n<body>\n" 65 htmlf("<html><head><title>%s</title></head>\n<body>\n"
66 " <h2>%s</h2>\n <ul>\n", fullpath, fullpath); 66 " <h2>%s</h2>\n <ul>\n", fullpath, fullpath);
67 if (path[0] || base[0]) 67 if (path[0] || base[0])
68 html(" <li><a href=\"../\">../</a></li>\n"); 68 html(" <li><a href=\"../\">../</a></li>\n");
69 match = 2; 69 match = 2;
70} 70}
71 71
72static void print_dir_entry(const unsigned char *sha1, const char *path, 72static void print_dir_entry(const unsigned char *sha1, const char *path,
73 unsigned mode) 73 unsigned mode)
74{ 74{
75 const char *sep = ""; 75 const char *sep = "";
76 if (S_ISDIR(mode)) 76 if (S_ISDIR(mode))
77 sep = "/"; 77 sep = "/";
78 htmlf(" <li><a href=\"%s%s\">%s%s</a></li>\n", path, sep, path, sep); 78 htmlf(" <li><a href=\"%s%s\">%s%s</a></li>\n", path, sep, path, sep);
79 match = 2; 79 match = 2;
80} 80}
81 81
82static void print_dir_tail(void) 82static void print_dir_tail(void)
83{ 83{
84 html(" </ul>\n</body></html>\n"); 84 html(" </ul>\n</body></html>\n");
85} 85}
86 86
87static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 87static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
88 const char *pathname, unsigned mode, int stage, 88 const char *pathname, unsigned mode, int stage,
89 void *cbdata) 89 void *cbdata)
90{ 90{
91 if (baselen == match_baselen) { 91 if (baselen == match_baselen) {
92 if (S_ISREG(mode)) 92 if (S_ISREG(mode))
93 print_object(sha1, pathname); 93 print_object(sha1, pathname);
94 else if (S_ISDIR(mode)) { 94 else if (S_ISDIR(mode)) {
95 print_dir(sha1, pathname, base); 95 print_dir(sha1, pathname, base);
96 return READ_TREE_RECURSIVE; 96 return READ_TREE_RECURSIVE;
97 } 97 }
98 } 98 }
99 else if (baselen > match_baselen) 99 else if (baselen > match_baselen)
100 print_dir_entry(sha1, pathname, mode); 100 print_dir_entry(sha1, pathname, mode);
101 else if (S_ISDIR(mode)) 101 else if (S_ISDIR(mode))
102 return READ_TREE_RECURSIVE; 102 return READ_TREE_RECURSIVE;
103 103
104 return 0; 104 return 0;
105} 105}
106 106
107static int basedir_len(const char *path) 107static int basedir_len(const char *path)
108{ 108{
109 char *p = strrchr(path, '/'); 109 char *p = strrchr(path, '/');
110 if (p) 110 if (p)
111 return p - path + 1; 111 return p - path + 1;
112 return 0; 112 return 0;
113} 113}
114 114
115void cgit_print_plain(struct cgit_context *ctx) 115void cgit_print_plain(struct cgit_context *ctx)
116{ 116{
117 const char *rev = ctx->qry.sha1; 117 const char *rev = ctx->qry.sha1;
118 unsigned char sha1[20]; 118 unsigned char sha1[20];
119 struct commit *commit; 119 struct commit *commit;
120 const char *paths[] = {ctx->qry.path, NULL}; 120 const char *paths[] = {ctx->qry.path, NULL};
121 121
122 if (!rev) 122 if (!rev)
123 rev = ctx->qry.head; 123 rev = ctx->qry.head;
124 124
125 if (get_sha1(rev, sha1)) { 125 if (get_sha1(rev, sha1)) {
126 html_status(404, "Not found", 0); 126 html_status(404, "Not found", 0);
127 return; 127 return;
128 } 128 }
129 commit = lookup_commit_reference(sha1); 129 commit = lookup_commit_reference(sha1);
130 if (!commit || parse_commit(commit)) { 130 if (!commit || parse_commit(commit)) {
131 html_status(404, "Not found", 0); 131 html_status(404, "Not found", 0);
132 return; 132 return;
133 } 133 }
134 if (!paths[0]) { 134 if (!paths[0]) {
135 paths[0] = ""; 135 paths[0] = "";
136 match_baselen = -1; 136 match_baselen = -1;
137 print_dir(commit->tree->object.sha1, "", ""); 137 print_dir(commit->tree->object.sha1, "", "");
138 } 138 }
139 else 139 else
140 match_baselen = basedir_len(paths[0]); 140 match_baselen = basedir_len(paths[0]);
141 read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); 141 read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
142 if (!match) 142 if (!match)
143 html_status(404, "Not found", 0); 143 html_status(404, "Not found", 0);
144 else if (match == 2) 144 else if (match == 2)
145 print_dir_tail(); 145 print_dir_tail();
146} 146}
diff --git a/ui-stats.c b/ui-stats.c
index bdaf9cc..50c2540 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -1,418 +1,418 @@
1#include <string-list.h> 1#include <string-list.h>
2 2
3#include "cgit.h" 3#include "cgit.h"
4#include "html.h" 4#include "html.h"
5#include "ui-shared.h" 5#include "ui-shared.h"
6#include "ui-stats.h" 6#include "ui-stats.h"
7 7
8#define MONTHS 6 8#define MONTHS 6
9 9
10struct authorstat { 10struct authorstat {
11 long total; 11 long total;
12 struct string_list list; 12 struct string_list list;
13}; 13};
14 14
15#define DAY_SECS (60 * 60 * 24) 15#define DAY_SECS (60 * 60 * 24)
16#define WEEK_SECS (DAY_SECS * 7) 16#define WEEK_SECS (DAY_SECS * 7)
17 17
18static void trunc_week(struct tm *tm) 18static void trunc_week(struct tm *tm)
19{ 19{
20 time_t t = timegm(tm); 20 time_t t = timegm(tm);
21 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; 21 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS;
22 gmtime_r(&t, tm); 22 gmtime_r(&t, tm);
23} 23}
24 24
25static void dec_week(struct tm *tm) 25static void dec_week(struct tm *tm)
26{ 26{
27 time_t t = timegm(tm); 27 time_t t = timegm(tm);
28 t -= WEEK_SECS; 28 t -= WEEK_SECS;
29 gmtime_r(&t, tm); 29 gmtime_r(&t, tm);
30} 30}
31 31
32static void inc_week(struct tm *tm) 32static void inc_week(struct tm *tm)
33{ 33{
34 time_t t = timegm(tm); 34 time_t t = timegm(tm);
35 t += WEEK_SECS; 35 t += WEEK_SECS;
36 gmtime_r(&t, tm); 36 gmtime_r(&t, tm);
37} 37}
38 38
39static char *pretty_week(struct tm *tm) 39static char *pretty_week(struct tm *tm)
40{ 40{
41 static char buf[10]; 41 static char buf[10];
42 42
43 strftime(buf, sizeof(buf), "W%V %G", tm); 43 strftime(buf, sizeof(buf), "W%V %G", tm);
44 return buf; 44 return buf;
45} 45}
46 46
47static void trunc_month(struct tm *tm) 47static void trunc_month(struct tm *tm)
48{ 48{
49 tm->tm_mday = 1; 49 tm->tm_mday = 1;
50} 50}
51 51
52static void dec_month(struct tm *tm) 52static void dec_month(struct tm *tm)
53{ 53{
54 tm->tm_mon--; 54 tm->tm_mon--;
55 if (tm->tm_mon < 0) { 55 if (tm->tm_mon < 0) {
56 tm->tm_year--; 56 tm->tm_year--;
57 tm->tm_mon = 11; 57 tm->tm_mon = 11;
58 } 58 }
59} 59}
60 60
61static void inc_month(struct tm *tm) 61static void inc_month(struct tm *tm)
62{ 62{
63 tm->tm_mon++; 63 tm->tm_mon++;
64 if (tm->tm_mon > 11) { 64 if (tm->tm_mon > 11) {
65 tm->tm_year++; 65 tm->tm_year++;
66 tm->tm_mon = 0; 66 tm->tm_mon = 0;
67 } 67 }
68} 68}
69 69
70static char *pretty_month(struct tm *tm) 70static char *pretty_month(struct tm *tm)
71{ 71{
72 static const char *months[] = { 72 static const char *months[] = {
73 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 73 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
74 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 74 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
75 }; 75 };
76 return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); 76 return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900);
77} 77}
78 78
79static void trunc_quarter(struct tm *tm) 79static void trunc_quarter(struct tm *tm)
80{ 80{
81 trunc_month(tm); 81 trunc_month(tm);
82 while(tm->tm_mon % 3 != 0) 82 while(tm->tm_mon % 3 != 0)
83 dec_month(tm); 83 dec_month(tm);
84} 84}
85 85
86static void dec_quarter(struct tm *tm) 86static void dec_quarter(struct tm *tm)
87{ 87{
88 dec_month(tm); 88 dec_month(tm);
89 dec_month(tm); 89 dec_month(tm);
90 dec_month(tm); 90 dec_month(tm);
91} 91}
92 92
93static void inc_quarter(struct tm *tm) 93static void inc_quarter(struct tm *tm)
94{ 94{
95 inc_month(tm); 95 inc_month(tm);
96 inc_month(tm); 96 inc_month(tm);
97 inc_month(tm); 97 inc_month(tm);
98} 98}
99 99
100static char *pretty_quarter(struct tm *tm) 100static char *pretty_quarter(struct tm *tm)
101{ 101{
102 return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); 102 return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900);
103} 103}
104 104
105static void trunc_year(struct tm *tm) 105static void trunc_year(struct tm *tm)
106{ 106{
107 trunc_month(tm); 107 trunc_month(tm);
108 tm->tm_mon = 0; 108 tm->tm_mon = 0;
109} 109}
110 110
111static void dec_year(struct tm *tm) 111static void dec_year(struct tm *tm)
112{ 112{
113 tm->tm_year--; 113 tm->tm_year--;
114} 114}
115 115
116static void inc_year(struct tm *tm) 116static void inc_year(struct tm *tm)
117{ 117{
118 tm->tm_year++; 118 tm->tm_year++;
119} 119}
120 120
121static char *pretty_year(struct tm *tm) 121static char *pretty_year(struct tm *tm)
122{ 122{
123 return fmt("%d", tm->tm_year + 1900); 123 return fmt("%d", tm->tm_year + 1900);
124} 124}
125 125
126struct cgit_period periods[] = { 126struct cgit_period periods[] = {
127 {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, 127 {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week},
128 {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, 128 {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month},
129 {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, 129 {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
130 {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, 130 {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year},
131}; 131};
132 132
133/* Given a period code or name, return a period index (1, 2, 3 or 4) 133/* Given a period code or name, return a period index (1, 2, 3 or 4)
134 * and update the period pointer to the correcsponding struct. 134 * and update the period pointer to the correcsponding struct.
135 * If no matching code is found, return 0. 135 * If no matching code is found, return 0.
136 */ 136 */
137int cgit_find_stats_period(const char *expr, struct cgit_period **period) 137int cgit_find_stats_period(const char *expr, struct cgit_period **period)
138{ 138{
139 int i; 139 int i;
140 char code = '\0'; 140 char code = '\0';
141 141
142 if (!expr) 142 if (!expr)
143 return 0; 143 return 0;
144 144
145 if (strlen(expr) == 1) 145 if (strlen(expr) == 1)
146 code = expr[0]; 146 code = expr[0];
147 147
148 for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) 148 for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++)
149 if (periods[i].code == code || !strcmp(periods[i].name, expr)) { 149 if (periods[i].code == code || !strcmp(periods[i].name, expr)) {
150 if (period) 150 if (period)
151 *period = &periods[i]; 151 *period = &periods[i];
152 return i+1; 152 return i+1;
153 } 153 }
154 return 0; 154 return 0;
155} 155}
156 156
157const char *cgit_find_stats_periodname(int idx) 157const char *cgit_find_stats_periodname(int idx)
158{ 158{
159 if (idx > 0 && idx < 4) 159 if (idx > 0 && idx < 4)
160 return periods[idx - 1].name; 160 return periods[idx - 1].name;
161 else 161 else
162 return ""; 162 return "";
163} 163}
164 164
165static void add_commit(struct string_list *authors, struct commit *commit, 165static void add_commit(struct string_list *authors, struct commit *commit,
166 struct cgit_period *period) 166 struct cgit_period *period)
167{ 167{
168 struct commitinfo *info; 168 struct commitinfo *info;
169 struct string_list_item *author, *item; 169 struct string_list_item *author, *item;
170 struct authorstat *authorstat; 170 struct authorstat *authorstat;
171 struct string_list *items; 171 struct string_list *items;
172 char *tmp; 172 char *tmp;
173 struct tm *date; 173 struct tm *date;
174 time_t t; 174 time_t t;
175 175
176 info = cgit_parse_commit(commit); 176 info = cgit_parse_commit(commit);
177 tmp = xstrdup(info->author); 177 tmp = xstrdup(info->author);
178 author = string_list_insert(tmp, authors); 178 author = string_list_insert(authors, tmp);
179 if (!author->util) 179 if (!author->util)
180 author->util = xcalloc(1, sizeof(struct authorstat)); 180 author->util = xcalloc(1, sizeof(struct authorstat));
181 else 181 else
182 free(tmp); 182 free(tmp);
183 authorstat = author->util; 183 authorstat = author->util;
184 items = &authorstat->list; 184 items = &authorstat->list;
185 t = info->committer_date; 185 t = info->committer_date;
186 date = gmtime(&t); 186 date = gmtime(&t);
187 period->trunc(date); 187 period->trunc(date);
188 tmp = xstrdup(period->pretty(date)); 188 tmp = xstrdup(period->pretty(date));
189 item = string_list_insert(tmp, items); 189 item = string_list_insert(items, tmp);
190 if (item->util) 190 if (item->util)
191 free(tmp); 191 free(tmp);
192 item->util++; 192 item->util++;
193 authorstat->total++; 193 authorstat->total++;
194 cgit_free_commitinfo(info); 194 cgit_free_commitinfo(info);
195} 195}
196 196
197static int cmp_total_commits(const void *a1, const void *a2) 197static int cmp_total_commits(const void *a1, const void *a2)
198{ 198{
199 const struct string_list_item *i1 = a1; 199 const struct string_list_item *i1 = a1;
200 const struct string_list_item *i2 = a2; 200 const struct string_list_item *i2 = a2;
201 const struct authorstat *auth1 = i1->util; 201 const struct authorstat *auth1 = i1->util;
202 const struct authorstat *auth2 = i2->util; 202 const struct authorstat *auth2 = i2->util;
203 203
204 return auth2->total - auth1->total; 204 return auth2->total - auth1->total;
205} 205}
206 206
207/* Walk the commit DAG and collect number of commits per author per 207/* Walk the commit DAG and collect number of commits per author per
208 * timeperiod into a nested string_list collection. 208 * timeperiod into a nested string_list collection.
209 */ 209 */
210struct string_list collect_stats(struct cgit_context *ctx, 210struct string_list collect_stats(struct cgit_context *ctx,
211 struct cgit_period *period) 211 struct cgit_period *period)
212{ 212{
213 struct string_list authors; 213 struct string_list authors;
214 struct rev_info rev; 214 struct rev_info rev;
215 struct commit *commit; 215 struct commit *commit;
216 const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; 216 const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL};
217 int argc = 3; 217 int argc = 3;
218 time_t now; 218 time_t now;
219 long i; 219 long i;
220 struct tm *tm; 220 struct tm *tm;
221 char tmp[11]; 221 char tmp[11];
222 222
223 time(&now); 223 time(&now);
224 tm = gmtime(&now); 224 tm = gmtime(&now);
225 period->trunc(tm); 225 period->trunc(tm);
226 for (i = 1; i < period->count; i++) 226 for (i = 1; i < period->count; i++)
227 period->dec(tm); 227 period->dec(tm);
228 strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); 228 strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm);
229 argv[2] = xstrdup(fmt("--since=%s", tmp)); 229 argv[2] = xstrdup(fmt("--since=%s", tmp));
230 if (ctx->qry.path) { 230 if (ctx->qry.path) {
231 argv[3] = "--"; 231 argv[3] = "--";
232 argv[4] = ctx->qry.path; 232 argv[4] = ctx->qry.path;
233 argc += 2; 233 argc += 2;
234 } 234 }
235 init_revisions(&rev, NULL); 235 init_revisions(&rev, NULL);
236 rev.abbrev = DEFAULT_ABBREV; 236 rev.abbrev = DEFAULT_ABBREV;
237 rev.commit_format = CMIT_FMT_DEFAULT; 237 rev.commit_format = CMIT_FMT_DEFAULT;
238 rev.no_merges = 1; 238 rev.no_merges = 1;
239 rev.verbose_header = 1; 239 rev.verbose_header = 1;
240 rev.show_root_diff = 0; 240 rev.show_root_diff = 0;
241 setup_revisions(argc, argv, &rev, NULL); 241 setup_revisions(argc, argv, &rev, NULL);
242 prepare_revision_walk(&rev); 242 prepare_revision_walk(&rev);
243 memset(&authors, 0, sizeof(authors)); 243 memset(&authors, 0, sizeof(authors));
244 while ((commit = get_revision(&rev)) != NULL) { 244 while ((commit = get_revision(&rev)) != NULL) {
245 add_commit(&authors, commit, period); 245 add_commit(&authors, commit, period);
246 free(commit->buffer); 246 free(commit->buffer);
247 free_commit_list(commit->parents); 247 free_commit_list(commit->parents);
248 } 248 }
249 return authors; 249 return authors;
250} 250}
251 251
252void print_combined_authorrow(struct string_list *authors, int from, int to, 252void print_combined_authorrow(struct string_list *authors, int from, int to,
253 const char *name, const char *leftclass, const char *centerclass, 253 const char *name, const char *leftclass, const char *centerclass,
254 const char *rightclass, struct cgit_period *period) 254 const char *rightclass, struct cgit_period *period)
255{ 255{
256 struct string_list_item *author; 256 struct string_list_item *author;
257 struct authorstat *authorstat; 257 struct authorstat *authorstat;
258 struct string_list *items; 258 struct string_list *items;
259 struct string_list_item *date; 259 struct string_list_item *date;
260 time_t now; 260 time_t now;
261 long i, j, total, subtotal; 261 long i, j, total, subtotal;
262 struct tm *tm; 262 struct tm *tm;
263 char *tmp; 263 char *tmp;
264 264
265 time(&now); 265 time(&now);
266 tm = gmtime(&now); 266 tm = gmtime(&now);
267 period->trunc(tm); 267 period->trunc(tm);
268 for (i = 1; i < period->count; i++) 268 for (i = 1; i < period->count; i++)
269 period->dec(tm); 269 period->dec(tm);
270 270
271 total = 0; 271 total = 0;
272 htmlf("<tr><td class='%s'>%s</td>", leftclass, 272 htmlf("<tr><td class='%s'>%s</td>", leftclass,
273 fmt(name, to - from + 1)); 273 fmt(name, to - from + 1));
274 for (j = 0; j < period->count; j++) { 274 for (j = 0; j < period->count; j++) {
275 tmp = period->pretty(tm); 275 tmp = period->pretty(tm);
276 period->inc(tm); 276 period->inc(tm);
277 subtotal = 0; 277 subtotal = 0;
278 for (i = from; i <= to; i++) { 278 for (i = from; i <= to; i++) {
279 author = &authors->items[i]; 279 author = &authors->items[i];
280 authorstat = author->util; 280 authorstat = author->util;
281 items = &authorstat->list; 281 items = &authorstat->list;
282 date = string_list_lookup(tmp, items); 282 date = string_list_lookup(items, tmp);
283 if (date) 283 if (date)
284 subtotal += (size_t)date->util; 284 subtotal += (size_t)date->util;
285 } 285 }
286 htmlf("<td class='%s'>%d</td>", centerclass, subtotal); 286 htmlf("<td class='%s'>%d</td>", centerclass, subtotal);
287 total += subtotal; 287 total += subtotal;
288 } 288 }
289 htmlf("<td class='%s'>%d</td></tr>", rightclass, total); 289 htmlf("<td class='%s'>%d</td></tr>", rightclass, total);
290} 290}
291 291
292void print_authors(struct string_list *authors, int top, 292void print_authors(struct string_list *authors, int top,
293 struct cgit_period *period) 293 struct cgit_period *period)
294{ 294{
295 struct string_list_item *author; 295 struct string_list_item *author;
296 struct authorstat *authorstat; 296 struct authorstat *authorstat;
297 struct string_list *items; 297 struct string_list *items;
298 struct string_list_item *date; 298 struct string_list_item *date;
299 time_t now; 299 time_t now;
300 long i, j, total; 300 long i, j, total;
301 struct tm *tm; 301 struct tm *tm;
302 char *tmp; 302 char *tmp;
303 303
304 time(&now); 304 time(&now);
305 tm = gmtime(&now); 305 tm = gmtime(&now);
306 period->trunc(tm); 306 period->trunc(tm);
307 for (i = 1; i < period->count; i++) 307 for (i = 1; i < period->count; i++)
308 period->dec(tm); 308 period->dec(tm);
309 309
310 html("<table class='stats'><tr><th>Author</th>"); 310 html("<table class='stats'><tr><th>Author</th>");
311 for (j = 0; j < period->count; j++) { 311 for (j = 0; j < period->count; j++) {
312 tmp = period->pretty(tm); 312 tmp = period->pretty(tm);
313 htmlf("<th>%s</th>", tmp); 313 htmlf("<th>%s</th>", tmp);
314 period->inc(tm); 314 period->inc(tm);
315 } 315 }
316 html("<th>Total</th></tr>\n"); 316 html("<th>Total</th></tr>\n");
317 317
318 if (top <= 0 || top > authors->nr) 318 if (top <= 0 || top > authors->nr)
319 top = authors->nr; 319 top = authors->nr;
320 320
321 for (i = 0; i < top; i++) { 321 for (i = 0; i < top; i++) {
322 author = &authors->items[i]; 322 author = &authors->items[i];
323 html("<tr><td class='left'>"); 323 html("<tr><td class='left'>");
324 html_txt(author->string); 324 html_txt(author->string);
325 html("</td>"); 325 html("</td>");
326 authorstat = author->util; 326 authorstat = author->util;
327 items = &authorstat->list; 327 items = &authorstat->list;
328 total = 0; 328 total = 0;
329 for (j = 0; j < period->count; j++) 329 for (j = 0; j < period->count; j++)
330 period->dec(tm); 330 period->dec(tm);
331 for (j = 0; j < period->count; j++) { 331 for (j = 0; j < period->count; j++) {
332 tmp = period->pretty(tm); 332 tmp = period->pretty(tm);
333 period->inc(tm); 333 period->inc(tm);
334 date = string_list_lookup(tmp, items); 334 date = string_list_lookup(items, tmp);
335 if (!date) 335 if (!date)
336 html("<td>0</td>"); 336 html("<td>0</td>");
337 else { 337 else {
338 htmlf("<td>%d</td>", date->util); 338 htmlf("<td>%d</td>", date->util);
339 total += (size_t)date->util; 339 total += (size_t)date->util;
340 } 340 }
341 } 341 }
342 htmlf("<td class='sum'>%d</td></tr>", total); 342 htmlf("<td class='sum'>%d</td></tr>", total);
343 } 343 }
344 344
345 if (top < authors->nr) 345 if (top < authors->nr)
346 print_combined_authorrow(authors, top, authors->nr - 1, 346 print_combined_authorrow(authors, top, authors->nr - 1,
347 "Others (%d)", "left", "", "sum", period); 347 "Others (%d)", "left", "", "sum", period);
348 348
349 print_combined_authorrow(authors, 0, authors->nr - 1, "Total", 349 print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
350 "total", "sum", "sum", period); 350 "total", "sum", "sum", period);
351 html("</table>"); 351 html("</table>");
352} 352}
353 353
354/* Create a sorted string_list with one entry per author. The util-field 354/* Create a sorted string_list with one entry per author. The util-field
355 * for each author is another string_list which is used to calculate the 355 * for each author is another string_list which is used to calculate the
356 * number of commits per time-interval. 356 * number of commits per time-interval.
357 */ 357 */
358void cgit_show_stats(struct cgit_context *ctx) 358void cgit_show_stats(struct cgit_context *ctx)
359{ 359{
360 struct string_list authors; 360 struct string_list authors;
361 struct cgit_period *period; 361 struct cgit_period *period;
362 int top, i; 362 int top, i;
363 const char *code = "w"; 363 const char *code = "w";
364 364
365 if (ctx->qry.period) 365 if (ctx->qry.period)
366 code = ctx->qry.period; 366 code = ctx->qry.period;
367 367
368 i = cgit_find_stats_period(code, &period); 368 i = cgit_find_stats_period(code, &period);
369 if (!i) { 369 if (!i) {
370 cgit_print_error(fmt("Unknown statistics type: %c", code)); 370 cgit_print_error(fmt("Unknown statistics type: %c", code));
371 return; 371 return;
372 } 372 }
373 if (i > ctx->repo->max_stats) { 373 if (i > ctx->repo->max_stats) {
374 cgit_print_error(fmt("Statistics type disabled: %s", 374 cgit_print_error(fmt("Statistics type disabled: %s",
375 period->name)); 375 period->name));
376 return; 376 return;
377 } 377 }
378 authors = collect_stats(ctx, period); 378 authors = collect_stats(ctx, period);
379 qsort(authors.items, authors.nr, sizeof(struct string_list_item), 379 qsort(authors.items, authors.nr, sizeof(struct string_list_item),
380 cmp_total_commits); 380 cmp_total_commits);
381 381
382 top = ctx->qry.ofs; 382 top = ctx->qry.ofs;
383 if (!top) 383 if (!top)
384 top = 10; 384 top = 10;
385 htmlf("<h2>Commits per author per %s", period->name); 385 htmlf("<h2>Commits per author per %s", period->name);
386 if (ctx->qry.path) { 386 if (ctx->qry.path) {
387 html(" (path '"); 387 html(" (path '");
388 html_txt(ctx->qry.path); 388 html_txt(ctx->qry.path);
389 html("')"); 389 html("')");
390 } 390 }
391 html("</h2>"); 391 html("</h2>");
392 392
393 html("<form method='get' action='' style='float: right; text-align: right;'>"); 393 html("<form method='get' action='' style='float: right; text-align: right;'>");
394 cgit_add_hidden_formfields(1, 0, "stats"); 394 cgit_add_hidden_formfields(1, 0, "stats");
395 if (ctx->repo->max_stats > 1) { 395 if (ctx->repo->max_stats > 1) {
396 html("Period: "); 396 html("Period: ");
397 html("<select name='period' onchange='this.form.submit();'>"); 397 html("<select name='period' onchange='this.form.submit();'>");
398 for (i = 0; i < ctx->repo->max_stats; i++) 398 for (i = 0; i < ctx->repo->max_stats; i++)
399 htmlf("<option value='%c'%s>%s</option>", 399 htmlf("<option value='%c'%s>%s</option>",
400 periods[i].code, 400 periods[i].code,
401 period == &periods[i] ? " selected" : "", 401 period == &periods[i] ? " selected" : "",
402 periods[i].name); 402 periods[i].name);
403 html("</select><br/><br/>"); 403 html("</select><br/><br/>");
404 } 404 }
405 html("Authors: "); 405 html("Authors: ");
406 html(""); 406 html("");
407 html("<select name='ofs' onchange='this.form.submit();'>"); 407 html("<select name='ofs' onchange='this.form.submit();'>");
408 htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); 408 htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : "");
409 htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); 409 htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : "");
410 htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); 410 htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : "");
411 htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); 411 htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : "");
412 htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); 412 htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : "");
413 html("</select>"); 413 html("</select>");
414 html("<noscript>&nbsp;&nbsp;<input type='submit' value='Reload'/></noscript>"); 414 html("<noscript>&nbsp;&nbsp;<input type='submit' value='Reload'/></noscript>");
415 html("</form>"); 415 html("</form>");
416 print_authors(&authors, top, period); 416 print_authors(&authors, top, period);
417} 417}
418 418