author | Lars Hjemli <hjemli@gmail.com> | 2010-09-27 05:58:01 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-09-27 05:58:13 (UTC) |
commit | 82a883ede7e47616aba041a5eb36e08666ef9177 (patch) (unidiff) | |
tree | 14acc2bad5ca5375aa08cb946788b6923d72df7c | |
parent | aaa3f7854232726d5530f66b9459e036bbba15cb (diff) | |
download | cgit-82a883ede7e47616aba041a5eb36e08666ef9177.zip cgit-82a883ede7e47616aba041a5eb36e08666ef9177.tar.gz cgit-82a883ede7e47616aba041a5eb36e08666ef9177.tar.bz2 |
Use GIT-1.7.3
This fixes http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-2542.
Noticed-by: Silvio Cesare <silvio.cesare@gmail.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | cgit.c | 2 | ||||
m--------- | git | 0 | ||||
-rw-r--r-- | ui-plain.c | 2 | ||||
-rw-r--r-- | ui-stats.c | 8 |
5 files changed, 8 insertions, 8 deletions
@@ -1,171 +1,171 @@ | |||
1 | CGIT_VERSION = v0.8.3.3 | 1 | CGIT_VERSION = v0.8.3.3 |
2 | CGIT_SCRIPT_NAME = cgit.cgi | 2 | CGIT_SCRIPT_NAME = cgit.cgi |
3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit | 3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit |
4 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) | 4 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) |
5 | CGIT_CONFIG = /etc/cgitrc | 5 | CGIT_CONFIG = /etc/cgitrc |
6 | CACHE_ROOT = /var/cache/cgit | 6 | CACHE_ROOT = /var/cache/cgit |
7 | SHA1_HEADER = <openssl/sha.h> | 7 | SHA1_HEADER = <openssl/sha.h> |
8 | GIT_VER = 1.6.4.3 | 8 | GIT_VER = 1.7.3 |
9 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 9 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
10 | INSTALL = install | 10 | INSTALL = 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 NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). | 14 | # Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). |
15 | # | 15 | # |
16 | 16 | ||
17 | #-include config.mak | 17 | #-include config.mak |
18 | 18 | ||
19 | # | 19 | # |
20 | # Platform specific tweaks | 20 | # Platform specific tweaks |
21 | # | 21 | # |
22 | 22 | ||
23 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | 23 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
24 | uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') | 24 | uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') |
25 | uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') | 25 | uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') |
26 | 26 | ||
27 | ifeq ($(uname_O),Cygwin) | 27 | ifeq ($(uname_O),Cygwin) |
28 | NO_STRCASESTR = YesPlease | 28 | NO_STRCASESTR = YesPlease |
29 | NEEDS_LIBICONV = YesPlease | 29 | NEEDS_LIBICONV = YesPlease |
30 | endif | 30 | endif |
31 | 31 | ||
32 | # | 32 | # |
33 | # Let the user override the above settings. | 33 | # Let the user override the above settings. |
34 | # | 34 | # |
35 | -include cgit.conf | 35 | -include cgit.conf |
36 | 36 | ||
37 | # | 37 | # |
38 | # Define a way to invoke make in subdirs quietly, shamelessly ripped | 38 | # Define a way to invoke make in subdirs quietly, shamelessly ripped |
39 | # from git.git | 39 | # from git.git |
40 | # | 40 | # |
41 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | 41 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir |
42 | QUIET_SUBDIR1 = | 42 | QUIET_SUBDIR1 = |
43 | 43 | ||
44 | ifneq ($(findstring $(MAKEFLAGS),w),w) | 44 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
45 | PRINT_DIR = --no-print-directory | 45 | PRINT_DIR = --no-print-directory |
46 | else # "make -w" | 46 | else # "make -w" |
47 | NO_SUBDIR = : | 47 | NO_SUBDIR = : |
48 | endif | 48 | endif |
49 | 49 | ||
50 | ifndef V | 50 | ifndef V |
51 | QUIET_CC = @echo ' ' CC $@; | 51 | QUIET_CC = @echo ' ' CC $@; |
52 | QUIET_MM = @echo ' ' MM $@; | 52 | QUIET_MM = @echo ' ' MM $@; |
53 | QUIET_SUBDIR0 = +@subdir= | 53 | QUIET_SUBDIR0 = +@subdir= |
54 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ | 54 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ |
55 | $(MAKE) $(PRINT_DIR) -C $$subdir | 55 | $(MAKE) $(PRINT_DIR) -C $$subdir |
56 | endif | 56 | endif |
57 | 57 | ||
58 | # | 58 | # |
59 | # Define a pattern rule for automatic dependency building | 59 | # Define a pattern rule for automatic dependency building |
60 | # | 60 | # |
61 | %.d: %.c | 61 | %.d: %.c |
62 | $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ | 62 | $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ |
63 | 63 | ||
64 | # | 64 | # |
65 | # Define a pattern rule for silent object building | 65 | # Define a pattern rule for silent object building |
66 | # | 66 | # |
67 | %.o: %.c | 67 | %.o: %.c |
68 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< | 68 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< |
69 | 69 | ||
70 | 70 | ||
71 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 71 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto -lpthread |
72 | OBJECTS = | 72 | OBJECTS = |
73 | OBJECTS += cache.o | 73 | OBJECTS += cache.o |
74 | OBJECTS += cgit.o | 74 | OBJECTS += cgit.o |
75 | OBJECTS += cmd.o | 75 | OBJECTS += cmd.o |
76 | OBJECTS += configfile.o | 76 | OBJECTS += configfile.o |
77 | OBJECTS += html.o | 77 | OBJECTS += html.o |
78 | OBJECTS += parsing.o | 78 | OBJECTS += parsing.o |
79 | OBJECTS += scan-tree.o | 79 | OBJECTS += scan-tree.o |
80 | OBJECTS += shared.o | 80 | OBJECTS += shared.o |
81 | OBJECTS += ui-atom.o | 81 | OBJECTS += ui-atom.o |
82 | OBJECTS += ui-blob.o | 82 | OBJECTS += ui-blob.o |
83 | OBJECTS += ui-clone.o | 83 | OBJECTS += ui-clone.o |
84 | OBJECTS += ui-commit.o | 84 | OBJECTS += ui-commit.o |
85 | OBJECTS += ui-diff.o | 85 | OBJECTS += ui-diff.o |
86 | OBJECTS += ui-log.o | 86 | OBJECTS += ui-log.o |
87 | OBJECTS += ui-patch.o | 87 | OBJECTS += ui-patch.o |
88 | OBJECTS += ui-plain.o | 88 | OBJECTS += ui-plain.o |
89 | OBJECTS += ui-refs.o | 89 | OBJECTS += ui-refs.o |
90 | OBJECTS += ui-repolist.o | 90 | OBJECTS += ui-repolist.o |
91 | OBJECTS += ui-shared.o | 91 | OBJECTS += ui-shared.o |
92 | OBJECTS += ui-snapshot.o | 92 | OBJECTS += ui-snapshot.o |
93 | OBJECTS += ui-stats.o | 93 | OBJECTS += ui-stats.o |
94 | OBJECTS += ui-summary.o | 94 | OBJECTS += ui-summary.o |
95 | OBJECTS += ui-tag.o | 95 | OBJECTS += ui-tag.o |
96 | OBJECTS += ui-tree.o | 96 | OBJECTS += ui-tree.o |
97 | 97 | ||
98 | ifdef NEEDS_LIBICONV | 98 | ifdef NEEDS_LIBICONV |
99 | EXTLIBS += -liconv | 99 | EXTLIBS += -liconv |
100 | endif | 100 | endif |
101 | 101 | ||
102 | 102 | ||
103 | .PHONY: all libgit test install uninstall clean force-version get-git \ | 103 | .PHONY: all libgit test install uninstall clean force-version get-git \ |
104 | doc man-doc html-doc clean-doc | 104 | doc man-doc html-doc clean-doc |
105 | 105 | ||
106 | all: cgit | 106 | all: cgit |
107 | 107 | ||
108 | VERSION: force-version | 108 | VERSION: force-version |
109 | @./gen-version.sh "$(CGIT_VERSION)" | 109 | @./gen-version.sh "$(CGIT_VERSION)" |
110 | -include VERSION | 110 | -include VERSION |
111 | 111 | ||
112 | 112 | ||
113 | CFLAGS += -g -Wall -Igit | 113 | CFLAGS += -g -Wall -Igit |
114 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 114 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
115 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 115 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
116 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 116 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
117 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 117 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
118 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 118 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
119 | 119 | ||
120 | ifdef NO_ICONV | 120 | ifdef NO_ICONV |
121 | CFLAGS += -DNO_ICONV | 121 | CFLAGS += -DNO_ICONV |
122 | endif | 122 | endif |
123 | ifdef NO_STRCASESTR | 123 | ifdef NO_STRCASESTR |
124 | CFLAGS += -DNO_STRCASESTR | 124 | CFLAGS += -DNO_STRCASESTR |
125 | endif | 125 | endif |
126 | 126 | ||
127 | cgit: $(OBJECTS) libgit | 127 | cgit: $(OBJECTS) libgit |
128 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) | 128 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) |
129 | 129 | ||
130 | cgit.o: VERSION | 130 | cgit.o: VERSION |
131 | 131 | ||
132 | -include $(OBJECTS:.o=.d) | 132 | -include $(OBJECTS:.o=.d) |
133 | 133 | ||
134 | libgit: | 134 | libgit: |
135 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a | 135 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a |
136 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a | 136 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a |
137 | 137 | ||
138 | test: all | 138 | test: all |
139 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all | 139 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
140 | 140 | ||
141 | install: all | 141 | install: all |
142 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) | 142 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) |
143 | $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 143 | $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
144 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) | 144 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) |
145 | $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css | 145 | $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css |
146 | $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png | 146 | $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png |
147 | 147 | ||
148 | uninstall: | 148 | uninstall: |
149 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 149 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
150 | rm -f $(CGIT_DATA_PATH)/cgit.css | 150 | rm -f $(CGIT_DATA_PATH)/cgit.css |
151 | rm -f $(CGIT_DATA_PATH)/cgit.png | 151 | rm -f $(CGIT_DATA_PATH)/cgit.png |
152 | 152 | ||
153 | doc: man-doc html-doc pdf-doc | 153 | doc: man-doc html-doc pdf-doc |
154 | 154 | ||
155 | man-doc: cgitrc.5.txt | 155 | man-doc: cgitrc.5.txt |
156 | a2x -f manpage cgitrc.5.txt | 156 | a2x -f manpage cgitrc.5.txt |
157 | 157 | ||
158 | html-doc: cgitrc.5.txt | 158 | html-doc: cgitrc.5.txt |
159 | a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt | 159 | a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt |
160 | 160 | ||
161 | pdf-doc: cgitrc.5.txt | 161 | pdf-doc: cgitrc.5.txt |
162 | a2x -f pdf cgitrc.5.txt | 162 | a2x -f pdf cgitrc.5.txt |
163 | 163 | ||
164 | clean: clean-doc | 164 | clean: clean-doc |
165 | rm -f cgit VERSION *.o *.d | 165 | rm -f cgit VERSION *.o *.d |
166 | 166 | ||
167 | clean-doc: | 167 | clean-doc: |
168 | rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo | 168 | rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo |
169 | 169 | ||
170 | get-git: | 170 | get-git: |
171 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git | 171 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git |
@@ -1,408 +1,408 @@ | |||
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 | * | 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 "cache.h" | 10 | #include "cache.h" |
11 | #include "cmd.h" | 11 | #include "cmd.h" |
12 | #include "configfile.h" | 12 | #include "configfile.h" |
13 | #include "html.h" | 13 | #include "html.h" |
14 | #include "ui-shared.h" | 14 | #include "ui-shared.h" |
15 | #include "ui-stats.h" | 15 | #include "ui-stats.h" |
16 | #include "scan-tree.h" | 16 | #include "scan-tree.h" |
17 | 17 | ||
18 | const char *cgit_version = CGIT_VERSION; | 18 | const char *cgit_version = CGIT_VERSION; |
19 | 19 | ||
20 | void add_mimetype(const char *name, const char *value) | 20 | void add_mimetype(const char *name, const char *value) |
21 | { | 21 | { |
22 | struct string_list_item *item; | 22 | struct string_list_item *item; |
23 | 23 | ||
24 | item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); | 24 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); |
25 | item->util = xstrdup(value); | 25 | item->util = xstrdup(value); |
26 | } | 26 | } |
27 | 27 | ||
28 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 28 | struct cgit_filter *new_filter(const char *cmd, int extra_args) |
29 | { | 29 | { |
30 | struct cgit_filter *f; | 30 | struct cgit_filter *f; |
31 | 31 | ||
32 | if (!cmd || !cmd[0]) | 32 | if (!cmd || !cmd[0]) |
33 | return NULL; | 33 | return NULL; |
34 | 34 | ||
35 | f = xmalloc(sizeof(struct cgit_filter)); | 35 | f = xmalloc(sizeof(struct cgit_filter)); |
36 | f->cmd = xstrdup(cmd); | 36 | f->cmd = xstrdup(cmd); |
37 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); | 37 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); |
38 | f->argv[0] = f->cmd; | 38 | f->argv[0] = f->cmd; |
39 | f->argv[1] = NULL; | 39 | f->argv[1] = NULL; |
40 | return f; | 40 | return f; |
41 | } | 41 | } |
42 | 42 | ||
43 | static void process_cached_repolist(const char *path); | 43 | static void process_cached_repolist(const char *path); |
44 | 44 | ||
45 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) | 45 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) |
46 | { | 46 | { |
47 | if (!strcmp(name, "name")) | 47 | if (!strcmp(name, "name")) |
48 | repo->name = xstrdup(value); | 48 | repo->name = xstrdup(value); |
49 | else if (!strcmp(name, "clone-url")) | 49 | else if (!strcmp(name, "clone-url")) |
50 | repo->clone_url = xstrdup(value); | 50 | repo->clone_url = xstrdup(value); |
51 | else if (!strcmp(name, "desc")) | 51 | else if (!strcmp(name, "desc")) |
52 | repo->desc = xstrdup(value); | 52 | repo->desc = xstrdup(value); |
53 | else if (!strcmp(name, "owner")) | 53 | else if (!strcmp(name, "owner")) |
54 | repo->owner = xstrdup(value); | 54 | repo->owner = xstrdup(value); |
55 | else if (!strcmp(name, "defbranch")) | 55 | else if (!strcmp(name, "defbranch")) |
56 | repo->defbranch = xstrdup(value); | 56 | repo->defbranch = xstrdup(value); |
57 | else if (!strcmp(name, "snapshots")) | 57 | else if (!strcmp(name, "snapshots")) |
58 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); | 58 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); |
59 | else if (!strcmp(name, "enable-log-filecount")) | 59 | else if (!strcmp(name, "enable-log-filecount")) |
60 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 60 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
61 | else if (!strcmp(name, "enable-log-linecount")) | 61 | else if (!strcmp(name, "enable-log-linecount")) |
62 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 62 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
63 | else if (!strcmp(name, "max-stats")) | 63 | else if (!strcmp(name, "max-stats")) |
64 | repo->max_stats = cgit_find_stats_period(value, NULL); | 64 | repo->max_stats = cgit_find_stats_period(value, NULL); |
65 | else if (!strcmp(name, "module-link")) | 65 | else if (!strcmp(name, "module-link")) |
66 | repo->module_link= xstrdup(value); | 66 | repo->module_link= xstrdup(value); |
67 | else if (!strcmp(name, "section")) | 67 | else if (!strcmp(name, "section")) |
68 | repo->section = xstrdup(value); | 68 | repo->section = xstrdup(value); |
69 | else if (!strcmp(name, "readme") && value != NULL) { | 69 | else if (!strcmp(name, "readme") && value != NULL) { |
70 | if (*value == '/') | 70 | if (*value == '/') |
71 | repo->readme = xstrdup(value); | 71 | repo->readme = xstrdup(value); |
72 | else | 72 | else |
73 | repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); | 73 | repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); |
74 | } else if (ctx.cfg.enable_filter_overrides) { | 74 | } else if (ctx.cfg.enable_filter_overrides) { |
75 | if (!strcmp(name, "about-filter")) | 75 | if (!strcmp(name, "about-filter")) |
76 | repo->about_filter = new_filter(value, 0); | 76 | repo->about_filter = new_filter(value, 0); |
77 | else if (!strcmp(name, "commit-filter")) | 77 | else if (!strcmp(name, "commit-filter")) |
78 | repo->commit_filter = new_filter(value, 0); | 78 | repo->commit_filter = new_filter(value, 0); |
79 | else if (!strcmp(name, "source-filter")) | 79 | else if (!strcmp(name, "source-filter")) |
80 | repo->source_filter = new_filter(value, 1); | 80 | repo->source_filter = new_filter(value, 1); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | void config_cb(const char *name, const char *value) | 84 | void config_cb(const char *name, const char *value) |
85 | { | 85 | { |
86 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) | 86 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) |
87 | ctx.cfg.section = xstrdup(value); | 87 | ctx.cfg.section = xstrdup(value); |
88 | else if (!strcmp(name, "repo.url")) | 88 | else if (!strcmp(name, "repo.url")) |
89 | ctx.repo = cgit_add_repo(value); | 89 | ctx.repo = cgit_add_repo(value); |
90 | else if (ctx.repo && !strcmp(name, "repo.path")) | 90 | else if (ctx.repo && !strcmp(name, "repo.path")) |
91 | ctx.repo->path = trim_end(value, '/'); | 91 | ctx.repo->path = trim_end(value, '/'); |
92 | else if (ctx.repo && !prefixcmp(name, "repo.")) | 92 | else if (ctx.repo && !prefixcmp(name, "repo.")) |
93 | repo_config(ctx.repo, name + 5, value); | 93 | repo_config(ctx.repo, name + 5, value); |
94 | else if (!strcmp(name, "root-title")) | 94 | else if (!strcmp(name, "root-title")) |
95 | ctx.cfg.root_title = xstrdup(value); | 95 | ctx.cfg.root_title = xstrdup(value); |
96 | else if (!strcmp(name, "root-desc")) | 96 | else if (!strcmp(name, "root-desc")) |
97 | ctx.cfg.root_desc = xstrdup(value); | 97 | ctx.cfg.root_desc = xstrdup(value); |
98 | else if (!strcmp(name, "root-readme")) | 98 | else if (!strcmp(name, "root-readme")) |
99 | ctx.cfg.root_readme = xstrdup(value); | 99 | ctx.cfg.root_readme = xstrdup(value); |
100 | else if (!strcmp(name, "css")) | 100 | else if (!strcmp(name, "css")) |
101 | ctx.cfg.css = xstrdup(value); | 101 | ctx.cfg.css = xstrdup(value); |
102 | else if (!strcmp(name, "favicon")) | 102 | else if (!strcmp(name, "favicon")) |
103 | ctx.cfg.favicon = xstrdup(value); | 103 | ctx.cfg.favicon = xstrdup(value); |
104 | else if (!strcmp(name, "footer")) | 104 | else if (!strcmp(name, "footer")) |
105 | ctx.cfg.footer = xstrdup(value); | 105 | ctx.cfg.footer = xstrdup(value); |
106 | else if (!strcmp(name, "head-include")) | 106 | else if (!strcmp(name, "head-include")) |
107 | ctx.cfg.head_include = xstrdup(value); | 107 | ctx.cfg.head_include = xstrdup(value); |
108 | else if (!strcmp(name, "header")) | 108 | else if (!strcmp(name, "header")) |
109 | ctx.cfg.header = xstrdup(value); | 109 | ctx.cfg.header = xstrdup(value); |
110 | else if (!strcmp(name, "logo")) | 110 | else if (!strcmp(name, "logo")) |
111 | ctx.cfg.logo = xstrdup(value); | 111 | ctx.cfg.logo = xstrdup(value); |
112 | else if (!strcmp(name, "index-header")) | 112 | else if (!strcmp(name, "index-header")) |
113 | ctx.cfg.index_header = xstrdup(value); | 113 | ctx.cfg.index_header = xstrdup(value); |
114 | else if (!strcmp(name, "index-info")) | 114 | else if (!strcmp(name, "index-info")) |
115 | ctx.cfg.index_info = xstrdup(value); | 115 | ctx.cfg.index_info = xstrdup(value); |
116 | else if (!strcmp(name, "logo-link")) | 116 | else if (!strcmp(name, "logo-link")) |
117 | ctx.cfg.logo_link = xstrdup(value); | 117 | ctx.cfg.logo_link = xstrdup(value); |
118 | else if (!strcmp(name, "module-link")) | 118 | else if (!strcmp(name, "module-link")) |
119 | ctx.cfg.module_link = xstrdup(value); | 119 | ctx.cfg.module_link = xstrdup(value); |
120 | else if (!strcmp(name, "virtual-root")) { | 120 | else if (!strcmp(name, "virtual-root")) { |
121 | ctx.cfg.virtual_root = trim_end(value, '/'); | 121 | ctx.cfg.virtual_root = trim_end(value, '/'); |
122 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | 122 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
123 | ctx.cfg.virtual_root = ""; | 123 | ctx.cfg.virtual_root = ""; |
124 | } else if (!strcmp(name, "nocache")) | 124 | } else if (!strcmp(name, "nocache")) |
125 | ctx.cfg.nocache = atoi(value); | 125 | ctx.cfg.nocache = atoi(value); |
126 | else if (!strcmp(name, "noplainemail")) | 126 | else if (!strcmp(name, "noplainemail")) |
127 | ctx.cfg.noplainemail = atoi(value); | 127 | ctx.cfg.noplainemail = atoi(value); |
128 | else if (!strcmp(name, "noheader")) | 128 | else if (!strcmp(name, "noheader")) |
129 | ctx.cfg.noheader = atoi(value); | 129 | ctx.cfg.noheader = atoi(value); |
130 | else if (!strcmp(name, "snapshots")) | 130 | else if (!strcmp(name, "snapshots")) |
131 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | 131 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
132 | else if (!strcmp(name, "enable-filter-overrides")) | 132 | else if (!strcmp(name, "enable-filter-overrides")) |
133 | ctx.cfg.enable_filter_overrides = atoi(value); | 133 | ctx.cfg.enable_filter_overrides = atoi(value); |
134 | else if (!strcmp(name, "enable-index-links")) | 134 | else if (!strcmp(name, "enable-index-links")) |
135 | ctx.cfg.enable_index_links = atoi(value); | 135 | ctx.cfg.enable_index_links = atoi(value); |
136 | else if (!strcmp(name, "enable-log-filecount")) | 136 | else if (!strcmp(name, "enable-log-filecount")) |
137 | ctx.cfg.enable_log_filecount = atoi(value); | 137 | ctx.cfg.enable_log_filecount = atoi(value); |
138 | else if (!strcmp(name, "enable-log-linecount")) | 138 | else if (!strcmp(name, "enable-log-linecount")) |
139 | ctx.cfg.enable_log_linecount = atoi(value); | 139 | ctx.cfg.enable_log_linecount = atoi(value); |
140 | else if (!strcmp(name, "enable-tree-linenumbers")) | 140 | else if (!strcmp(name, "enable-tree-linenumbers")) |
141 | ctx.cfg.enable_tree_linenumbers = atoi(value); | 141 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
142 | else if (!strcmp(name, "max-stats")) | 142 | else if (!strcmp(name, "max-stats")) |
143 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); | 143 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
144 | else if (!strcmp(name, "cache-size")) | 144 | else if (!strcmp(name, "cache-size")) |
145 | ctx.cfg.cache_size = atoi(value); | 145 | ctx.cfg.cache_size = atoi(value); |
146 | else if (!strcmp(name, "cache-root")) | 146 | else if (!strcmp(name, "cache-root")) |
147 | ctx.cfg.cache_root = xstrdup(value); | 147 | ctx.cfg.cache_root = xstrdup(value); |
148 | else if (!strcmp(name, "cache-root-ttl")) | 148 | else if (!strcmp(name, "cache-root-ttl")) |
149 | ctx.cfg.cache_root_ttl = atoi(value); | 149 | ctx.cfg.cache_root_ttl = atoi(value); |
150 | else if (!strcmp(name, "cache-repo-ttl")) | 150 | else if (!strcmp(name, "cache-repo-ttl")) |
151 | ctx.cfg.cache_repo_ttl = atoi(value); | 151 | ctx.cfg.cache_repo_ttl = atoi(value); |
152 | else if (!strcmp(name, "cache-scanrc-ttl")) | 152 | else if (!strcmp(name, "cache-scanrc-ttl")) |
153 | ctx.cfg.cache_scanrc_ttl = atoi(value); | 153 | ctx.cfg.cache_scanrc_ttl = atoi(value); |
154 | else if (!strcmp(name, "cache-static-ttl")) | 154 | else if (!strcmp(name, "cache-static-ttl")) |
155 | ctx.cfg.cache_static_ttl = atoi(value); | 155 | ctx.cfg.cache_static_ttl = atoi(value); |
156 | else if (!strcmp(name, "cache-dynamic-ttl")) | 156 | else if (!strcmp(name, "cache-dynamic-ttl")) |
157 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 157 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
158 | else if (!strcmp(name, "about-filter")) | 158 | else if (!strcmp(name, "about-filter")) |
159 | ctx.cfg.about_filter = new_filter(value, 0); | 159 | ctx.cfg.about_filter = new_filter(value, 0); |
160 | else if (!strcmp(name, "commit-filter")) | 160 | else if (!strcmp(name, "commit-filter")) |
161 | ctx.cfg.commit_filter = new_filter(value, 0); | 161 | ctx.cfg.commit_filter = new_filter(value, 0); |
162 | else if (!strcmp(name, "embedded")) | 162 | else if (!strcmp(name, "embedded")) |
163 | ctx.cfg.embedded = atoi(value); | 163 | ctx.cfg.embedded = atoi(value); |
164 | else if (!strcmp(name, "max-message-length")) | 164 | else if (!strcmp(name, "max-message-length")) |
165 | ctx.cfg.max_msg_len = atoi(value); | 165 | ctx.cfg.max_msg_len = atoi(value); |
166 | else if (!strcmp(name, "max-repodesc-length")) | 166 | else if (!strcmp(name, "max-repodesc-length")) |
167 | ctx.cfg.max_repodesc_len = atoi(value); | 167 | ctx.cfg.max_repodesc_len = atoi(value); |
168 | else if (!strcmp(name, "max-repo-count")) | 168 | else if (!strcmp(name, "max-repo-count")) |
169 | ctx.cfg.max_repo_count = atoi(value); | 169 | ctx.cfg.max_repo_count = atoi(value); |
170 | else if (!strcmp(name, "max-commit-count")) | 170 | else if (!strcmp(name, "max-commit-count")) |
171 | ctx.cfg.max_commit_count = atoi(value); | 171 | ctx.cfg.max_commit_count = atoi(value); |
172 | else if (!strcmp(name, "scan-path")) | 172 | else if (!strcmp(name, "scan-path")) |
173 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) | 173 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
174 | process_cached_repolist(value); | 174 | process_cached_repolist(value); |
175 | else | 175 | else |
176 | scan_tree(value, repo_config); | 176 | scan_tree(value, repo_config); |
177 | else if (!strcmp(name, "source-filter")) | 177 | else if (!strcmp(name, "source-filter")) |
178 | ctx.cfg.source_filter = new_filter(value, 1); | 178 | ctx.cfg.source_filter = new_filter(value, 1); |
179 | else if (!strcmp(name, "summary-log")) | 179 | else if (!strcmp(name, "summary-log")) |
180 | ctx.cfg.summary_log = atoi(value); | 180 | ctx.cfg.summary_log = atoi(value); |
181 | else if (!strcmp(name, "summary-branches")) | 181 | else if (!strcmp(name, "summary-branches")) |
182 | ctx.cfg.summary_branches = atoi(value); | 182 | ctx.cfg.summary_branches = atoi(value); |
183 | else if (!strcmp(name, "summary-tags")) | 183 | else if (!strcmp(name, "summary-tags")) |
184 | ctx.cfg.summary_tags = atoi(value); | 184 | ctx.cfg.summary_tags = atoi(value); |
185 | else if (!strcmp(name, "agefile")) | 185 | else if (!strcmp(name, "agefile")) |
186 | ctx.cfg.agefile = xstrdup(value); | 186 | ctx.cfg.agefile = xstrdup(value); |
187 | else if (!strcmp(name, "renamelimit")) | 187 | else if (!strcmp(name, "renamelimit")) |
188 | ctx.cfg.renamelimit = atoi(value); | 188 | ctx.cfg.renamelimit = atoi(value); |
189 | else if (!strcmp(name, "robots")) | 189 | else if (!strcmp(name, "robots")) |
190 | ctx.cfg.robots = xstrdup(value); | 190 | ctx.cfg.robots = xstrdup(value); |
191 | else if (!strcmp(name, "clone-prefix")) | 191 | else if (!strcmp(name, "clone-prefix")) |
192 | ctx.cfg.clone_prefix = xstrdup(value); | 192 | ctx.cfg.clone_prefix = xstrdup(value); |
193 | else if (!strcmp(name, "local-time")) | 193 | else if (!strcmp(name, "local-time")) |
194 | ctx.cfg.local_time = atoi(value); | 194 | ctx.cfg.local_time = atoi(value); |
195 | else if (!prefixcmp(name, "mimetype.")) | 195 | else if (!prefixcmp(name, "mimetype.")) |
196 | add_mimetype(name + 9, value); | 196 | add_mimetype(name + 9, value); |
197 | else if (!strcmp(name, "include")) | 197 | else if (!strcmp(name, "include")) |
198 | parse_configfile(value, config_cb); | 198 | parse_configfile(value, config_cb); |
199 | } | 199 | } |
200 | 200 | ||
201 | static void querystring_cb(const char *name, const char *value) | 201 | static void querystring_cb(const char *name, const char *value) |
202 | { | 202 | { |
203 | if (!value) | 203 | if (!value) |
204 | value = ""; | 204 | value = ""; |
205 | 205 | ||
206 | if (!strcmp(name,"r")) { | 206 | if (!strcmp(name,"r")) { |
207 | ctx.qry.repo = xstrdup(value); | 207 | ctx.qry.repo = xstrdup(value); |
208 | ctx.repo = cgit_get_repoinfo(value); | 208 | ctx.repo = cgit_get_repoinfo(value); |
209 | } else if (!strcmp(name, "p")) { | 209 | } else if (!strcmp(name, "p")) { |
210 | ctx.qry.page = xstrdup(value); | 210 | ctx.qry.page = xstrdup(value); |
211 | } else if (!strcmp(name, "url")) { | 211 | } else if (!strcmp(name, "url")) { |
212 | ctx.qry.url = xstrdup(value); | 212 | ctx.qry.url = xstrdup(value); |
213 | cgit_parse_url(value); | 213 | cgit_parse_url(value); |
214 | } else if (!strcmp(name, "qt")) { | 214 | } else if (!strcmp(name, "qt")) { |
215 | ctx.qry.grep = xstrdup(value); | 215 | ctx.qry.grep = xstrdup(value); |
216 | } else if (!strcmp(name, "q")) { | 216 | } else if (!strcmp(name, "q")) { |
217 | ctx.qry.search = xstrdup(value); | 217 | ctx.qry.search = xstrdup(value); |
218 | } else if (!strcmp(name, "h")) { | 218 | } else if (!strcmp(name, "h")) { |
219 | ctx.qry.head = xstrdup(value); | 219 | ctx.qry.head = xstrdup(value); |
220 | ctx.qry.has_symref = 1; | 220 | ctx.qry.has_symref = 1; |
221 | } else if (!strcmp(name, "id")) { | 221 | } else if (!strcmp(name, "id")) { |
222 | ctx.qry.sha1 = xstrdup(value); | 222 | ctx.qry.sha1 = xstrdup(value); |
223 | ctx.qry.has_sha1 = 1; | 223 | ctx.qry.has_sha1 = 1; |
224 | } else if (!strcmp(name, "id2")) { | 224 | } else if (!strcmp(name, "id2")) { |
225 | ctx.qry.sha2 = xstrdup(value); | 225 | ctx.qry.sha2 = xstrdup(value); |
226 | ctx.qry.has_sha1 = 1; | 226 | ctx.qry.has_sha1 = 1; |
227 | } else if (!strcmp(name, "ofs")) { | 227 | } else if (!strcmp(name, "ofs")) { |
228 | ctx.qry.ofs = atoi(value); | 228 | ctx.qry.ofs = atoi(value); |
229 | } else if (!strcmp(name, "path")) { | 229 | } else if (!strcmp(name, "path")) { |
230 | ctx.qry.path = trim_end(value, '/'); | 230 | ctx.qry.path = trim_end(value, '/'); |
231 | } else if (!strcmp(name, "name")) { | 231 | } else if (!strcmp(name, "name")) { |
232 | ctx.qry.name = xstrdup(value); | 232 | ctx.qry.name = xstrdup(value); |
233 | } else if (!strcmp(name, "mimetype")) { | 233 | } else if (!strcmp(name, "mimetype")) { |
234 | ctx.qry.mimetype = xstrdup(value); | 234 | ctx.qry.mimetype = xstrdup(value); |
235 | } else if (!strcmp(name, "s")){ | 235 | } else if (!strcmp(name, "s")){ |
236 | ctx.qry.sort = xstrdup(value); | 236 | ctx.qry.sort = xstrdup(value); |
237 | } else if (!strcmp(name, "showmsg")) { | 237 | } else if (!strcmp(name, "showmsg")) { |
238 | ctx.qry.showmsg = atoi(value); | 238 | ctx.qry.showmsg = atoi(value); |
239 | } else if (!strcmp(name, "period")) { | 239 | } else if (!strcmp(name, "period")) { |
240 | ctx.qry.period = xstrdup(value); | 240 | ctx.qry.period = xstrdup(value); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | char *xstrdupn(const char *str) | 244 | char *xstrdupn(const char *str) |
245 | { | 245 | { |
246 | return (str ? xstrdup(str) : NULL); | 246 | return (str ? xstrdup(str) : NULL); |
247 | } | 247 | } |
248 | 248 | ||
249 | static void prepare_context(struct cgit_context *ctx) | 249 | static void prepare_context(struct cgit_context *ctx) |
250 | { | 250 | { |
251 | memset(ctx, 0, sizeof(*ctx)); | 251 | memset(ctx, 0, sizeof(*ctx)); |
252 | ctx->cfg.agefile = "info/web/last-modified"; | 252 | ctx->cfg.agefile = "info/web/last-modified"; |
253 | ctx->cfg.nocache = 0; | 253 | ctx->cfg.nocache = 0; |
254 | ctx->cfg.cache_size = 0; | 254 | ctx->cfg.cache_size = 0; |
255 | ctx->cfg.cache_dynamic_ttl = 5; | 255 | ctx->cfg.cache_dynamic_ttl = 5; |
256 | ctx->cfg.cache_max_create_time = 5; | 256 | ctx->cfg.cache_max_create_time = 5; |
257 | ctx->cfg.cache_repo_ttl = 5; | 257 | ctx->cfg.cache_repo_ttl = 5; |
258 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 258 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
259 | ctx->cfg.cache_root_ttl = 5; | 259 | ctx->cfg.cache_root_ttl = 5; |
260 | ctx->cfg.cache_scanrc_ttl = 15; | 260 | ctx->cfg.cache_scanrc_ttl = 15; |
261 | ctx->cfg.cache_static_ttl = -1; | 261 | ctx->cfg.cache_static_ttl = -1; |
262 | ctx->cfg.css = "/cgit.css"; | 262 | ctx->cfg.css = "/cgit.css"; |
263 | ctx->cfg.logo = "/cgit.png"; | 263 | ctx->cfg.logo = "/cgit.png"; |
264 | ctx->cfg.local_time = 0; | 264 | ctx->cfg.local_time = 0; |
265 | ctx->cfg.enable_tree_linenumbers = 1; | 265 | ctx->cfg.enable_tree_linenumbers = 1; |
266 | ctx->cfg.max_repo_count = 50; | 266 | ctx->cfg.max_repo_count = 50; |
267 | ctx->cfg.max_commit_count = 50; | 267 | ctx->cfg.max_commit_count = 50; |
268 | ctx->cfg.max_lock_attempts = 5; | 268 | ctx->cfg.max_lock_attempts = 5; |
269 | ctx->cfg.max_msg_len = 80; | 269 | ctx->cfg.max_msg_len = 80; |
270 | ctx->cfg.max_repodesc_len = 80; | 270 | ctx->cfg.max_repodesc_len = 80; |
271 | ctx->cfg.max_stats = 0; | 271 | ctx->cfg.max_stats = 0; |
272 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 272 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
273 | ctx->cfg.renamelimit = -1; | 273 | ctx->cfg.renamelimit = -1; |
274 | ctx->cfg.robots = "index, nofollow"; | 274 | ctx->cfg.robots = "index, nofollow"; |
275 | ctx->cfg.root_title = "Git repository browser"; | 275 | ctx->cfg.root_title = "Git repository browser"; |
276 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 276 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
277 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 277 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
278 | ctx->cfg.section = ""; | 278 | ctx->cfg.section = ""; |
279 | ctx->cfg.summary_branches = 10; | 279 | ctx->cfg.summary_branches = 10; |
280 | ctx->cfg.summary_log = 10; | 280 | ctx->cfg.summary_log = 10; |
281 | ctx->cfg.summary_tags = 10; | 281 | ctx->cfg.summary_tags = 10; |
282 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); | 282 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); |
283 | ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); | 283 | ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); |
284 | ctx->env.https = xstrdupn(getenv("HTTPS")); | 284 | ctx->env.https = xstrdupn(getenv("HTTPS")); |
285 | ctx->env.no_http = xstrdupn(getenv("NO_HTTP")); | 285 | ctx->env.no_http = xstrdupn(getenv("NO_HTTP")); |
286 | ctx->env.path_info = xstrdupn(getenv("PATH_INFO")); | 286 | ctx->env.path_info = xstrdupn(getenv("PATH_INFO")); |
287 | ctx->env.query_string = xstrdupn(getenv("QUERY_STRING")); | 287 | ctx->env.query_string = xstrdupn(getenv("QUERY_STRING")); |
288 | ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD")); | 288 | ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD")); |
289 | ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME")); | 289 | ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME")); |
290 | ctx->env.server_name = xstrdupn(getenv("SERVER_NAME")); | 290 | ctx->env.server_name = xstrdupn(getenv("SERVER_NAME")); |
291 | ctx->env.server_port = xstrdupn(getenv("SERVER_PORT")); | 291 | ctx->env.server_port = xstrdupn(getenv("SERVER_PORT")); |
292 | ctx->page.mimetype = "text/html"; | 292 | ctx->page.mimetype = "text/html"; |
293 | ctx->page.charset = PAGE_ENCODING; | 293 | ctx->page.charset = PAGE_ENCODING; |
294 | ctx->page.filename = NULL; | 294 | ctx->page.filename = NULL; |
295 | ctx->page.size = 0; | 295 | ctx->page.size = 0; |
296 | ctx->page.modified = time(NULL); | 296 | ctx->page.modified = time(NULL); |
297 | ctx->page.expires = ctx->page.modified; | 297 | ctx->page.expires = ctx->page.modified; |
298 | ctx->page.etag = NULL; | 298 | ctx->page.etag = NULL; |
299 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | 299 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); |
300 | if (ctx->env.script_name) | 300 | if (ctx->env.script_name) |
301 | ctx->cfg.script_name = ctx->env.script_name; | 301 | ctx->cfg.script_name = ctx->env.script_name; |
302 | if (ctx->env.query_string) | 302 | if (ctx->env.query_string) |
303 | ctx->qry.raw = ctx->env.query_string; | 303 | ctx->qry.raw = ctx->env.query_string; |
304 | if (!ctx->env.cgit_config) | 304 | if (!ctx->env.cgit_config) |
305 | ctx->env.cgit_config = CGIT_CONFIG; | 305 | ctx->env.cgit_config = CGIT_CONFIG; |
306 | } | 306 | } |
307 | 307 | ||
308 | struct refmatch { | 308 | struct refmatch { |
309 | char *req_ref; | 309 | char *req_ref; |
310 | char *first_ref; | 310 | char *first_ref; |
311 | int match; | 311 | int match; |
312 | }; | 312 | }; |
313 | 313 | ||
314 | int find_current_ref(const char *refname, const unsigned char *sha1, | 314 | int find_current_ref(const char *refname, const unsigned char *sha1, |
315 | int flags, void *cb_data) | 315 | int flags, void *cb_data) |
316 | { | 316 | { |
317 | struct refmatch *info; | 317 | struct refmatch *info; |
318 | 318 | ||
319 | info = (struct refmatch *)cb_data; | 319 | info = (struct refmatch *)cb_data; |
320 | if (!strcmp(refname, info->req_ref)) | 320 | if (!strcmp(refname, info->req_ref)) |
321 | info->match = 1; | 321 | info->match = 1; |
322 | if (!info->first_ref) | 322 | if (!info->first_ref) |
323 | info->first_ref = xstrdup(refname); | 323 | info->first_ref = xstrdup(refname); |
324 | return info->match; | 324 | return info->match; |
325 | } | 325 | } |
326 | 326 | ||
327 | char *find_default_branch(struct cgit_repo *repo) | 327 | char *find_default_branch(struct cgit_repo *repo) |
328 | { | 328 | { |
329 | struct refmatch info; | 329 | struct refmatch info; |
330 | char *ref; | 330 | char *ref; |
331 | 331 | ||
332 | info.req_ref = repo->defbranch; | 332 | info.req_ref = repo->defbranch; |
333 | info.first_ref = NULL; | 333 | info.first_ref = NULL; |
334 | info.match = 0; | 334 | info.match = 0; |
335 | for_each_branch_ref(find_current_ref, &info); | 335 | for_each_branch_ref(find_current_ref, &info); |
336 | if (info.match) | 336 | if (info.match) |
337 | ref = info.req_ref; | 337 | ref = info.req_ref; |
338 | else | 338 | else |
339 | ref = info.first_ref; | 339 | ref = info.first_ref; |
340 | if (ref) | 340 | if (ref) |
341 | ref = xstrdup(ref); | 341 | ref = xstrdup(ref); |
342 | return ref; | 342 | return ref; |
343 | } | 343 | } |
344 | 344 | ||
345 | static int prepare_repo_cmd(struct cgit_context *ctx) | 345 | static int prepare_repo_cmd(struct cgit_context *ctx) |
346 | { | 346 | { |
347 | char *tmp; | 347 | char *tmp; |
348 | unsigned char sha1[20]; | 348 | unsigned char sha1[20]; |
349 | int nongit = 0; | 349 | int nongit = 0; |
350 | 350 | ||
351 | setenv("GIT_DIR", ctx->repo->path, 1); | 351 | setenv("GIT_DIR", ctx->repo->path, 1); |
352 | setup_git_directory_gently(&nongit); | 352 | setup_git_directory_gently(&nongit); |
353 | if (nongit) { | 353 | if (nongit) { |
354 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, | 354 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
355 | "config error"); | 355 | "config error"); |
356 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); | 356 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); |
357 | ctx->repo = NULL; | 357 | ctx->repo = NULL; |
358 | cgit_print_http_headers(ctx); | 358 | cgit_print_http_headers(ctx); |
359 | cgit_print_docstart(ctx); | 359 | cgit_print_docstart(ctx); |
360 | cgit_print_pageheader(ctx); | 360 | cgit_print_pageheader(ctx); |
361 | cgit_print_error(tmp); | 361 | cgit_print_error(tmp); |
362 | cgit_print_docend(); | 362 | cgit_print_docend(); |
363 | return 1; | 363 | return 1; |
364 | } | 364 | } |
365 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 365 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
366 | 366 | ||
367 | if (!ctx->qry.head) { | 367 | if (!ctx->qry.head) { |
368 | ctx->qry.nohead = 1; | 368 | ctx->qry.nohead = 1; |
369 | ctx->qry.head = find_default_branch(ctx->repo); | 369 | ctx->qry.head = find_default_branch(ctx->repo); |
370 | ctx->repo->defbranch = ctx->qry.head; | 370 | ctx->repo->defbranch = ctx->qry.head; |
371 | } | 371 | } |
372 | 372 | ||
373 | if (!ctx->qry.head) { | 373 | if (!ctx->qry.head) { |
374 | cgit_print_http_headers(ctx); | 374 | cgit_print_http_headers(ctx); |
375 | cgit_print_docstart(ctx); | 375 | cgit_print_docstart(ctx); |
376 | cgit_print_pageheader(ctx); | 376 | cgit_print_pageheader(ctx); |
377 | cgit_print_error("Repository seems to be empty"); | 377 | cgit_print_error("Repository seems to be empty"); |
378 | cgit_print_docend(); | 378 | cgit_print_docend(); |
379 | return 1; | 379 | return 1; |
380 | } | 380 | } |
381 | 381 | ||
382 | if (get_sha1(ctx->qry.head, sha1)) { | 382 | if (get_sha1(ctx->qry.head, sha1)) { |
383 | tmp = xstrdup(ctx->qry.head); | 383 | tmp = xstrdup(ctx->qry.head); |
384 | ctx->qry.head = ctx->repo->defbranch; | 384 | ctx->qry.head = ctx->repo->defbranch; |
385 | ctx->page.status = 404; | 385 | ctx->page.status = 404; |
386 | ctx->page.statusmsg = "not found"; | 386 | ctx->page.statusmsg = "not found"; |
387 | cgit_print_http_headers(ctx); | 387 | cgit_print_http_headers(ctx); |
388 | cgit_print_docstart(ctx); | 388 | cgit_print_docstart(ctx); |
389 | cgit_print_pageheader(ctx); | 389 | cgit_print_pageheader(ctx); |
390 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 390 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
391 | cgit_print_docend(); | 391 | cgit_print_docend(); |
392 | return 1; | 392 | return 1; |
393 | } | 393 | } |
394 | return 0; | 394 | return 0; |
395 | } | 395 | } |
396 | 396 | ||
397 | static void process_request(void *cbdata) | 397 | static void process_request(void *cbdata) |
398 | { | 398 | { |
399 | struct cgit_context *ctx = cbdata; | 399 | struct cgit_context *ctx = cbdata; |
400 | struct cgit_cmd *cmd; | 400 | struct cgit_cmd *cmd; |
401 | 401 | ||
402 | cmd = cgit_get_cmd(ctx); | 402 | cmd = cgit_get_cmd(ctx); |
403 | if (!cmd) { | 403 | if (!cmd) { |
404 | ctx->page.title = "cgit error"; | 404 | ctx->page.title = "cgit error"; |
405 | cgit_print_http_headers(ctx); | 405 | cgit_print_http_headers(ctx); |
406 | cgit_print_docstart(ctx); | 406 | cgit_print_docstart(ctx); |
407 | cgit_print_pageheader(ctx); | 407 | cgit_print_pageheader(ctx); |
408 | cgit_print_error("Invalid request"); | 408 | cgit_print_error("Invalid request"); |
diff --git a/git b/git | |||
Subproject 7fb6bcff2dece2ff9fbc5ebfe526d9b2a7e764c | Subproject 87b50542a08ac6caa083ddc376e674424e37940 | ||
@@ -1,94 +1,94 @@ | |||
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 | ||
13 | char *curr_rev; | 13 | char *curr_rev; |
14 | char *match_path; | 14 | char *match_path; |
15 | int match; | 15 | int match; |
16 | 16 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 17 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf, *ext; | 20 | char *buf, *ext; |
21 | unsigned long size; | 21 | unsigned long size; |
22 | struct string_list_item *mime; | 22 | struct string_list_item *mime; |
23 | 23 | ||
24 | type = sha1_object_info(sha1, &size); | 24 | type = sha1_object_info(sha1, &size); |
25 | if (type == OBJ_BAD) { | 25 | if (type == OBJ_BAD) { |
26 | html_status(404, "Not found", 0); | 26 | html_status(404, "Not found", 0); |
27 | return; | 27 | return; |
28 | } | 28 | } |
29 | 29 | ||
30 | buf = read_sha1_file(sha1, &type, &size); | 30 | buf = read_sha1_file(sha1, &type, &size); |
31 | if (!buf) { | 31 | if (!buf) { |
32 | html_status(404, "Not found", 0); | 32 | html_status(404, "Not found", 0); |
33 | return; | 33 | return; |
34 | } | 34 | } |
35 | ctx.page.mimetype = NULL; | 35 | ctx.page.mimetype = NULL; |
36 | ext = strrchr(path, '.'); | 36 | ext = strrchr(path, '.'); |
37 | if (ext && *(++ext)) { | 37 | if (ext && *(++ext)) { |
38 | mime = string_list_lookup(ext, &ctx.cfg.mimetypes); | 38 | mime = string_list_lookup(&ctx.cfg.mimetypes, ext); |
39 | if (mime) | 39 | if (mime) |
40 | ctx.page.mimetype = (char *)mime->util; | 40 | ctx.page.mimetype = (char *)mime->util; |
41 | } | 41 | } |
42 | if (!ctx.page.mimetype) { | 42 | if (!ctx.page.mimetype) { |
43 | if (buffer_is_binary(buf, size)) | 43 | if (buffer_is_binary(buf, size)) |
44 | ctx.page.mimetype = "application/octet-stream"; | 44 | ctx.page.mimetype = "application/octet-stream"; |
45 | else | 45 | else |
46 | ctx.page.mimetype = "text/plain"; | 46 | ctx.page.mimetype = "text/plain"; |
47 | } | 47 | } |
48 | ctx.page.filename = fmt("%s", path); | 48 | ctx.page.filename = fmt("%s", path); |
49 | ctx.page.size = size; | 49 | ctx.page.size = size; |
50 | ctx.page.etag = sha1_to_hex(sha1); | 50 | ctx.page.etag = sha1_to_hex(sha1); |
51 | cgit_print_http_headers(&ctx); | 51 | cgit_print_http_headers(&ctx); |
52 | html_raw(buf, size); | 52 | html_raw(buf, size); |
53 | match = 1; | 53 | match = 1; |
54 | } | 54 | } |
55 | 55 | ||
56 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 56 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
57 | const char *pathname, unsigned mode, int stage, | 57 | const char *pathname, unsigned mode, int stage, |
58 | void *cbdata) | 58 | void *cbdata) |
59 | { | 59 | { |
60 | if (S_ISDIR(mode)) | 60 | if (S_ISDIR(mode)) |
61 | return READ_TREE_RECURSIVE; | 61 | return READ_TREE_RECURSIVE; |
62 | 62 | ||
63 | if (S_ISREG(mode) && !strncmp(base, match_path, baselen) && | 63 | if (S_ISREG(mode) && !strncmp(base, match_path, baselen) && |
64 | !strcmp(pathname, match_path + baselen)) | 64 | !strcmp(pathname, match_path + baselen)) |
65 | print_object(sha1, pathname); | 65 | print_object(sha1, pathname); |
66 | 66 | ||
67 | return 0; | 67 | return 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | void cgit_print_plain(struct cgit_context *ctx) | 70 | void cgit_print_plain(struct cgit_context *ctx) |
71 | { | 71 | { |
72 | const char *rev = ctx->qry.sha1; | 72 | const char *rev = ctx->qry.sha1; |
73 | unsigned char sha1[20]; | 73 | unsigned char sha1[20]; |
74 | struct commit *commit; | 74 | struct commit *commit; |
75 | const char *paths[] = {ctx->qry.path, NULL}; | 75 | const char *paths[] = {ctx->qry.path, NULL}; |
76 | 76 | ||
77 | if (!rev) | 77 | if (!rev) |
78 | rev = ctx->qry.head; | 78 | rev = ctx->qry.head; |
79 | 79 | ||
80 | curr_rev = xstrdup(rev); | 80 | curr_rev = xstrdup(rev); |
81 | if (get_sha1(rev, sha1)) { | 81 | if (get_sha1(rev, sha1)) { |
82 | html_status(404, "Not found", 0); | 82 | html_status(404, "Not found", 0); |
83 | return; | 83 | return; |
84 | } | 84 | } |
85 | commit = lookup_commit_reference(sha1); | 85 | commit = lookup_commit_reference(sha1); |
86 | if (!commit || parse_commit(commit)) { | 86 | if (!commit || parse_commit(commit)) { |
87 | html_status(404, "Not found", 0); | 87 | html_status(404, "Not found", 0); |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | match_path = ctx->qry.path; | 90 | match_path = ctx->qry.path; |
91 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); | 91 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); |
92 | if (!match) | 92 | if (!match) |
93 | html_status(404, "Not found", 0); | 93 | html_status(404, "Not found", 0); |
94 | } | 94 | } |
@@ -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 | ||
10 | struct authorstat { | 10 | struct 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 | ||
18 | static void trunc_week(struct tm *tm) | 18 | static 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 | ||
25 | static void dec_week(struct tm *tm) | 25 | static 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 | ||
32 | static void inc_week(struct tm *tm) | 32 | static 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 | ||
39 | static char *pretty_week(struct tm *tm) | 39 | static 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 | ||
47 | static void trunc_month(struct tm *tm) | 47 | static void trunc_month(struct tm *tm) |
48 | { | 48 | { |
49 | tm->tm_mday = 1; | 49 | tm->tm_mday = 1; |
50 | } | 50 | } |
51 | 51 | ||
52 | static void dec_month(struct tm *tm) | 52 | static 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 | ||
61 | static void inc_month(struct tm *tm) | 61 | static 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 | ||
70 | static char *pretty_month(struct tm *tm) | 70 | static 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 | ||
79 | static void trunc_quarter(struct tm *tm) | 79 | static 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 | ||
86 | static void dec_quarter(struct tm *tm) | 86 | static 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 | ||
93 | static void inc_quarter(struct tm *tm) | 93 | static 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 | ||
100 | static char *pretty_quarter(struct tm *tm) | 100 | static 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 | ||
105 | static void trunc_year(struct tm *tm) | 105 | static 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 | ||
111 | static void dec_year(struct tm *tm) | 111 | static void dec_year(struct tm *tm) |
112 | { | 112 | { |
113 | tm->tm_year--; | 113 | tm->tm_year--; |
114 | } | 114 | } |
115 | 115 | ||
116 | static void inc_year(struct tm *tm) | 116 | static void inc_year(struct tm *tm) |
117 | { | 117 | { |
118 | tm->tm_year++; | 118 | tm->tm_year++; |
119 | } | 119 | } |
120 | 120 | ||
121 | static char *pretty_year(struct tm *tm) | 121 | static 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 | ||
126 | struct cgit_period periods[] = { | 126 | struct 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 | */ |
137 | int cgit_find_stats_period(const char *expr, struct cgit_period **period) | 137 | int 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 | ||
157 | const char *cgit_find_stats_periodname(int idx) | 157 | const 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 | ||
165 | static void add_commit(struct string_list *authors, struct commit *commit, | 165 | static 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 | ||
197 | static int cmp_total_commits(const void *a1, const void *a2) | 197 | static 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 | */ |
210 | struct string_list collect_stats(struct cgit_context *ctx, | 210 | struct 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 | ||
252 | void print_combined_authorrow(struct string_list *authors, int from, int to, | 252 | void 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 | ||
292 | void print_authors(struct string_list *authors, int top, | 292 | void 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 | */ |
358 | void cgit_show_stats(struct cgit_context *ctx) | 358 | void 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> <input type='submit' value='Reload'/></noscript>"); | 414 | html("<noscript> <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 | ||