summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile12
-rw-r--r--cgit.c67
-rw-r--r--cgit.css64
-rw-r--r--cgit.h12
-rw-r--r--cgit.pngbin3790 -> 5406 bytes
-rw-r--r--cgitrc12
-rw-r--r--html.c2
-rw-r--r--parsing.c25
-rw-r--r--shared.c12
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile13
-rwxr-xr-xtests/setup.sh108
-rwxr-xr-xtests/t0010-validate-html.sh31
-rwxr-xr-xtests/t0101-index.sh13
-rwxr-xr-xtests/t0102-summary.sh20
-rwxr-xr-xtests/t0103-log.sh15
-rwxr-xr-xtests/t0104-tree.sh21
-rwxr-xr-xtests/t0105-commit.sh22
-rwxr-xr-xtests/t0106-diff.sh20
-rwxr-xr-xtests/t0107-snapshot.sh36
-rw-r--r--ui-commit.c6
-rw-r--r--ui-diff.c2
-rw-r--r--ui-log.c23
-rw-r--r--ui-patch.c110
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c67
-rw-r--r--ui-summary.c2
-rw-r--r--ui-tree.c6
28 files changed, 651 insertions, 74 deletions
diff --git a/Makefile b/Makefile
index 68d617e..e39be18 100644
--- a/Makefile
+++ b/Makefile
@@ -13,16 +13,21 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
13-include cgit.conf 13-include cgit.conf
14 14
15 15
16EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto 16EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
17OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ 17OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \
18 ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ 18 ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \
19 ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o 19 ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o
20 20
21 21
22.PHONY: all git install clean distclean emptycache force-version get-git 22ifdef NEEDS_LIBICONV
23 EXTLIBS += -liconv
24endif
25
26
27.PHONY: all git test install clean distclean emptycache force-version get-git
23 28
24all: cgit git 29all: cgit git
25 30
26VERSION: force-version 31VERSION: force-version
27 @./gen-version.sh "$(CGIT_VERSION)" 32 @./gen-version.sh "$(CGIT_VERSION)"
28-include VERSION 33-include VERSION
@@ -46,12 +51,15 @@ git/xdiff/lib.a: | git
46git/libgit.a: | git 51git/libgit.a: | git
47 52
48git: 53git:
49 cd git && $(MAKE) xdiff/lib.a 54 cd git && $(MAKE) xdiff/lib.a
50 cd git && $(MAKE) libgit.a 55 cd git && $(MAKE) libgit.a
51 56
57test: all
58 $(MAKE) -C tests
59
52install: all 60install: all
53 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) 61 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
54 install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 62 install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
55 install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css 63 install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css
56 install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png 64 install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png
57 65
diff --git a/cgit.c b/cgit.c
index 142e416..e8acc03 100644
--- a/cgit.c
+++ b/cgit.c
@@ -42,19 +42,50 @@ static int cgit_prepare_cache(struct cacheitem *item)
42 else 42 else
43 item->ttl = cgit_cache_repo_ttl; 43 item->ttl = cgit_cache_repo_ttl;
44 } 44 }
45 return 1; 45 return 1;
46} 46}
47 47
48struct refmatch {
49 char *req_ref;
50 char *first_ref;
51 int match;
52};
53
54int find_current_ref(const char *refname, const unsigned char *sha1,
55 int flags, void *cb_data)
56{
57 struct refmatch *info;
58
59 info = (struct refmatch *)cb_data;
60 if (!strcmp(refname, info->req_ref))
61 info->match = 1;
62 if (!info->first_ref)
63 info->first_ref = xstrdup(refname);
64 return info->match;
65}
66
67char *find_default_branch(struct repoinfo *repo)
68{
69 struct refmatch info;
70
71 info.req_ref = repo->defbranch;
72 info.first_ref = NULL;
73 info.match = 0;
74 for_each_branch_ref(find_current_ref, &info);
75 if (info.match)
76 return info.req_ref;
77 else
78 return info.first_ref;
79}
80
48static void cgit_print_repo_page(struct cacheitem *item) 81static void cgit_print_repo_page(struct cacheitem *item)
49{ 82{
50 char *title; 83 char *title, *tmp;
51 int show_search; 84 int show_search;
52 85 unsigned char sha1[20];
53 if (!cgit_query_head)
54 cgit_query_head = cgit_repo->defbranch;
55 86
56 if (chdir(cgit_repo->path)) { 87 if (chdir(cgit_repo->path)) {
57 title = fmt("%s - %s", cgit_root_title, "Bad request"); 88 title = fmt("%s - %s", cgit_root_title, "Bad request");
58 cgit_print_docstart(title, item); 89 cgit_print_docstart(title, item);
59 cgit_print_pageheader(title, 0); 90 cgit_print_pageheader(title, 0);
60 cgit_print_error(fmt("Unable to scan repository: %s", 91 cgit_print_error(fmt("Unable to scan repository: %s",
@@ -64,20 +95,48 @@ static void cgit_print_repo_page(struct cacheitem *item)
64 } 95 }
65 96
66 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); 97 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
67 show_search = 0; 98 show_search = 0;
68 setenv("GIT_DIR", cgit_repo->path, 1); 99 setenv("GIT_DIR", cgit_repo->path, 1);
69 100
101 if (!cgit_query_head) {
102 cgit_query_head = xstrdup(find_default_branch(cgit_repo));
103 cgit_repo->defbranch = cgit_query_head;
104 }
105
106 if (!cgit_query_head) {
107 cgit_print_docstart(title, item);
108 cgit_print_pageheader(title, 0);
109 cgit_print_error("Repository seems to be empty");
110 cgit_print_docend();
111 return;
112 }
113
114 if (get_sha1(cgit_query_head, sha1)) {
115 tmp = xstrdup(cgit_query_head);
116 cgit_query_head = cgit_repo->defbranch;
117 cgit_print_docstart(title, item);
118 cgit_print_pageheader(title, 0);
119 cgit_print_error(fmt("Invalid branch: %s", tmp));
120 cgit_print_docend();
121 return;
122 }
123
70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { 124 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
71 cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, 125 cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1,
72 cgit_repobasename(cgit_repo->url), 126 cgit_repobasename(cgit_repo->url),
73 cgit_query_path, 127 cgit_query_path,
74 cgit_repo->snapshots ); 128 cgit_repo->snapshots );
75 return; 129 return;
76 } 130 }
77 131
132 if (cgit_cmd == CMD_PATCH) {
133 cgit_print_patch(cgit_query_sha1, item);
134 return;
135 }
136
78 if (cgit_cmd == CMD_BLOB) { 137 if (cgit_cmd == CMD_BLOB) {
79 cgit_print_blob(item, cgit_query_sha1, cgit_query_path); 138 cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
80 return; 139 return;
81 } 140 }
82 141
83 show_search = (cgit_cmd == CMD_LOG); 142 show_search = (cgit_cmd == CMD_LOG);
diff --git a/cgit.css b/cgit.css
index 1b2e9d6..17c2712 100644
--- a/cgit.css
+++ b/cgit.css
@@ -5,13 +5,13 @@ body, table {
5 5
6body { 6body {
7 font-family: sans; 7 font-family: sans;
8 font-size: 10pt; 8 font-size: 10pt;
9 color: #333; 9 color: #333;
10 background: white; 10 background: white;
11 padding-left: 4px; 11 padding: 4px;
12} 12}
13 13
14table { 14table {
15 border-collapse: collapse; 15 border-collapse: collapse;
16} 16}
17 17
@@ -75,86 +75,90 @@ table.list td {
75} 75}
76 76
77img { 77img {
78 border: none; 78 border: none;
79} 79}
80 80
81div#sidebar { 81table#layout {
82 border-collapse: collapse;
83 border: none;
84 margin: 0px;
85}
86
87td#sidebar {
82 vertical-align: top; 88 vertical-align: top;
83 width: 162px; 89 width: 162px;
84 padding: 0px 0px 0px 0px; 90 padding: 0px 0px 0px 0px;
85 margin: 4px; 91 margin: 0px;
86 float: left;
87} 92}
88 93
89div#logo { 94td#sidebar table {
95 border-collapse: separate;
96 border-spacing: 0px;
90 margin: 0px; 97 margin: 0px;
91 padding: 4px 0px 4px 0px; 98 padding: 0px;
92 text-align: center;
93 background-color: #ccc; 99 background-color: #ccc;
100}
101
102td#sidebar table.sidebar td.sidebar {
103 padding: 4px;
94 border-top: solid 1px #eee; 104 border-top: solid 1px #eee;
95 border-left: solid 1px #eee; 105 border-left: solid 1px #eee;
96 border-right: solid 1px #aaa; 106 border-right: solid 1px #aaa;
97 border-bottom: solid 1px #aaa; 107 border-bottom: solid 1px #aaa;
98} 108}
99 109
100div#sidebar div.infobox { 110div#logo {
101 margin: 0px 0px 0px 0px; 111 margin: 0px;
102 padding: 0.5em; 112 padding: 4px 0px 4px 0px;
103 text-align: left; 113 text-align: center;
104 background-color: #ccc; 114 background-color: #ccc;
105 border-top: solid 1px #eee; 115 border-top: solid 1px #eee;
106 border-left: solid 1px #eee; 116 border-left: solid 1px #eee;
107 border-right: solid 1px #aaa; 117 border-right: solid 1px #aaa;
108 border-bottom: solid 1px #aaa; 118 border-bottom: solid 1px #aaa;
109} 119}
110 120
111div#sidebar div.infobox h1 { 121td#sidebar h1 {
112 font-size: 11pt; 122 font-size: 10pt;
113 font-weight: bold; 123 font-weight: bold;
114 margin: 0px; 124 margin: 8px 0px 0px 0px;
115} 125}
116 126
117div#sidebar div.infobox a.menu { 127td#sidebar h1.first {
128 margin-top: 0px;
129}
130
131td#sidebar a.menu {
118 display: block; 132 display: block;
119 background-color: #ccc; 133 background-color: #ccc;
120 padding: 0.1em 0.5em; 134 padding: 0.1em 0.5em;
121 text-decoration: none; 135 text-decoration: none;
122} 136}
123 137
124div#sidebar div.infobox a.menu:hover { 138td#sidebar a.menu:hover {
125 background-color: #bbb; 139 background-color: #bbb;
126 text-decoration: none; 140 text-decoration: none;
127} 141}
128 142
129div#sidebar div.infobox select { 143td#sidebar select {
130 width: 100%; 144 width: 100%;
131 border: solid 1px #aaa;
132 background-color: #bbb;
133 margin: 2px 0px 0px 0px; 145 margin: 2px 0px 0px 0px;
134 padding: 0px;
135} 146}
136 147
137td#branch-dropdown-cell { 148td#sidebar form {
138 width: 99%; 149 text-align: right;
139} 150}
140 151
141input#switch-btn { 152input#switch-btn {
142 width: 20px;
143 border: solid 1px #aaa;
144 background-color: #bbb;
145 margin: 2px 0px 0px 0px; 153 margin: 2px 0px 0px 0px;
146 padding: 0px;
147} 154}
148 155
149div#sidebar div.infobox input.txt { 156td#sidebar input.txt {
150 width: 100%; 157 width: 100%;
151 border: solid 1px #aaa;
152 background-color: #bbb;
153 margin: 2px 0px 0px 0px; 158 margin: 2px 0px 0px 0px;
154 padding: 0;
155} 159}
156 160
157table#grid { 161table#grid {
158 margin: 0px; 162 margin: 0px;
159} 163}
160 164
diff --git a/cgit.h b/cgit.h
index 163f355..66c40b9 100644
--- a/cgit.h
+++ b/cgit.h
@@ -13,12 +13,13 @@
13#include <diffcore.h> 13#include <diffcore.h>
14#include <refs.h> 14#include <refs.h>
15#include <revision.h> 15#include <revision.h>
16#include <log-tree.h> 16#include <log-tree.h>
17#include <archive.h> 17#include <archive.h>
18#include <xdiff/xdiff.h> 18#include <xdiff/xdiff.h>
19#include <utf8.h>
19 20
20 21
21/* 22/*
22 * The valid cgit repo-commands 23 * The valid cgit repo-commands
23 */ 24 */
24#define CMD_LOG 1 25#define CMD_LOG 1
@@ -26,12 +27,13 @@
26#define CMD_DIFF 3 27#define CMD_DIFF 3
27#define CMD_TREE 4 28#define CMD_TREE 4
28#define CMD_BLOB 5 29#define CMD_BLOB 5
29#define CMD_SNAPSHOT 6 30#define CMD_SNAPSHOT 6
30#define CMD_TAG 7 31#define CMD_TAG 7
31#define CMD_REFS 8 32#define CMD_REFS 8
33#define CMD_PATCH 9
32 34
33/* 35/*
34 * Dateformats used on misc. pages 36 * Dateformats used on misc. pages
35 */ 37 */
36#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" 38#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
37#define FMT_SHORTDATE "%Y-%m-%d" 39#define FMT_SHORTDATE "%Y-%m-%d"
@@ -45,12 +47,17 @@
45#define TM_DAY (TM_HOUR * 24) 47#define TM_DAY (TM_HOUR * 24)
46#define TM_WEEK (TM_DAY * 7) 48#define TM_WEEK (TM_DAY * 7)
47#define TM_YEAR (TM_DAY * 365) 49#define TM_YEAR (TM_DAY * 365)
48#define TM_MONTH (TM_YEAR / 12.0) 50#define TM_MONTH (TM_YEAR / 12.0)
49 51
50 52
53/*
54 * Default encoding
55 */
56#define PAGE_ENCODING "UTF-8"
57
51typedef void (*configfn)(const char *name, const char *value); 58typedef void (*configfn)(const char *name, const char *value);
52typedef void (*filepair_fn)(struct diff_filepair *pair); 59typedef void (*filepair_fn)(struct diff_filepair *pair);
53typedef void (*linediff_fn)(char *line, int len); 60typedef void (*linediff_fn)(char *line, int len);
54 61
55struct cacheitem { 62struct cacheitem {
56 char *name; 63 char *name;
@@ -66,12 +73,13 @@ struct repoinfo {
66 char *desc; 73 char *desc;
67 char *owner; 74 char *owner;
68 char *defbranch; 75 char *defbranch;
69 char *group; 76 char *group;
70 char *module_link; 77 char *module_link;
71 char *readme; 78 char *readme;
79 char *clone_url;
72 int snapshots; 80 int snapshots;
73 int enable_log_filecount; 81 int enable_log_filecount;
74 int enable_log_linecount; 82 int enable_log_linecount;
75}; 83};
76 84
77struct repolist { 85struct repolist {
@@ -87,12 +95,13 @@ struct commitinfo {
87 unsigned long author_date; 95 unsigned long author_date;
88 char *committer; 96 char *committer;
89 char *committer_email; 97 char *committer_email;
90 unsigned long committer_date; 98 unsigned long committer_date;
91 char *subject; 99 char *subject;
92 char *msg; 100 char *msg;
101 char *msg_encoding;
93}; 102};
94 103
95struct taginfo { 104struct taginfo {
96 char *tagger; 105 char *tagger;
97 char *tagger_email; 106 char *tagger_email;
98 int tagger_date; 107 int tagger_date;
@@ -129,12 +138,14 @@ extern char *cgit_logo_link;
129extern char *cgit_module_link; 138extern char *cgit_module_link;
130extern char *cgit_agefile; 139extern char *cgit_agefile;
131extern char *cgit_virtual_root; 140extern char *cgit_virtual_root;
132extern char *cgit_script_name; 141extern char *cgit_script_name;
133extern char *cgit_cache_root; 142extern char *cgit_cache_root;
134extern char *cgit_repo_group; 143extern char *cgit_repo_group;
144extern char *cgit_robots;
145extern char *cgit_clone_prefix;
135 146
136extern int cgit_nocache; 147extern int cgit_nocache;
137extern int cgit_snapshots; 148extern int cgit_snapshots;
138extern int cgit_enable_index_links; 149extern int cgit_enable_index_links;
139extern int cgit_enable_log_filecount; 150extern int cgit_enable_log_filecount;
140extern int cgit_enable_log_linecount; 151extern int cgit_enable_log_linecount;
@@ -270,12 +281,13 @@ extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep,
270extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 281extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
271extern void cgit_print_tree(const char *rev, char *path); 282extern void cgit_print_tree(const char *rev, char *path);
272extern void cgit_print_commit(char *hex); 283extern void cgit_print_commit(char *hex);
273extern void cgit_print_refs(); 284extern void cgit_print_refs();
274extern void cgit_print_tag(char *revname); 285extern void cgit_print_tag(char *revname);
275extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); 286extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix);
287extern void cgit_print_patch(char *hex, struct cacheitem *item);
276extern void cgit_print_snapshot(struct cacheitem *item, const char *head, 288extern void cgit_print_snapshot(struct cacheitem *item, const char *head,
277 const char *hex, const char *prefix, 289 const char *hex, const char *prefix,
278 const char *filename, int snapshot); 290 const char *filename, int snapshot);
279extern void cgit_print_snapshot_links(const char *repo, const char *head, 291extern void cgit_print_snapshot_links(const char *repo, const char *head,
280 const char *hex, int snapshots); 292 const char *hex, int snapshots);
281extern int cgit_parse_snapshots_mask(const char *str); 293extern int cgit_parse_snapshots_mask(const char *str);
diff --git a/cgit.png b/cgit.png
index ee48197..22f7e95 100644
--- a/cgit.png
+++ b/cgit.png
Binary files differ
diff --git a/cgitrc b/cgitrc
index 6363c9c..ce0c01b 100644
--- a/cgitrc
+++ b/cgitrc
@@ -5,12 +5,17 @@
5 5
6## Uncomment and set to 1 to deactivate caching of generated pages. Mostly 6## Uncomment and set to 1 to deactivate caching of generated pages. Mostly
7## usefull for testing. 7## usefull for testing.
8#nocache=0 8#nocache=0
9 9
10 10
11## This variable can be used to override the default value for "robots"
12## meta-tag. If unset, the meta-tag isn't generated.
13#robots=index, nofollow
14
15
11## Set allowed snapshot types by default. Can be overridden per repo 16## Set allowed snapshot types by default. Can be overridden per repo
12# can be any combination of zip/tar.gz/tar.bz2/tar 17# can be any combination of zip/tar.gz/tar.bz2/tar
13#snapshots=0 18#snapshots=0
14 19
15 20
16## Enable/disable extra links to summary/log/tree per repo on index page 21## Enable/disable extra links to summary/log/tree per repo on index page
@@ -108,12 +113,17 @@
108 113
109 114
110## Url loaded when clicking a submodule link 115## Url loaded when clicking a submodule link
111#module-link=./?repo=%s&page=commit&id=%s 116#module-link=./?repo=%s&page=commit&id=%s
112 117
113 118
119## Shared prefix which, when combined with repo url, becomes the url used
120## to clone the repo
121#clone-prefix=
122
123
114## Number of chars shown of repo description (in repolist view) 124## Number of chars shown of repo description (in repolist view)
115#max-repodesc-length=60 125#max-repodesc-length=60
116 126
117 127
118## Number of chars shown of commit subject message (in log view) 128## Number of chars shown of commit subject message (in log view)
119#max-message-length=60 129#max-message-length=60
@@ -159,18 +169,20 @@
159 #repo.defbranch=master ## define a default branch 169 #repo.defbranch=master ## define a default branch
160 #repo.snapshots=tar.bz2 ## override a sitewide snapshot-setting 170 #repo.snapshots=tar.bz2 ## override a sitewide snapshot-setting
161 #repo.enable-log-filecount=0 ## override the default filecount setting 171 #repo.enable-log-filecount=0 ## override the default filecount setting
162 #repo.enable-log-linecount=0 ## override the default linecount setting 172 #repo.enable-log-linecount=0 ## override the default linecount setting
163 #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link 173 #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link
164 #repo.readme=info/web/readme ## specify a file to include on summary page 174 #repo.readme=info/web/readme ## specify a file to include on summary page
175#repo.clone-url=git://hjemli.net/pub/git/cgit
165 176
166## Additional repositories grouped under "mirrors" 177## Additional repositories grouped under "mirrors"
167#repo.group=mirrors 178#repo.group=mirrors
168 179
169#repo.url=git 180#repo.url=git
170#repo.path=/pub/git/git 181#repo.path=/pub/git/git
182#repo.clone-url=git://hjemli.net/pub/git/git
171# 183#
172#repo.url=linux 184#repo.url=linux
173#repo.path=/pub/git/linux 185#repo.path=/pub/git/linux
174 186
175## A group of private repositories (with a working directory) 187## A group of private repositories (with a working directory)
176#repo.group=private 188#repo.group=private
diff --git a/html.c b/html.c
index 6c9cc8b..eb163d9 100644
--- a/html.c
+++ b/html.c
@@ -129,13 +129,13 @@ void html_hidden(char *name, char *value)
129void html_option(char *value, char *text, char *selected_value) 129void html_option(char *value, char *text, char *selected_value)
130{ 130{
131 html("<option value='"); 131 html("<option value='");
132 html_attr(value); 132 html_attr(value);
133 html("'"); 133 html("'");
134 if (selected_value && !strcmp(selected_value, value)) 134 if (selected_value && !strcmp(selected_value, value))
135 html(" selected"); 135 html(" selected='selected'");
136 html(">"); 136 html(">");
137 html_txt(text); 137 html_txt(text);
138 html("</option>\n"); 138 html("</option>\n");
139} 139}
140 140
141void html_link_open(char *url, char *title, char *class) 141void html_link_open(char *url, char *title, char *class)
diff --git a/parsing.c b/parsing.c
index 55a485d..5093b8b 100644
--- a/parsing.c
+++ b/parsing.c
@@ -196,12 +196,13 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
196 ret->author = NULL; 196 ret->author = NULL;
197 ret->author_email = NULL; 197 ret->author_email = NULL;
198 ret->committer = NULL; 198 ret->committer = NULL;
199 ret->committer_email = NULL; 199 ret->committer_email = NULL;
200 ret->subject = NULL; 200 ret->subject = NULL;
201 ret->msg = NULL; 201 ret->msg = NULL;
202 ret->msg_encoding = NULL;
202 203
203 if (p == NULL) 204 if (p == NULL)
204 return ret; 205 return ret;
205 206
206 if (strncmp(p, "tree ", 5)) 207 if (strncmp(p, "tree ", 5))
207 die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); 208 die("Bad commit: %s", sha1_to_hex(commit->object.sha1));
@@ -230,12 +231,20 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
230 t = strchr(t, '>') + 1; 231 t = strchr(t, '>') + 1;
231 ret->committer_email = substr(p, t); 232 ret->committer_email = substr(p, t);
232 ret->committer_date = atol(t+1); 233 ret->committer_date = atol(t+1);
233 p = strchr(t, '\n') + 1; 234 p = strchr(t, '\n') + 1;
234 } 235 }
235 236
237 if (!strncmp(p, "encoding ", 9)) {
238 p += 9;
239 t = strchr(p, '\n') + 1;
240 ret->msg_encoding = substr(p, t);
241 p = t;
242 } else
243 ret->msg_encoding = xstrdup(PAGE_ENCODING);
244
236 while (*p && (*p != '\n')) 245 while (*p && (*p != '\n'))
237 p = strchr(p, '\n') + 1; // skip unknown header fields 246 p = strchr(p, '\n') + 1; // skip unknown header fields
238 247
239 while (*p == '\n') 248 while (*p == '\n')
240 p = strchr(p, '\n') + 1; 249 p = strchr(p, '\n') + 1;
241 250
@@ -250,12 +259,28 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
250 while (*p == '\n') 259 while (*p == '\n')
251 p = strchr(p, '\n') + 1; 260 p = strchr(p, '\n') + 1;
252 ret->msg = xstrdup(p); 261 ret->msg = xstrdup(p);
253 } else 262 } else
254 ret->subject = substr(p, p+strlen(p)); 263 ret->subject = substr(p, p+strlen(p));
255 264
265 if(strcmp(ret->msg_encoding, PAGE_ENCODING)) {
266 t = reencode_string(ret->subject, PAGE_ENCODING,
267 ret->msg_encoding);
268 if(t) {
269 free(ret->subject);
270 ret->subject = t;
271 }
272
273 t = reencode_string(ret->msg, PAGE_ENCODING,
274 ret->msg_encoding);
275 if(t) {
276 free(ret->msg);
277 ret->msg = t;
278 }
279 }
280
256 return ret; 281 return ret;
257} 282}
258 283
259 284
260struct taginfo *cgit_parse_tag(struct tag *tag) 285struct taginfo *cgit_parse_tag(struct tag *tag)
261{ 286{
diff --git a/shared.c b/shared.c
index 84aa281..bf0581f 100644
--- a/shared.c
+++ b/shared.c
@@ -23,12 +23,14 @@ char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
23char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; 23char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
24char *cgit_agefile = "info/web/last-modified"; 24char *cgit_agefile = "info/web/last-modified";
25char *cgit_virtual_root = NULL; 25char *cgit_virtual_root = NULL;
26char *cgit_script_name = CGIT_SCRIPT_NAME; 26char *cgit_script_name = CGIT_SCRIPT_NAME;
27char *cgit_cache_root = CGIT_CACHE_ROOT; 27char *cgit_cache_root = CGIT_CACHE_ROOT;
28char *cgit_repo_group = NULL; 28char *cgit_repo_group = NULL;
29char *cgit_robots = "index, nofollow";
30char *cgit_clone_prefix = NULL;
29 31
30int cgit_nocache = 0; 32int cgit_nocache = 0;
31int cgit_snapshots = 0; 33int cgit_snapshots = 0;
32int cgit_enable_index_links = 0; 34int cgit_enable_index_links = 0;
33int cgit_enable_log_filecount = 0; 35int cgit_enable_log_filecount = 0;
34int cgit_enable_log_linecount = 0; 36int cgit_enable_log_linecount = 0;
@@ -65,13 +67,13 @@ int cgit_query_ofs = 0;
65int htmlfd = 0; 67int htmlfd = 0;
66 68
67 69
68int cgit_get_cmd_index(const char *cmd) 70int cgit_get_cmd_index(const char *cmd)
69{ 71{
70 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 72 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
71 "snapshot", "tag", "refs", NULL}; 73 "snapshot", "tag", "refs", "patch", NULL};
72 int i; 74 int i;
73 75
74 for(i = 0; cmds[i]; i++) 76 for(i = 0; cmds[i]; i++)
75 if (!strcmp(cmd, cmds[i])) 77 if (!strcmp(cmd, cmds[i]))
76 return i + 1; 78 return i + 1;
77 return 0; 79 return 0;
@@ -194,20 +196,26 @@ void cgit_global_config_cb(const char *name, const char *value)
194 else if (!strcmp(name, "summary-tags")) 196 else if (!strcmp(name, "summary-tags"))
195 cgit_summary_tags = atoi(value); 197 cgit_summary_tags = atoi(value);
196 else if (!strcmp(name, "agefile")) 198 else if (!strcmp(name, "agefile"))
197 cgit_agefile = xstrdup(value); 199 cgit_agefile = xstrdup(value);
198 else if (!strcmp(name, "renamelimit")) 200 else if (!strcmp(name, "renamelimit"))
199 cgit_renamelimit = atoi(value); 201 cgit_renamelimit = atoi(value);
202 else if (!strcmp(name, "robots"))
203 cgit_robots = xstrdup(value);
204 else if (!strcmp(name, "clone-prefix"))
205 cgit_clone_prefix = xstrdup(value);
200 else if (!strcmp(name, "repo.group")) 206 else if (!strcmp(name, "repo.group"))
201 cgit_repo_group = xstrdup(value); 207 cgit_repo_group = xstrdup(value);
202 else if (!strcmp(name, "repo.url")) 208 else if (!strcmp(name, "repo.url"))
203 cgit_repo = add_repo(value); 209 cgit_repo = add_repo(value);
204 else if (!strcmp(name, "repo.name")) 210 else if (!strcmp(name, "repo.name"))
205 cgit_repo->name = xstrdup(value); 211 cgit_repo->name = xstrdup(value);
206 else if (cgit_repo && !strcmp(name, "repo.path")) 212 else if (cgit_repo && !strcmp(name, "repo.path"))
207 cgit_repo->path = trim_end(value, '/'); 213 cgit_repo->path = trim_end(value, '/');
214 else if (cgit_repo && !strcmp(name, "repo.clone-url"))
215 cgit_repo->clone_url = xstrdup(value);
208 else if (cgit_repo && !strcmp(name, "repo.desc")) 216 else if (cgit_repo && !strcmp(name, "repo.desc"))
209 cgit_repo->desc = xstrdup(value); 217 cgit_repo->desc = xstrdup(value);
210 else if (cgit_repo && !strcmp(name, "repo.owner")) 218 else if (cgit_repo && !strcmp(name, "repo.owner"))
211 cgit_repo->owner = xstrdup(value); 219 cgit_repo->owner = xstrdup(value);
212 else if (cgit_repo && !strcmp(name, "repo.defbranch")) 220 else if (cgit_repo && !strcmp(name, "repo.defbranch"))
213 cgit_repo->defbranch = xstrdup(value); 221 cgit_repo->defbranch = xstrdup(value);
@@ -264,12 +272,14 @@ void *cgit_free_commitinfo(struct commitinfo *info)
264{ 272{
265 free(info->author); 273 free(info->author);
266 free(info->author_email); 274 free(info->author_email);
267 free(info->committer); 275 free(info->committer);
268 free(info->committer_email); 276 free(info->committer_email);
269 free(info->subject); 277 free(info->subject);
278 free(info->msg);
279 free(info->msg_encoding);
270 free(info); 280 free(info);
271 return NULL; 281 return NULL;
272} 282}
273 283
274int hextoint(char c) 284int hextoint(char c)
275{ 285{
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..c1c1c0b
--- a/dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,2 @@
1trash
2test-output.log
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..697e5a1
--- a/dev/null
+++ b/tests/Makefile
@@ -0,0 +1,13 @@
1
2
3T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
4
5all: $(T)
6
7$(T):
8 @$@
9
10clean:
11 $(RM) -rf trash
12
13.PHONY: $(T) clean
diff --git a/tests/setup.sh b/tests/setup.sh
new file mode 100755
index 0000000..51d5a75
--- a/dev/null
+++ b/tests/setup.sh
@@ -0,0 +1,108 @@
1# This file should be sourced by all test-scripts
2#
3# Main functions:
4# prepare_tests(description) - setup for testing, i.e. create repos+config
5# run_test(description, script) - run one test, i.e. eval script
6#
7# Helper functions
8# cgit_query(querystring) - call cgit with the specified querystring
9# cgit_url(url) - call cgit with the specified virtual url
10#
11# Example script:
12#
13# . setup.sh
14# prepare_tests "html validation"
15# run_test 'repo index' 'cgit_url "/" | tidy -e'
16# run_test 'repo summary' 'cgit_url "/foo" | tidy -e'
17
18
19mkrepo() {
20 name=$1
21 count=$2
22 dir=$PWD
23 test -d $name && return
24 printf "Creating testrepo %s\n" $name
25 mkdir -p $name
26 cd $name
27 git init
28 for ((n=1; n<=count; n++))
29 do
30 echo $n >file-$n
31 git add file-$n
32 git commit -m "commit $n"
33 done
34 cd $dir
35}
36
37setup_repos()
38{
39 rm -rf trash/cache
40 mkdir -p trash/cache
41 mkrepo trash/repos/foo 5 >/dev/null
42 mkrepo trash/repos/bar 50 >/dev/null
43 cat >trash/cgitrc <<EOF
44virtual-root=/
45cache-root=$PWD/trash/cache
46
47nocache=0
48snapshots=tar.gz tar.bz zip
49enable-log-filecount=1
50enable-log-linecount=1
51summary-log=5
52summary-branches=5
53summary-tags=5
54
55repo.url=foo
56repo.path=$PWD/trash/repos/foo/.git
57repo.desc=the foo repo
58
59repo.url=bar
60repo.path=$PWD/trash/repos/bar/.git
61repo.desc=the bar repo
62EOF
63}
64
65prepare_tests()
66{
67 setup_repos
68 test_count=0
69 test_failed=0
70 echo "$@" "($0)"
71}
72
73tests_done()
74{
75 printf "\n"
76 if test $test_failed -gt 0
77 then
78 printf "[%s of %s tests failed]\n" $test_failed $test_count
79 false
80 fi
81}
82
83run_test()
84{
85 desc=$1
86 script=$2
87 ((test_count++))
88 eval "$2" >test-output.log
89 res=$?
90 if test $res = 0
91 then
92 printf " %s: ok - %s\n" $test_count "$desc"
93 else
94 ((test_failed++))
95 printf " %s: fail - %s\n" $test_count "$desc"
96 fi
97}
98
99cgit_query()
100{
101 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit"
102}
103
104cgit_url()
105{
106 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit"
107}
108
diff --git a/tests/t0010-validate-html.sh b/tests/t0010-validate-html.sh
new file mode 100755
index 0000000..907a415
--- a/dev/null
+++ b/tests/t0010-validate-html.sh
@@ -0,0 +1,31 @@
1#!/bin/sh
2
3. ./setup.sh
4
5
6test_url()
7{
8 tidy_opt="-eq"
9 test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no"
10 cgit_url "$1" | sed -e "1,4d" >trash/tidy-$test_count
11 tidy $tidy_opt trash/tidy-$test_count
12 rc=$?
13 if test $rc = 2
14 then
15 false
16 else
17 :
18 fi
19}
20
21prepare_tests 'Validate html with tidy'
22
23run_test 'index page' 'test_url ""'
24run_test 'foo' 'test_url "foo"'
25run_test 'foo/log' 'test_url "foo/log"'
26run_test 'foo/tree' 'test_url "foo/tree"'
27run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"'
28run_test 'foo/commit' 'test_url "foo/commit"'
29run_test 'foo/diff' 'test_url "foo/diff"'
30
31tests_done
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh
new file mode 100755
index 0000000..12ed00c
--- a/dev/null
+++ b/tests/t0101-index.sh
@@ -0,0 +1,13 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on index page"
6
7run_test 'generate index page' 'cgit_url "" >trash/tmp'
8run_test 'find foo repo' 'grep -e "foo" trash/tmp'
9run_test 'find bar repo' 'grep -e "bar" trash/tmp'
10run_test 'no tree-link' 'grep -ve "foo/tree" trash/tmp'
11run_test 'no log-link' 'grep -ve "foo/log" trash/tmp'
12
13tests_done
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh
new file mode 100755
index 0000000..7edd675
--- a/dev/null
+++ b/tests/t0102-summary.sh
@@ -0,0 +1,20 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on summary page"
6
7run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp'
8run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
9run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
10run_test 'find branch master' 'grep -e "master" trash/tmp'
11run_test 'no tags' 'grep -ve "tags" trash/tmp'
12
13run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp'
14run_test 'no commit 45' 'grep -ve "commit 45" trash/tmp'
15run_test 'find commit 46' 'grep -e "commit 46" trash/tmp'
16run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
17run_test 'find branch master' 'grep -e "master" trash/tmp'
18run_test 'no tags' 'grep -ve "tags" trash/tmp'
19
20tests_done
diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh
new file mode 100755
index 0000000..b08cd29
--- a/dev/null
+++ b/tests/t0103-log.sh
@@ -0,0 +1,15 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on log page"
6
7run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp'
8run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
9run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
10
11run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp'
12run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
13run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
14
15tests_done
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
new file mode 100755
index 0000000..2516c72
--- a/dev/null
+++ b/tests/t0104-tree.sh
@@ -0,0 +1,21 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on tree page"
6
7run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp'
8run_test 'find file-1' 'grep -e "file-1" trash/tmp'
9run_test 'find file-50' 'grep -e "file-50" trash/tmp'
10
11run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'
12
13run_test 'find line 1' '
14 grep -e "<a id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
15'
16
17run_test 'no line 2' '
18 grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
19'
20
21tests_done
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh
new file mode 100755
index 0000000..aa2bf33
--- a/dev/null
+++ b/tests/t0105-commit.sh
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on commit page"
6
7run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp'
8run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" trash/tmp'
9run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp'
10
11run_test 'find commit subject' '
12 grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp
13'
14
15run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp'
16run_test 'find diffstat' 'grep -e "<table summary=.diffstat. class=.diffstat.>" trash/tmp'
17
18run_test 'find diff summary' '
19 grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp
20'
21
22tests_done
diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh
new file mode 100755
index 0000000..e140bcc
--- a/dev/null
+++ b/tests/t0106-diff.sh
@@ -0,0 +1,20 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on diff page"
6
7run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp'
8run_test 'find diff header' 'grep -e "a/file-5 b/file-5" trash/tmp'
9run_test 'find blob link' 'grep -e "<a href=./foo/tree/file-5?id=" trash/tmp'
10run_test 'find added file' 'grep -e "new file mode 100644" trash/tmp'
11
12run_test 'find hunk header' '
13 grep -e "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp
14'
15
16run_test 'find added line' '
17 grep -e "<div class=.add.>+5</div>" trash/tmp
18'
19
20tests_done
diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
new file mode 100755
index 0000000..8e90e10
--- a/dev/null
+++ b/tests/t0107-snapshot.sh
@@ -0,0 +1,36 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Verify snapshot"
6
7run_test 'get foo/snapshot/test.tar.gz' '
8 cgit_url "foo/snapshot/test.tar.gz" >trash/tmp
9'
10
11run_test 'check html headers' '
12 head -n 1 trash/tmp |
13 grep -e "Content-Type: application/x-tar" &&
14
15 head -n 2 trash/tmp |
16 grep -e "Content-Disposition: inline; filename=.test.tar.gz."
17'
18
19run_test 'strip off the header lines' '
20 tail -n +6 trash/tmp > trash/test.tar.gz
21'
22
23run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz'
24run_test 'untar' 'tar -xf trash/test.tar.gz -C trash'
25
26run_test 'count files' '
27 c=$(ls -1 trash/foo/ | wc -l) &&
28 test $c = 5
29'
30
31run_test 'verify untarred file-5' '
32 grep -e "^5$" trash/foo/file-5 &&
33 test $(cat trash/foo/file-5 | wc -l) = 1
34'
35
36tests_done
diff --git a/ui-commit.c b/ui-commit.c
index 4ac8955..bd55a33 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -81,13 +81,13 @@ void print_fileinfo(struct fileinfo *info)
81 htmlf(" (%s from %s)", 81 htmlf(" (%s from %s)",
82 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", 82 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
83 info->old_path); 83 info->old_path);
84 html("</td><td class='right'>"); 84 html("</td><td class='right'>");
85 htmlf("%d", info->added + info->removed); 85 htmlf("%d", info->added + info->removed);
86 html("</td><td class='graph'>"); 86 html("</td><td class='graph'>");
87 htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); 87 htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
88 htmlf("<td class='add' style='width: %.1f%%;'/>", 88 htmlf("<td class='add' style='width: %.1f%%;'/>",
89 info->added * 100.0 / max_changes); 89 info->added * 100.0 / max_changes);
90 htmlf("<td class='rem' style='width: %.1f%%;'/>", 90 htmlf("<td class='rem' style='width: %.1f%%;'/>",
91 info->removed * 100.0 / max_changes); 91 info->removed * 100.0 / max_changes);
92 htmlf("<td class='none' style='width: %.1f%%;'/>", 92 htmlf("<td class='none' style='width: %.1f%%;'/>",
93 (max_changes - info->removed - info->added) * 100.0 / max_changes); 93 (max_changes - info->removed - info->added) * 100.0 / max_changes);
@@ -154,13 +154,13 @@ void cgit_print_commit(char *hex)
154 if (!commit) { 154 if (!commit) {
155 cgit_print_error(fmt("Bad commit reference: %s", hex)); 155 cgit_print_error(fmt("Bad commit reference: %s", hex));
156 return; 156 return;
157 } 157 }
158 info = cgit_parse_commit(commit); 158 info = cgit_parse_commit(commit);
159 159
160 html("<table class='commit-info'>\n"); 160 html("<table summary='commit info' class='commit-info'>\n");
161 html("<tr><th>author</th><td>"); 161 html("<tr><th>author</th><td>");
162 html_txt(info->author); 162 html_txt(info->author);
163 html(" "); 163 html(" ");
164 html_txt(info->author_email); 164 html_txt(info->author_email);
165 html("</td><td class='right'>"); 165 html("</td><td class='right'>");
166 cgit_print_date(info->author_date, FMT_LONGDATE); 166 cgit_print_date(info->author_date, FMT_LONGDATE);
@@ -206,13 +206,13 @@ void cgit_print_commit(char *hex)
206 html("</div>"); 206 html("</div>");
207 html("<div class='commit-msg'>"); 207 html("<div class='commit-msg'>");
208 html_txt(info->msg); 208 html_txt(info->msg);
209 html("</div>"); 209 html("</div>");
210 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { 210 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) {
211 html("<div class='diffstat-header'>Diffstat</div>"); 211 html("<div class='diffstat-header'>Diffstat</div>");
212 html("<table class='diffstat'>"); 212 html("<table summary='diffstat' class='diffstat'>");
213 max_changes = 0; 213 max_changes = 0;
214 cgit_diff_commit(commit, inspect_filepair); 214 cgit_diff_commit(commit, inspect_filepair);
215 for(i = 0; i<files; i++) 215 for(i = 0; i<files; i++)
216 print_fileinfo(&items[i]); 216 print_fileinfo(&items[i]);
217 html("</table>"); 217 html("</table>");
218 html("<div class='diffstat-summary'>"); 218 html("<div class='diffstat-summary'>");
diff --git a/ui-diff.c b/ui-diff.c
index ac9a3fa..4fcf852 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -138,12 +138,12 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
138 return; 138 return;
139 } 139 }
140 commit2 = lookup_commit_reference(old_rev_sha1); 140 commit2 = lookup_commit_reference(old_rev_sha1);
141 if (!commit2 || parse_commit(commit2)) 141 if (!commit2 || parse_commit(commit2))
142 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); 142 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
143 } 143 }
144 html("<table class='diff'>"); 144 html("<table summary='diff' class='diff'>");
145 html("<tr><td>"); 145 html("<tr><td>");
146 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); 146 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
147 html("</td></tr>"); 147 html("</td></tr>");
148 html("</table>"); 148 html("</table>");
149} 149}
diff --git a/ui-log.c b/ui-log.c
index 9f5fdf6..a41d2b2 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -5,18 +5,24 @@
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 10
11int files, lines; 11int files, add_lines, rem_lines;
12 12
13void count_lines(char *line, int size) 13void count_lines(char *line, int size)
14{ 14{
15 if (size>0 && (line[0] == '+' || line[0] == '-')) 15 if (size <= 0)
16 lines++; 16 return;
17
18 if (line[0] == '+')
19 add_lines++;
20
21 else if (line[0] == '-')
22 rem_lines++;
17} 23}
18 24
19void inspect_files(struct diff_filepair *pair) 25void inspect_files(struct diff_filepair *pair)
20{ 26{
21 files++; 27 files++;
22 if (cgit_repo->enable_log_linecount) 28 if (cgit_repo->enable_log_linecount)
@@ -32,19 +38,20 @@ void print_commit(struct commit *commit)
32 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 38 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
33 html("</td><td>"); 39 html("</td><td>");
34 cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, 40 cgit_commit_link(info->subject, NULL, NULL, cgit_query_head,
35 sha1_to_hex(commit->object.sha1)); 41 sha1_to_hex(commit->object.sha1));
36 if (cgit_repo->enable_log_filecount) { 42 if (cgit_repo->enable_log_filecount) {
37 files = 0; 43 files = 0;
38 lines = 0; 44 add_lines = 0;
45 rem_lines = 0;
39 cgit_diff_commit(commit, inspect_files); 46 cgit_diff_commit(commit, inspect_files);
40 html("</td><td class='right'>"); 47 html("</td><td class='right'>");
41 htmlf("%d", files); 48 htmlf("%d", files);
42 if (cgit_repo->enable_log_linecount) { 49 if (cgit_repo->enable_log_linecount) {
43 html("</td><td class='right'>"); 50 html("</td><td class='right'>");
44 htmlf("%d", lines); 51 htmlf("-%d/+%d", rem_lines, add_lines);
45 } 52 }
46 } 53 }
47 html("</td><td>"); 54 html("</td><td>");
48 html_txt(info->author); 55 html_txt(info->author);
49 html("</td></tr>\n"); 56 html("</td></tr>\n");
50 cgit_free_commitinfo(info); 57 cgit_free_commitinfo(info);
@@ -80,20 +87,20 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
80 if (rev.grep_filter) { 87 if (rev.grep_filter) {
81 rev.grep_filter->regflags |= REG_ICASE; 88 rev.grep_filter->regflags |= REG_ICASE;
82 compile_grep_patterns(rev.grep_filter); 89 compile_grep_patterns(rev.grep_filter);
83 } 90 }
84 prepare_revision_walk(&rev); 91 prepare_revision_walk(&rev);
85 92
86 html("<table class='list nowrap'>"); 93 html("<table summary='log' class='list nowrap'>");
87 html("<tr class='nohover'><th class='left'>Age</th>" 94 html("<tr class='nohover'><th class='left'>Age</th>"
88 "<th class='left'>Message</th>"); 95 "<th class='left'>Message</th>");
89 96
90 if (cgit_repo->enable_log_filecount) { 97 if (cgit_repo->enable_log_filecount) {
91 html("<th class='left'>Files</th>"); 98 html("<th class='right'>Files</th>");
92 if (cgit_repo->enable_log_linecount) 99 if (cgit_repo->enable_log_linecount)
93 html("<th class='left'>Lines</th>"); 100 html("<th class='right'>Lines</th>");
94 } 101 }
95 html("<th class='left'>Author</th></tr>\n"); 102 html("<th class='left'>Author</th></tr>\n");
96 103
97 if (ofs<0) 104 if (ofs<0)
98 ofs = 0; 105 ofs = 0;
99 106
diff --git a/ui-patch.c b/ui-patch.c
new file mode 100644
index 0000000..e7a010a
--- a/dev/null
+++ b/ui-patch.c
@@ -0,0 +1,110 @@
1/* ui-patch.c: generate patch view
2 *
3 * Copyright (C) 2007 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
10
11static void print_line(char *line, int len)
12{
13 char c = line[len-1];
14
15 line[len-1] = '\0';
16 htmlf("%s\n", line);
17 line[len-1] = c;
18}
19
20static void header(unsigned char *sha1, char *path1, int mode1,
21 unsigned char *sha2, char *path2, int mode2)
22{
23 char *abbrev1, *abbrev2;
24 int subproject;
25
26 subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2));
27 htmlf("diff --git a/%s b/%s\n", path1, path2);
28
29 if (is_null_sha1(sha1))
30 path1 = "dev/null";
31 if (is_null_sha1(sha2))
32 path2 = "dev/null";
33
34 if (mode1 == 0)
35 htmlf("new file mode %.6o\n", mode2);
36
37 if (mode2 == 0)
38 htmlf("deleted file mode %.6o\n", mode1);
39
40 if (!subproject) {
41 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
42 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
43 htmlf("index %s..%s", abbrev1, abbrev2);
44 free(abbrev1);
45 free(abbrev2);
46 if (mode1 != 0 && mode2 != 0) {
47 htmlf(" %.6o", mode1);
48 if (mode2 != mode1)
49 htmlf("..%.6o", mode2);
50 }
51 htmlf("\n--- a/%s\n", path1);
52 htmlf("+++ b/%s\n", path2);
53 }
54}
55
56static void filepair_cb(struct diff_filepair *pair)
57{
58 header(pair->one->sha1, pair->one->path, pair->one->mode,
59 pair->two->sha1, pair->two->path, pair->two->mode);
60 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
61 if (S_ISGITLINK(pair->one->mode))
62 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
63 if (S_ISGITLINK(pair->two->mode))
64 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
65 return;
66 }
67 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
68 html("Error running diff");
69}
70
71void cgit_print_patch(char *hex, struct cacheitem *item)
72{
73 struct commit *commit;
74 struct commitinfo *info;
75 unsigned char sha1[20], old_sha1[20];
76 char *patchname;
77
78 if (!hex)
79 hex = cgit_query_head;
80
81 if (get_sha1(hex, sha1)) {
82 cgit_print_error(fmt("Bad object id: %s", hex));
83 return;
84 }
85 commit = lookup_commit_reference(sha1);
86 if (!commit) {
87 cgit_print_error(fmt("Bad commit reference: %s", hex));
88 return;
89 }
90 info = cgit_parse_commit(commit);
91 hashcpy(old_sha1, commit->parents->item->object.sha1);
92
93 patchname = fmt("%s.patch", sha1_to_hex(sha1));
94 cgit_print_snapshot_start("text/plain", patchname, item);
95 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
96 htmlf("From: %s%s\n", info->author, info->author_email);
97 html("Date: ");
98 cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n");
99 htmlf("Subject: %s\n\n", info->subject);
100 if (info->msg && *info->msg) {
101 htmlf("%s", info->msg);
102 if (info->msg[strlen(info->msg) - 1] != '\n')
103 html("\n");
104 }
105 html("---\n");
106 cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL);
107 html("--\n");
108 htmlf("cgit %s\n", CGIT_VERSION);
109 cgit_free_commitinfo(info);
110}
diff --git a/ui-repolist.c b/ui-repolist.c
index 9aa5c1e..3e97ca9 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -50,13 +50,13 @@ void cgit_print_repolist(struct cacheitem *item)
50 if (cgit_enable_index_links) 50 if (cgit_enable_index_links)
51 columns++; 51 columns++;
52 52
53 cgit_print_docstart(cgit_root_title, item); 53 cgit_print_docstart(cgit_root_title, item);
54 cgit_print_pageheader(cgit_root_title, 0); 54 cgit_print_pageheader(cgit_root_title, 0);
55 55
56 html("<table class='list nowrap'>"); 56 html("<table summary='repository list' class='list nowrap'>");
57 if (cgit_index_header) { 57 if (cgit_index_header) {
58 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", 58 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>",
59 columns); 59 columns);
60 html_include(cgit_index_header); 60 html_include(cgit_index_header);
61 html("</td></tr>"); 61 html("</td></tr>");
62 } 62 }
diff --git a/ui-shared.c b/ui-shared.c
index 4944dfd..60aa2e3 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -269,12 +269,18 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
269 } 269 }
270 html("'>"); 270 html("'>");
271 html_txt(name); 271 html_txt(name);
272 html("</a>"); 272 html("</a>");
273} 273}
274 274
275void cgit_patch_link(char *name, char *title, char *class, char *head,
276 char *rev)
277{
278 reporevlink("patch", name, title, class, head, rev, NULL);
279}
280
275void cgit_object_link(struct object *obj) 281void cgit_object_link(struct object *obj)
276{ 282{
277 char *page, *arg, *url; 283 char *page, *arg, *url;
278 284
279 if (obj->type == OBJ_COMMIT) { 285 if (obj->type == OBJ_COMMIT) {
280 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 286 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
@@ -353,34 +359,36 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
353 htmlf("<span class='age-years'>%.0f years</span>", 359 htmlf("<span class='age-years'>%.0f years</span>",
354 secs * 1.0 / TM_YEAR); 360 secs * 1.0 / TM_YEAR);
355} 361}
356 362
357void cgit_print_docstart(char *title, struct cacheitem *item) 363void cgit_print_docstart(char *title, struct cacheitem *item)
358{ 364{
359 html("Content-Type: text/html; charset=utf-8\n"); 365 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
360 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 366 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
361 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 367 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
362 ttl_seconds(item->ttl))); 368 ttl_seconds(item->ttl)));
363 html("\n"); 369 html("\n");
364 html(cgit_doctype); 370 html(cgit_doctype);
365 html("<html>\n"); 371 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
366 html("<head>\n"); 372 html("<head>\n");
367 html("<title>"); 373 html("<title>");
368 html_txt(title); 374 html_txt(title);
369 html("</title>\n"); 375 html("</title>\n");
370 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 376 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
377 if (cgit_robots && *cgit_robots)
378 htmlf("<meta name='robots' content='%s'/>\n", cgit_robots);
371 html("<link rel='stylesheet' type='text/css' href='"); 379 html("<link rel='stylesheet' type='text/css' href='");
372 html_attr(cgit_css); 380 html_attr(cgit_css);
373 html("'/>\n"); 381 html("'/>\n");
374 html("</head>\n"); 382 html("</head>\n");
375 html("<body>\n"); 383 html("<body>\n");
376} 384}
377 385
378void cgit_print_docend() 386void cgit_print_docend()
379{ 387{
380 html("</td>\n</tr>\n<table>\n</body>\n</html>\n"); 388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
381} 389}
382 390
383int print_branch_option(const char *refname, const unsigned char *sha1, 391int print_branch_option(const char *refname, const unsigned char *sha1,
384 int flags, void *cb_data) 392 int flags, void *cb_data)
385{ 393{
386 char *name = (char *)refname; 394 char *name = (char *)refname;
@@ -412,13 +420,13 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
412 } else if (obj->type != OBJ_BLOB) { 420 } else if (obj->type != OBJ_BLOB) {
413 return 0; 421 return 0;
414 } else { 422 } else {
415 hashcpy(fileid, sha1); 423 hashcpy(fileid, sha1);
416 } 424 }
417 if (!*header) { 425 if (!*header) {
418 html("<p><h1>download</h1>"); 426 html("<h1>download</h1>\n");
419 *header = 1; 427 *header = 1;
420 } 428 }
421 url = cgit_pageurl(cgit_query_repo, "blob", 429 url = cgit_pageurl(cgit_query_repo, "blob",
422 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
423 buf)); 431 buf));
424 html_link_open(url, NULL, "menu"); 432 html_link_open(url, NULL, "menu");
@@ -455,55 +463,76 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
455} 463}
456 464
457void cgit_print_pageheader(char *title, int show_search) 465void cgit_print_pageheader(char *title, int show_search)
458{ 466{
459 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 467 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
460 int header = 0; 468 int header = 0;
469 char *url;
461 470
462 html("<div id='sidebar'>\n"); 471 html("<table id='layout' summary=''>\n");
463 html("<a href='"); 472 html("<tr><td id='sidebar'>\n");
473 html("<table class='sidebar' cellspacing='0' summary=''>\n");
474 html("<tr><td class='sidebar'>\n<a href='");
464 html_attr(cgit_rooturl()); 475 html_attr(cgit_rooturl());
465 htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", 476 htmlf("'><img src='%s' alt='cgit'/></a>\n",
466 cgit_logo); 477 cgit_logo);
467 html("<div class='infobox'>"); 478 html("</td></tr>\n<tr><td class='sidebar'>\n");
468 if (cgit_query_repo) { 479 if (cgit_query_repo) {
469 html("<h1>"); 480 html("<h1 class='first'>");
470 html_txt(strrpart(cgit_repo->name, 20)); 481 html_txt(strrpart(cgit_repo->name, 20));
471 html("</h1>\n"); 482 html("</h1>\n");
472 html_txt(cgit_repo->desc); 483 html_txt(cgit_repo->desc);
473 if (cgit_repo->owner) { 484 if (cgit_repo->owner) {
474 html("<p>\n<h1>owner</h1>\n"); 485 html("<h1>owner</h1>\n");
475 html_txt(cgit_repo->owner); 486 html_txt(cgit_repo->owner);
476 } 487 }
477 html("<p>\n<h1>navigate</h1>\n"); 488 html("<h1>navigate</h1>\n");
478 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 489 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head,
479 NULL, NULL); 490 NULL, NULL);
480 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, 491 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL,
481 0, NULL, NULL); 492 0, NULL, NULL);
482 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 493 cgit_tree_link("tree", NULL, "menu", cgit_query_head,
483 cgit_query_sha1, NULL); 494 cgit_query_sha1, NULL);
484 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 495 cgit_commit_link("commit", NULL, "menu", cgit_query_head,
485 cgit_query_sha1); 496 cgit_query_sha1);
486 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 497 cgit_diff_link("diff", NULL, "menu", cgit_query_head,
487 cgit_query_sha1, cgit_query_sha2, NULL); 498 cgit_query_sha1, cgit_query_sha2, NULL);
499 cgit_patch_link("patch", NULL, "menu", cgit_query_head,
500 cgit_query_sha1);
488 501
489 for_each_ref(print_archive_ref, &header); 502 for_each_ref(print_archive_ref, &header);
490 503
491 html("<p>\n<h1>branch</h1>\n"); 504 if (cgit_repo->clone_url || cgit_clone_prefix) {
505 html("<h1>clone</h1>\n");
506 if (cgit_repo->clone_url)
507 url = cgit_repo->clone_url;
508 else
509 url = fmt("%s%s", cgit_clone_prefix,
510 cgit_repo->url);
511 html("<a class='menu' href='");
512 html_attr(url);
513 html("' title='");
514 html_attr(url);
515 html("'>\n");
516 html_txt(strrpart(url, 20));
517 html("</a>\n");
518 }
519
520 html("<h1>branch</h1>\n");
492 html("<form method='get' action=''>\n"); 521 html("<form method='get' action=''>\n");
493 add_hidden_formfields(0, 1, cgit_query_page); 522 add_hidden_formfields(0, 1, cgit_query_page);
494 html("<table class='grid'><tr><td id='branch-dropdown-cell'>"); 523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
495 html("<select name='h' onchange='this.form.submit();'>\n"); 524 html("<select name='h' onchange='this.form.submit();'>\n");
496 for_each_branch_ref(print_branch_option, cgit_query_head); 525 for_each_branch_ref(print_branch_option, cgit_query_head);
497 html("</select>\n"); 526 html("</select>\n");
498 html("</td><td>"); 527 // html("</td><td>");
499 html("<noscript><input type='submit' id='switch-btn' value='..'></noscript>\n"); 528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
500 html("</td></tr></table>"); 529 // html("</td></tr></table>");
501 html("</form>\n"); 530 html("</form>\n");
502 531
503 html("<p>\n<h1>search</h1>\n"); 532 html("<h1>search</h1>\n");
504 html("<form method='get' action='"); 533 html("<form method='get' action='");
505 if (cgit_virtual_root) 534 if (cgit_virtual_root)
506 html_attr(cgit_fileurl(cgit_query_repo, "log", 535 html_attr(cgit_fileurl(cgit_query_repo, "log",
507 cgit_query_path, NULL)); 536 cgit_query_path, NULL));
508 html("'>\n"); 537 html("'>\n");
509 add_hidden_formfields(1, 0, "log"); 538 add_hidden_formfields(1, 0, "log");
@@ -518,15 +547,15 @@ void cgit_print_pageheader(char *title, int show_search)
518 html("</form>\n"); 547 html("</form>\n");
519 } else { 548 } else {
520 if (!cgit_index_info || html_include(cgit_index_info)) 549 if (!cgit_index_info || html_include(cgit_index_info))
521 html(default_info); 550 html(default_info);
522 } 551 }
523 552
524 html("</div>\n"); 553 html("</td></tr></table></td>\n");
525 554
526 html("</div>\n<table class='grid'><tr><td id='content'>\n"); 555 html("<td id='content'>\n");
527} 556}
528 557
529 558
530void cgit_print_snapshot_start(const char *mimetype, const char *filename, 559void cgit_print_snapshot_start(const char *mimetype, const char *filename,
531 struct cacheitem *item) 560 struct cacheitem *item)
532{ 561{
diff --git a/ui-summary.c b/ui-summary.c
index c856793..b96414e 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -187,13 +187,13 @@ void cgit_print_summary()
187 html_include(cgit_repo->readme); 187 html_include(cgit_repo->readme);
188 html("</div>"); 188 html("</div>");
189 } 189 }
190 if (cgit_summary_log > 0) 190 if (cgit_summary_log > 0)
191 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, 191 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL,
192 NULL, NULL, 0); 192 NULL, NULL, 0);
193 html("<table class='list nowrap'>"); 193 html("<table summary='repository info' class='list nowrap'>");
194 if (cgit_summary_log > 0) 194 if (cgit_summary_log > 0)
195 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 195 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
196 cgit_print_branches(cgit_summary_branches); 196 cgit_print_branches(cgit_summary_branches);
197 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 197 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
198 cgit_print_tags(cgit_summary_tags); 198 cgit_print_tags(cgit_summary_tags);
199 html("</table>"); 199 html("</table>");
diff --git a/ui-tree.c b/ui-tree.c
index c22e30b..c138877 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -14,13 +14,13 @@ int header = 0;
14 14
15static void print_object(const unsigned char *sha1, char *path) 15static void print_object(const unsigned char *sha1, char *path)
16{ 16{
17 enum object_type type; 17 enum object_type type;
18 char *buf; 18 char *buf;
19 unsigned long size, lineno, start, idx; 19 unsigned long size, lineno, start, idx;
20 const char *linefmt = "<tr><td class='no'><a name='%1$d'>%1$d</a></td><td class='txt'>"; 20 const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>";
21 21
22 type = sha1_object_info(sha1, &size); 22 type = sha1_object_info(sha1, &size);
23 if (type == OBJ_BAD) { 23 if (type == OBJ_BAD) {
24 cgit_print_error(fmt("Bad object name: %s", 24 cgit_print_error(fmt("Bad object name: %s",
25 sha1_to_hex(sha1))); 25 sha1_to_hex(sha1)));
26 return; 26 return;
@@ -34,13 +34,13 @@ static void print_object(const unsigned char *sha1, char *path)
34 } 34 }
35 35
36 html(" blob: <a href='"); 36 html(" blob: <a href='");
37 html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); 37 html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1))));
38 htmlf("'>%s</a>",sha1_to_hex(sha1)); 38 htmlf("'>%s</a>",sha1_to_hex(sha1));
39 39
40 html("<table class='blob'>\n"); 40 html("<table summary='blob content' class='blob'>\n");
41 idx = 0; 41 idx = 0;
42 start = 0; 42 start = 0;
43 lineno = 0; 43 lineno = 0;
44 while(idx < size) { 44 while(idx < size) {
45 if (buf[idx] == '\n') { 45 if (buf[idx] == '\n') {
46 buf[idx] = '\0'; 46 buf[idx] = '\0';
@@ -105,13 +105,13 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
105 free(name); 105 free(name);
106 return 0; 106 return 0;
107} 107}
108 108
109static void ls_head() 109static void ls_head()
110{ 110{
111 html("<table class='list'>\n"); 111 html("<table summary='tree listing' class='list'>\n");
112 html("<tr class='nohover'>"); 112 html("<tr class='nohover'>");
113 html("<th class='left'>Mode</th>"); 113 html("<th class='left'>Mode</th>");
114 html("<th class='left'>Name</th>"); 114 html("<th class='left'>Name</th>");
115 html("<th class='right'>Size</th>"); 115 html("<th class='right'>Size</th>");
116 html("<th/>"); 116 html("<th/>");
117 html("</tr>\n"); 117 html("</tr>\n");