-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,122 +1,122 @@ | |||
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)"' |
@@ -1,73 +1,73 @@ | |||
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); |
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,87 +1,87 @@ | |||
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>"); |
@@ -67,97 +67,97 @@ void show_commit_decorations(struct commit *commit) | |||
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); |
@@ -1,85 +1,85 @@ | |||
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 | } |
@@ -130,253 +130,253 @@ struct cgit_period periods[] = { | |||
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; |