author | Lars Hjemli <hjemli@gmail.com> | 2010-08-22 11:29:57 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-08-22 11:29:57 (UTC) |
commit | 6d7552bc072599313ef423d69156d824c075572a (patch) (unidiff) | |
tree | 3189efeb6ca80dc6dcf0811ff2d8011e2b3e8c7b | |
parent | 379e80e3a83481d3639c5d312eeddcce57c486b2 (diff) | |
download | cgit-6d7552bc072599313ef423d69156d824c075572a.zip cgit-6d7552bc072599313ef423d69156d824c075572a.tar.gz cgit-6d7552bc072599313ef423d69156d824c075572a.tar.bz2 |
Use GIT-1.7.2.2
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-commit.c | 2 | ||||
-rw-r--r-- | ui-log.c | 2 | ||||
-rw-r--r-- | ui-plain.c | 2 | ||||
-rw-r--r-- | ui-stats.c | 8 |
7 files changed, 10 insertions, 10 deletions
@@ -1,170 +1,170 @@ | |||
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.7.0 | 8 | GIT_VER = 1.7.2.2 |
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 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 | ||
26 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | 26 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
27 | uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') | 27 | uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') |
28 | uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') | 28 | uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') |
29 | 29 | ||
30 | ifeq ($(uname_O),Cygwin) | 30 | ifeq ($(uname_O),Cygwin) |
31 | NO_STRCASESTR = YesPlease | 31 | NO_STRCASESTR = YesPlease |
32 | NEEDS_LIBICONV = YesPlease | 32 | NEEDS_LIBICONV = YesPlease |
33 | endif | 33 | endif |
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 | # |
44 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | 44 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir |
45 | QUIET_SUBDIR1 = | 45 | QUIET_SUBDIR1 = |
46 | 46 | ||
47 | ifneq ($(findstring $(MAKEFLAGS),w),w) | 47 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
48 | PRINT_DIR = --no-print-directory | 48 | PRINT_DIR = --no-print-directory |
49 | else # "make -w" | 49 | else # "make -w" |
50 | NO_SUBDIR = : | 50 | NO_SUBDIR = : |
51 | endif | 51 | endif |
52 | 52 | ||
53 | ifndef V | 53 | ifndef 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 |
59 | endif | 59 | endif |
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 | ||
74 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz | 74 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread |
75 | OBJECTS = | 75 | OBJECTS = |
76 | OBJECTS += cache.o | 76 | OBJECTS += cache.o |
77 | OBJECTS += cgit.o | 77 | OBJECTS += cgit.o |
78 | OBJECTS += cmd.o | 78 | OBJECTS += cmd.o |
79 | OBJECTS += configfile.o | 79 | OBJECTS += configfile.o |
80 | OBJECTS += html.o | 80 | OBJECTS += html.o |
81 | OBJECTS += parsing.o | 81 | OBJECTS += parsing.o |
82 | OBJECTS += scan-tree.o | 82 | OBJECTS += scan-tree.o |
83 | OBJECTS += shared.o | 83 | OBJECTS += shared.o |
84 | OBJECTS += ui-atom.o | 84 | OBJECTS += ui-atom.o |
85 | OBJECTS += ui-blob.o | 85 | OBJECTS += ui-blob.o |
86 | OBJECTS += ui-clone.o | 86 | OBJECTS += ui-clone.o |
87 | OBJECTS += ui-commit.o | 87 | OBJECTS += ui-commit.o |
88 | OBJECTS += ui-diff.o | 88 | OBJECTS += ui-diff.o |
89 | OBJECTS += ui-log.o | 89 | OBJECTS += ui-log.o |
90 | OBJECTS += ui-patch.o | 90 | OBJECTS += ui-patch.o |
91 | OBJECTS += ui-plain.o | 91 | OBJECTS += ui-plain.o |
92 | OBJECTS += ui-refs.o | 92 | OBJECTS += ui-refs.o |
93 | OBJECTS += ui-repolist.o | 93 | OBJECTS += ui-repolist.o |
94 | OBJECTS += ui-shared.o | 94 | OBJECTS += ui-shared.o |
95 | OBJECTS += ui-snapshot.o | 95 | OBJECTS += ui-snapshot.o |
96 | OBJECTS += ui-ssdiff.o | 96 | OBJECTS += ui-ssdiff.o |
97 | OBJECTS += ui-stats.o | 97 | OBJECTS += ui-stats.o |
98 | OBJECTS += ui-summary.o | 98 | OBJECTS += ui-summary.o |
99 | OBJECTS += ui-tag.o | 99 | OBJECTS += ui-tag.o |
100 | OBJECTS += ui-tree.o | 100 | OBJECTS += ui-tree.o |
101 | 101 | ||
102 | ifdef NEEDS_LIBICONV | 102 | ifdef NEEDS_LIBICONV |
103 | EXTLIBS += -liconv | 103 | EXTLIBS += -liconv |
104 | endif | 104 | endif |
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 | ||
110 | all: cgit | 110 | all: cgit |
111 | 111 | ||
112 | VERSION: force-version | 112 | VERSION: force-version |
113 | @./gen-version.sh "$(CGIT_VERSION)" | 113 | @./gen-version.sh "$(CGIT_VERSION)" |
114 | -include VERSION | 114 | -include VERSION |
115 | 115 | ||
116 | 116 | ||
117 | CFLAGS += -g -Wall -Igit | 117 | CFLAGS += -g -Wall -Igit |
118 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 118 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
119 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 119 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
120 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 120 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
121 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 121 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
122 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 122 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
123 | 123 | ||
124 | ifdef NO_ICONV | 124 | ifdef NO_ICONV |
125 | CFLAGS += -DNO_ICONV | 125 | CFLAGS += -DNO_ICONV |
126 | endif | 126 | endif |
127 | ifdef NO_STRCASESTR | 127 | ifdef NO_STRCASESTR |
128 | CFLAGS += -DNO_STRCASESTR | 128 | CFLAGS += -DNO_STRCASESTR |
129 | endif | 129 | endif |
130 | ifdef NO_OPENSSL | 130 | ifdef NO_OPENSSL |
131 | CFLAGS += -DNO_OPENSSL | 131 | CFLAGS += -DNO_OPENSSL |
132 | GIT_OPTIONS += NO_OPENSSL=1 | 132 | GIT_OPTIONS += NO_OPENSSL=1 |
133 | else | 133 | else |
134 | EXTLIBS += -lcrypto | 134 | EXTLIBS += -lcrypto |
135 | endif | 135 | endif |
136 | 136 | ||
137 | cgit: $(OBJECTS) libgit | 137 | cgit: $(OBJECTS) libgit |
138 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) | 138 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) |
139 | 139 | ||
140 | cgit.o: VERSION | 140 | cgit.o: VERSION |
141 | 141 | ||
142 | ifneq "$(MAKECMDGOALS)" "clean" | 142 | ifneq "$(MAKECMDGOALS)" "clean" |
143 | -include $(OBJECTS:.o=.d) | 143 | -include $(OBJECTS:.o=.d) |
144 | endif | 144 | endif |
145 | 145 | ||
146 | libgit: | 146 | libgit: |
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 | ||
150 | test: all | 150 | test: all |
151 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all | 151 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
152 | 152 | ||
153 | install: all | 153 | install: 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 | ||
160 | uninstall: | 160 | uninstall: |
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 | ||
165 | doc: man-doc html-doc pdf-doc | 165 | doc: man-doc html-doc pdf-doc |
166 | 166 | ||
167 | man-doc: cgitrc.5.txt | 167 | man-doc: cgitrc.5.txt |
168 | a2x -f manpage cgitrc.5.txt | 168 | a2x -f manpage cgitrc.5.txt |
169 | 169 | ||
170 | html-doc: cgitrc.5.txt | 170 | html-doc: cgitrc.5.txt |
@@ -1,121 +1,121 @@ | |||
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 | ||
19 | const char *cgit_version = CGIT_VERSION; | 19 | const char *cgit_version = CGIT_VERSION; |
20 | 20 | ||
21 | void add_mimetype(const char *name, const char *value) | 21 | void 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 | ||
29 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 29 | struct 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 | ||
44 | static void process_cached_repolist(const char *path); | 44 | static void process_cached_repolist(const char *path); |
45 | 45 | ||
46 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) | 46 | void 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 | ||
90 | void config_cb(const char *name, const char *value) | 90 | void 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); |
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,135 +1,135 @@ | |||
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 | ||
15 | void cgit_print_commit(char *hex, const char *prefix) | 15 | void 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, ¬es, PAGE_ENCODING, 0); | 39 | format_note(NULL, sha1, ¬es, 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>"); |
@@ -19,193 +19,193 @@ void count_lines(char *line, int size) | |||
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 | ||
27 | void inspect_files(struct diff_filepair *pair) | 27 | void 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 | ||
40 | void show_commit_decorations(struct commit *commit) | 40 | void 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 | ||
79 | void print_commit(struct commit *commit) | 79 | void 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, ¬es, PAGE_ENCODING, 0); | 115 | format_note(NULL, commit->object.sha1, ¬es, 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(¬es); | 134 | strbuf_release(¬es); |
135 | } | 135 | } |
136 | cgit_free_commitinfo(info); | 136 | cgit_free_commitinfo(info); |
137 | } | 137 | } |
138 | 138 | ||
139 | static const char *disambiguate_ref(const char *ref) | 139 | static 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 | ||
151 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 151 | void 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"); |
@@ -1,133 +1,133 @@ | |||
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 | int match_baselen; | 13 | int match_baselen; |
14 | int match; | 14 | int match; |
15 | 15 | ||
16 | static void print_object(const unsigned char *sha1, const char *path) | 16 | static 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 | ||
55 | static void print_dir(const unsigned char *sha1, const char *path, | 55 | static 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 | ||
72 | static void print_dir_entry(const unsigned char *sha1, const char *path, | 72 | static 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 | ||
82 | static void print_dir_tail(void) | 82 | static 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 | ||
87 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 87 | static 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 | ||
107 | static int basedir_len(const char *path) | 107 | static 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 | ||
115 | void cgit_print_plain(struct cgit_context *ctx) | 115 | void 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 | } |
@@ -82,337 +82,337 @@ static void trunc_quarter(struct tm *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 | ||