summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css6
-rw-r--r--html.c2
-rwxr-xr-xtests/t0104-tree.sh10
-rwxr-xr-xtests/t0105-commit.sh2
-rw-r--r--ui-commit.c6
-rw-r--r--ui-diff.c2
-rw-r--r--ui-log.c2
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c24
-rw-r--r--ui-summary.c2
-rw-r--r--ui-tree.c6
11 files changed, 37 insertions, 27 deletions
diff --git a/cgit.css b/cgit.css
index f1003b4..565427f 100644
--- a/cgit.css
+++ b/cgit.css
@@ -18,193 +18,197 @@ table {
18h2 { 18h2 {
19 font-size: 120%; 19 font-size: 120%;
20 font-weight: bold; 20 font-weight: bold;
21 margin-top: 0em; 21 margin-top: 0em;
22 margin-bottom: 0.25em; 22 margin-bottom: 0.25em;
23} 23}
24 24
25h3 { 25h3 {
26 margin-top: 0em; 26 margin-top: 0em;
27 font-size: 100%; 27 font-size: 100%;
28 font-weight: normal; 28 font-weight: normal;
29} 29}
30 30
31h4 { 31h4 {
32 margin-top: 1.5em; 32 margin-top: 1.5em;
33 margin-bottom: 0.1em; 33 margin-bottom: 0.1em;
34 font-size: 100%; 34 font-size: 100%;
35 font-weight: bold; 35 font-weight: bold;
36} 36}
37 37
38a { 38a {
39 color: #600; 39 color: #600;
40 text-decoration: none; 40 text-decoration: none;
41} 41}
42 42
43a:hover { 43a:hover {
44 background-color: #ddd; 44 background-color: #ddd;
45 text-decoration: none; 45 text-decoration: none;
46} 46}
47 47
48table.list { 48table.list {
49 border: none; 49 border: none;
50 border-collapse: collapse; 50 border-collapse: collapse;
51} 51}
52 52
53table.list tr { 53table.list tr {
54 background: white; 54 background: white;
55} 55}
56 56
57table.list tr:hover { 57table.list tr:hover {
58 background: #f8f8f8; 58 background: #f8f8f8;
59} 59}
60 60
61table.list tr.nohover:hover { 61table.list tr.nohover:hover {
62 background: white; 62 background: white;
63} 63}
64 64
65table.list th { 65table.list th {
66 font-weight: bold; 66 font-weight: bold;
67 border-bottom: solid 1px #777; 67 border-bottom: solid 1px #777;
68 padding: 0.1em 0.5em 0.1em 0.5em; 68 padding: 0.1em 0.5em 0.1em 0.5em;
69 vertical-align: baseline; 69 vertical-align: baseline;
70} 70}
71 71
72table.list td { 72table.list td {
73 border: none; 73 border: none;
74 padding: 0.1em 0.5em 0.1em 0.5em; 74 padding: 0.1em 0.5em 0.1em 0.5em;
75} 75}
76 76
77img { 77img {
78 border: none; 78 border: none;
79} 79}
80 80
81div#sidebar { 81div#sidebar {
82 vertical-align: top; 82 vertical-align: top;
83 width: 162px; 83 width: 162px;
84 padding: 0px 0px 0px 0px; 84 padding: 0px 0px 0px 0px;
85 margin: 4px; 85 margin: 4px;
86 float: left; 86 float: left;
87} 87}
88 88
89div#logo { 89div#logo {
90 margin: 0px; 90 margin: 0px;
91 padding: 4px 0px 4px 0px; 91 padding: 4px 0px 4px 0px;
92 text-align: center; 92 text-align: center;
93 background-color: #ccc; 93 background-color: #ccc;
94 border-top: solid 1px #eee; 94 border-top: solid 1px #eee;
95 border-left: solid 1px #eee; 95 border-left: solid 1px #eee;
96 border-right: solid 1px #aaa; 96 border-right: solid 1px #aaa;
97 border-bottom: solid 1px #aaa; 97 border-bottom: solid 1px #aaa;
98} 98}
99 99
100div#sidebar div.infobox { 100div#sidebar div.infobox {
101 margin: 0px 0px 0px 0px; 101 margin: 0px 0px 0px 0px;
102 padding: 0.5em; 102 padding: 0.5em;
103 text-align: left; 103 text-align: left;
104 background-color: #ccc; 104 background-color: #ccc;
105 border-top: solid 1px #eee; 105 border-top: solid 1px #eee;
106 border-left: solid 1px #eee; 106 border-left: solid 1px #eee;
107 border-right: solid 1px #aaa; 107 border-right: solid 1px #aaa;
108 border-bottom: solid 1px #aaa; 108 border-bottom: solid 1px #aaa;
109} 109}
110 110
111div#sidebar div.infobox h1 { 111div#sidebar div.infobox h1 {
112 font-size: 10pt; 112 font-size: 10pt;
113 font-weight: bold; 113 font-weight: bold;
114 margin: 0px; 114 margin: 8px 0px 0px 0px;
115}
116
117div#sidebar div.infobox h1.first {
118 margin-top: 0px;
115} 119}
116 120
117div#sidebar div.infobox a.menu { 121div#sidebar div.infobox a.menu {
118 display: block; 122 display: block;
119 background-color: #ccc; 123 background-color: #ccc;
120 padding: 0.1em 0.5em; 124 padding: 0.1em 0.5em;
121 text-decoration: none; 125 text-decoration: none;
122} 126}
123 127
124div#sidebar div.infobox a.menu:hover { 128div#sidebar div.infobox a.menu:hover {
125 background-color: #bbb; 129 background-color: #bbb;
126 text-decoration: none; 130 text-decoration: none;
127} 131}
128 132
129div#sidebar div.infobox select { 133div#sidebar div.infobox select {
130 width: 100%; 134 width: 100%;
131 margin: 2px 0px 0px 0px; 135 margin: 2px 0px 0px 0px;
132} 136}
133 137
134td#branch-dropdown-cell { 138td#branch-dropdown-cell {
135 width: 99%; 139 width: 99%;
136} 140}
137 141
138input#switch-btn { 142input#switch-btn {
139 width: 20px; 143 width: 20px;
140 margin: 2px 0px 0px 0px; 144 margin: 2px 0px 0px 0px;
141} 145}
142 146
143div#sidebar div.infobox input.txt { 147div#sidebar div.infobox input.txt {
144 width: 100%; 148 width: 100%;
145 margin: 2px 0px 0px 0px; 149 margin: 2px 0px 0px 0px;
146} 150}
147 151
148table#grid { 152table#grid {
149 margin: 0px; 153 margin: 0px;
150} 154}
151 155
152td#content { 156td#content {
153 vertical-align: top; 157 vertical-align: top;
154 padding: 1em 2em 1em 1em; 158 padding: 1em 2em 1em 1em;
155 border: none; 159 border: none;
156} 160}
157 161
158div#summary { 162div#summary {
159 vertical-align: top; 163 vertical-align: top;
160 margin-bottom: 1em; 164 margin-bottom: 1em;
161} 165}
162 166
163table#downloads { 167table#downloads {
164 float: right; 168 float: right;
165 border-collapse: collapse; 169 border-collapse: collapse;
166 border: solid 1px #777; 170 border: solid 1px #777;
167 margin-left: 0.5em; 171 margin-left: 0.5em;
168 margin-bottom: 0.5em; 172 margin-bottom: 0.5em;
169} 173}
170 174
171table#downloads th { 175table#downloads th {
172 background-color: #ccc; 176 background-color: #ccc;
173} 177}
174 178
175div#blob { 179div#blob {
176 border: solid 1px black; 180 border: solid 1px black;
177} 181}
178 182
179div.error { 183div.error {
180 color: red; 184 color: red;
181 font-weight: bold; 185 font-weight: bold;
182 margin: 1em 2em; 186 margin: 1em 2em;
183} 187}
184 188
185a.ls-blob, a.ls-dir, a.ls-mod { 189a.ls-blob, a.ls-dir, a.ls-mod {
186 font-family: monospace; 190 font-family: monospace;
187} 191}
188 192
189td.ls-size { 193td.ls-size {
190 text-align: right; 194 text-align: right;
191} 195}
192 196
193td.ls-size { 197td.ls-size {
194 font-family: monospace; 198 font-family: monospace;
195} 199}
196 200
197td.ls-mode { 201td.ls-mode {
198 font-family: monospace; 202 font-family: monospace;
199} 203}
200 204
201table.blob { 205table.blob {
202 margin-top: 0.5em; 206 margin-top: 0.5em;
203 border-top: solid 1px black; 207 border-top: solid 1px black;
204} 208}
205 209
206table.blob td.no { 210table.blob td.no {
207 border-right: solid 1px black; 211 border-right: solid 1px black;
208 color: black; 212 color: black;
209 background-color: #eee; 213 background-color: #eee;
210 text-align: right; 214 text-align: right;
diff --git a/html.c b/html.c
index 6c9cc8b..eb163d9 100644
--- a/html.c
+++ b/html.c
@@ -39,156 +39,156 @@ void htmlf(const char *format, ...)
39 va_start(args, format); 39 va_start(args, format);
40 vsnprintf(buf, sizeof(buf), format, args); 40 vsnprintf(buf, sizeof(buf), format, args);
41 va_end(args); 41 va_end(args);
42 html(buf); 42 html(buf);
43} 43}
44 44
45void html_txt(char *txt) 45void html_txt(char *txt)
46{ 46{
47 char *t = txt; 47 char *t = txt;
48 while(t && *t){ 48 while(t && *t){
49 int c = *t; 49 int c = *t;
50 if (c=='<' || c=='>' || c=='&') { 50 if (c=='<' || c=='>' || c=='&') {
51 *t = '\0'; 51 *t = '\0';
52 html(txt); 52 html(txt);
53 *t = c; 53 *t = c;
54 if (c=='>') 54 if (c=='>')
55 html("&gt;"); 55 html("&gt;");
56 else if (c=='<') 56 else if (c=='<')
57 html("&lt;"); 57 html("&lt;");
58 else if (c=='&') 58 else if (c=='&')
59 html("&amp;"); 59 html("&amp;");
60 txt = t+1; 60 txt = t+1;
61 } 61 }
62 t++; 62 t++;
63 } 63 }
64 if (t!=txt) 64 if (t!=txt)
65 html(txt); 65 html(txt);
66} 66}
67 67
68void html_ntxt(int len, char *txt) 68void html_ntxt(int len, char *txt)
69{ 69{
70 char *t = txt; 70 char *t = txt;
71 while(t && *t && len--){ 71 while(t && *t && len--){
72 int c = *t; 72 int c = *t;
73 if (c=='<' || c=='>' || c=='&') { 73 if (c=='<' || c=='>' || c=='&') {
74 *t = '\0'; 74 *t = '\0';
75 html(txt); 75 html(txt);
76 *t = c; 76 *t = c;
77 if (c=='>') 77 if (c=='>')
78 html("&gt;"); 78 html("&gt;");
79 else if (c=='<') 79 else if (c=='<')
80 html("&lt;"); 80 html("&lt;");
81 else if (c=='&') 81 else if (c=='&')
82 html("&amp;"); 82 html("&amp;");
83 txt = t+1; 83 txt = t+1;
84 } 84 }
85 t++; 85 t++;
86 } 86 }
87 if (t!=txt) { 87 if (t!=txt) {
88 char c = *t; 88 char c = *t;
89 *t = '\0'; 89 *t = '\0';
90 html(txt); 90 html(txt);
91 *t = c; 91 *t = c;
92 } 92 }
93 if (len<0) 93 if (len<0)
94 html("..."); 94 html("...");
95} 95}
96 96
97void html_attr(char *txt) 97void html_attr(char *txt)
98{ 98{
99 char *t = txt; 99 char *t = txt;
100 while(t && *t){ 100 while(t && *t){
101 int c = *t; 101 int c = *t;
102 if (c=='<' || c=='>' || c=='\'') { 102 if (c=='<' || c=='>' || c=='\'') {
103 *t = '\0'; 103 *t = '\0';
104 html(txt); 104 html(txt);
105 *t = c; 105 *t = c;
106 if (c=='>') 106 if (c=='>')
107 html("&gt;"); 107 html("&gt;");
108 else if (c=='<') 108 else if (c=='<')
109 html("&lt;"); 109 html("&lt;");
110 else if (c=='\'') 110 else if (c=='\'')
111 html("&quote;"); 111 html("&quote;");
112 txt = t+1; 112 txt = t+1;
113 } 113 }
114 t++; 114 t++;
115 } 115 }
116 if (t!=txt) 116 if (t!=txt)
117 html(txt); 117 html(txt);
118} 118}
119 119
120void html_hidden(char *name, char *value) 120void html_hidden(char *name, char *value)
121{ 121{
122 html("<input type='hidden' name='"); 122 html("<input type='hidden' name='");
123 html_attr(name); 123 html_attr(name);
124 html("' value='"); 124 html("' value='");
125 html_attr(value); 125 html_attr(value);
126 html("'/>"); 126 html("'/>");
127} 127}
128 128
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)
142{ 142{
143 html("<a href='"); 143 html("<a href='");
144 html_attr(url); 144 html_attr(url);
145 if (title) { 145 if (title) {
146 html("' title='"); 146 html("' title='");
147 html_attr(title); 147 html_attr(title);
148 } 148 }
149 if (class) { 149 if (class) {
150 html("' class='"); 150 html("' class='");
151 html_attr(class); 151 html_attr(class);
152 } 152 }
153 html("'>"); 153 html("'>");
154} 154}
155 155
156void html_link_close(void) 156void html_link_close(void)
157{ 157{
158 html("</a>"); 158 html("</a>");
159} 159}
160 160
161void html_fileperm(unsigned short mode) 161void html_fileperm(unsigned short mode)
162{ 162{
163 htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), 163 htmlf("%c%c%c", (mode & 4 ? 'r' : '-'),
164 (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); 164 (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-'));
165} 165}
166 166
167void html_filemode(unsigned short mode) 167void html_filemode(unsigned short mode)
168{ 168{
169 if (S_ISDIR(mode)) 169 if (S_ISDIR(mode))
170 html("d"); 170 html("d");
171 else if (S_ISLNK(mode)) 171 else if (S_ISLNK(mode))
172 html("l"); 172 html("l");
173 else if (S_ISGITLINK(mode)) 173 else if (S_ISGITLINK(mode))
174 html("m"); 174 html("m");
175 else 175 else
176 html("-"); 176 html("-");
177 html_fileperm(mode >> 6); 177 html_fileperm(mode >> 6);
178 html_fileperm(mode >> 3); 178 html_fileperm(mode >> 3);
179 html_fileperm(mode); 179 html_fileperm(mode);
180} 180}
181 181
182int html_include(const char *filename) 182int html_include(const char *filename)
183{ 183{
184 FILE *f; 184 FILE *f;
185 char buf[4096]; 185 char buf[4096];
186 size_t len; 186 size_t len;
187 187
188 if (!(f = fopen(filename, "r"))) 188 if (!(f = fopen(filename, "r")))
189 return -1; 189 return -1;
190 while((len = fread(buf, 1, 4096, f)) > 0) 190 while((len = fread(buf, 1, 4096, f)) > 0)
191 write(htmlfd, buf, len); 191 write(htmlfd, buf, len);
192 fclose(f); 192 fclose(f);
193 return 0; 193 return 0;
194} 194}
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
index 9c362ca..2516c72 100755
--- a/tests/t0104-tree.sh
+++ b/tests/t0104-tree.sh
@@ -1,15 +1,21 @@
1#!/bin/sh 1#!/bin/sh
2 2
3. ./setup.sh 3. ./setup.sh
4 4
5prepare_tests "Check content on tree page" 5prepare_tests "Check content on tree page"
6 6
7run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp' 7run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp'
8run_test 'find file-1' 'grep -e "file-1" trash/tmp' 8run_test 'find file-1' 'grep -e "file-1" trash/tmp'
9run_test 'find file-50' 'grep -e "file-50" trash/tmp' 9run_test 'find file-50' 'grep -e "file-50" trash/tmp'
10 10
11run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp' 11run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'
12run_test 'find line 1' 'grep -e "<a name=.1.>1</a>" trash/tmp' 12
13run_test 'no line 2' 'grep -ve "<a name=.2.>2</a>" trash/tmp' 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'
14 20
15tests_done 21tests_done
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh
index 7137751..aa2bf33 100755
--- a/tests/t0105-commit.sh
+++ b/tests/t0105-commit.sh
@@ -1,22 +1,22 @@
1#!/bin/sh 1#!/bin/sh
2 2
3. ./setup.sh 3. ./setup.sh
4 4
5prepare_tests "Check content on commit page" 5prepare_tests "Check content on commit page"
6 6
7run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp' 7run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp'
8run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" 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' 9run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp'
10 10
11run_test 'find commit subject' ' 11run_test 'find commit subject' '
12 grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp 12 grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp
13' 13'
14 14
15run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp' 15run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp'
16run_test 'find diffstat' 'grep -e "<table class=.diffstat.>" trash/tmp' 16run_test 'find diffstat' 'grep -e "<table summary=.diffstat. class=.diffstat.>" trash/tmp'
17 17
18run_test 'find diff summary' ' 18run_test 'find diff summary' '
19 grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp 19 grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp
20' 20'
21 21
22tests_done 22tests_done
diff --git a/ui-commit.c b/ui-commit.c
index 4ac8955..bd55a33 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -1,226 +1,226 @@
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 10
11static int files, slots; 11static int files, slots;
12static int total_adds, total_rems, max_changes; 12static int total_adds, total_rems, max_changes;
13static int lines_added, lines_removed; 13static int lines_added, lines_removed;
14static char *curr_rev; 14static char *curr_rev;
15 15
16static struct fileinfo { 16static struct fileinfo {
17 char status; 17 char status;
18 unsigned char old_sha1[20]; 18 unsigned char old_sha1[20];
19 unsigned char new_sha1[20]; 19 unsigned char new_sha1[20];
20 unsigned short old_mode; 20 unsigned short old_mode;
21 unsigned short new_mode; 21 unsigned short new_mode;
22 char *old_path; 22 char *old_path;
23 char *new_path; 23 char *new_path;
24 unsigned int added; 24 unsigned int added;
25 unsigned int removed; 25 unsigned int removed;
26} *items; 26} *items;
27 27
28 28
29void print_fileinfo(struct fileinfo *info) 29void print_fileinfo(struct fileinfo *info)
30{ 30{
31 char *class; 31 char *class;
32 32
33 switch (info->status) { 33 switch (info->status) {
34 case DIFF_STATUS_ADDED: 34 case DIFF_STATUS_ADDED:
35 class = "add"; 35 class = "add";
36 break; 36 break;
37 case DIFF_STATUS_COPIED: 37 case DIFF_STATUS_COPIED:
38 class = "cpy"; 38 class = "cpy";
39 break; 39 break;
40 case DIFF_STATUS_DELETED: 40 case DIFF_STATUS_DELETED:
41 class = "del"; 41 class = "del";
42 break; 42 break;
43 case DIFF_STATUS_MODIFIED: 43 case DIFF_STATUS_MODIFIED:
44 class = "upd"; 44 class = "upd";
45 break; 45 break;
46 case DIFF_STATUS_RENAMED: 46 case DIFF_STATUS_RENAMED:
47 class = "mov"; 47 class = "mov";
48 break; 48 break;
49 case DIFF_STATUS_TYPE_CHANGED: 49 case DIFF_STATUS_TYPE_CHANGED:
50 class = "typ"; 50 class = "typ";
51 break; 51 break;
52 case DIFF_STATUS_UNKNOWN: 52 case DIFF_STATUS_UNKNOWN:
53 class = "unk"; 53 class = "unk";
54 break; 54 break;
55 case DIFF_STATUS_UNMERGED: 55 case DIFF_STATUS_UNMERGED:
56 class = "stg"; 56 class = "stg";
57 break; 57 break;
58 default: 58 default:
59 die("bug: unhandled diff status %c", info->status); 59 die("bug: unhandled diff status %c", info->status);
60 } 60 }
61 61
62 html("<tr>"); 62 html("<tr>");
63 htmlf("<td class='mode'>"); 63 htmlf("<td class='mode'>");
64 if (is_null_sha1(info->new_sha1)) { 64 if (is_null_sha1(info->new_sha1)) {
65 html_filemode(info->old_mode); 65 html_filemode(info->old_mode);
66 } else { 66 } else {
67 html_filemode(info->new_mode); 67 html_filemode(info->new_mode);
68 } 68 }
69 69
70 if (info->old_mode != info->new_mode && 70 if (info->old_mode != info->new_mode &&
71 !is_null_sha1(info->old_sha1) && 71 !is_null_sha1(info->old_sha1) &&
72 !is_null_sha1(info->new_sha1)) { 72 !is_null_sha1(info->new_sha1)) {
73 html("<span class='modechange'>["); 73 html("<span class='modechange'>[");
74 html_filemode(info->old_mode); 74 html_filemode(info->old_mode);
75 html("]</span>"); 75 html("]</span>");
76 } 76 }
77 htmlf("</td><td class='%s'>", class); 77 htmlf("</td><td class='%s'>", class);
78 cgit_diff_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev, 78 cgit_diff_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev,
79 NULL, info->new_path); 79 NULL, info->new_path);
80 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) 80 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
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);
94 html("</tr></table></td></tr>\n"); 94 html("</tr></table></td></tr>\n");
95} 95}
96 96
97void cgit_count_diff_lines(char *line, int len) 97void cgit_count_diff_lines(char *line, int len)
98{ 98{
99 if (line && (len > 0)) { 99 if (line && (len > 0)) {
100 if (line[0] == '+') 100 if (line[0] == '+')
101 lines_added++; 101 lines_added++;
102 else if (line[0] == '-') 102 else if (line[0] == '-')
103 lines_removed++; 103 lines_removed++;
104 } 104 }
105} 105}
106 106
107void inspect_filepair(struct diff_filepair *pair) 107void inspect_filepair(struct diff_filepair *pair)
108{ 108{
109 files++; 109 files++;
110 lines_added = 0; 110 lines_added = 0;
111 lines_removed = 0; 111 lines_removed = 0;
112 cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); 112 cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines);
113 if (files >= slots) { 113 if (files >= slots) {
114 if (slots == 0) 114 if (slots == 0)
115 slots = 4; 115 slots = 4;
116 else 116 else
117 slots = slots * 2; 117 slots = slots * 2;
118 items = xrealloc(items, slots * sizeof(struct fileinfo)); 118 items = xrealloc(items, slots * sizeof(struct fileinfo));
119 } 119 }
120 items[files-1].status = pair->status; 120 items[files-1].status = pair->status;
121 hashcpy(items[files-1].old_sha1, pair->one->sha1); 121 hashcpy(items[files-1].old_sha1, pair->one->sha1);
122 hashcpy(items[files-1].new_sha1, pair->two->sha1); 122 hashcpy(items[files-1].new_sha1, pair->two->sha1);
123 items[files-1].old_mode = pair->one->mode; 123 items[files-1].old_mode = pair->one->mode;
124 items[files-1].new_mode = pair->two->mode; 124 items[files-1].new_mode = pair->two->mode;
125 items[files-1].old_path = xstrdup(pair->one->path); 125 items[files-1].old_path = xstrdup(pair->one->path);
126 items[files-1].new_path = xstrdup(pair->two->path); 126 items[files-1].new_path = xstrdup(pair->two->path);
127 items[files-1].added = lines_added; 127 items[files-1].added = lines_added;
128 items[files-1].removed = lines_removed; 128 items[files-1].removed = lines_removed;
129 if (lines_added + lines_removed > max_changes) 129 if (lines_added + lines_removed > max_changes)
130 max_changes = lines_added + lines_removed; 130 max_changes = lines_added + lines_removed;
131 total_adds += lines_added; 131 total_adds += lines_added;
132 total_rems += lines_removed; 132 total_rems += lines_removed;
133} 133}
134 134
135 135
136void cgit_print_commit(char *hex) 136void cgit_print_commit(char *hex)
137{ 137{
138 struct commit *commit, *parent; 138 struct commit *commit, *parent;
139 struct commitinfo *info; 139 struct commitinfo *info;
140 struct commit_list *p; 140 struct commit_list *p;
141 unsigned char sha1[20]; 141 unsigned char sha1[20];
142 char *tmp; 142 char *tmp;
143 int i; 143 int i;
144 144
145 if (!hex) 145 if (!hex)
146 hex = cgit_query_head; 146 hex = cgit_query_head;
147 curr_rev = hex; 147 curr_rev = hex;
148 148
149 if (get_sha1(hex, sha1)) { 149 if (get_sha1(hex, sha1)) {
150 cgit_print_error(fmt("Bad object id: %s", hex)); 150 cgit_print_error(fmt("Bad object id: %s", hex));
151 return; 151 return;
152 } 152 }
153 commit = lookup_commit_reference(sha1); 153 commit = lookup_commit_reference(sha1);
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);
167 html("</td></tr>\n"); 167 html("</td></tr>\n");
168 html("<tr><th>committer</th><td>"); 168 html("<tr><th>committer</th><td>");
169 html_txt(info->committer); 169 html_txt(info->committer);
170 html(" "); 170 html(" ");
171 html_txt(info->committer_email); 171 html_txt(info->committer_email);
172 html("</td><td class='right'>"); 172 html("</td><td class='right'>");
173 cgit_print_date(info->committer_date, FMT_LONGDATE); 173 cgit_print_date(info->committer_date, FMT_LONGDATE);
174 html("</td></tr>\n"); 174 html("</td></tr>\n");
175 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 175 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
176 tmp = xstrdup(hex); 176 tmp = xstrdup(hex);
177 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, 177 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
178 cgit_query_head, tmp, NULL); 178 cgit_query_head, tmp, NULL);
179 html("</td></tr>\n"); 179 html("</td></tr>\n");
180 for (p = commit->parents; p ; p = p->next) { 180 for (p = commit->parents; p ; p = p->next) {
181 parent = lookup_commit_reference(p->item->object.sha1); 181 parent = lookup_commit_reference(p->item->object.sha1);
182 if (!parent) { 182 if (!parent) {
183 html("<tr><td colspan='3'>"); 183 html("<tr><td colspan='3'>");
184 cgit_print_error("Error reading parent commit"); 184 cgit_print_error("Error reading parent commit");
185 html("</td></tr>"); 185 html("</td></tr>");
186 continue; 186 continue;
187 } 187 }
188 html("<tr><th>parent</th>" 188 html("<tr><th>parent</th>"
189 "<td colspan='2' class='sha1'>"); 189 "<td colspan='2' class='sha1'>");
190 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, 190 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
191 cgit_query_head, sha1_to_hex(p->item->object.sha1)); 191 cgit_query_head, sha1_to_hex(p->item->object.sha1));
192 html(" ("); 192 html(" (");
193 cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, 193 cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex,
194 sha1_to_hex(p->item->object.sha1), NULL); 194 sha1_to_hex(p->item->object.sha1), NULL);
195 html(")</td></tr>"); 195 html(")</td></tr>");
196 } 196 }
197 if (cgit_repo->snapshots) { 197 if (cgit_repo->snapshots) {
198 html("<tr><th>download</th><td colspan='2' class='sha1'>"); 198 html("<tr><th>download</th><td colspan='2' class='sha1'>");
199 cgit_print_snapshot_links(cgit_query_repo, cgit_query_head, 199 cgit_print_snapshot_links(cgit_query_repo, cgit_query_head,
200 hex, cgit_repo->snapshots); 200 hex, cgit_repo->snapshots);
201 html("</td></tr>"); 201 html("</td></tr>");
202 } 202 }
203 html("</table>\n"); 203 html("</table>\n");
204 html("<div class='commit-subject'>"); 204 html("<div class='commit-subject'>");
205 html_txt(info->subject); 205 html_txt(info->subject);
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'>");
219 htmlf("%d files changed, %d insertions, %d deletions (", 219 htmlf("%d files changed, %d insertions, %d deletions (",
220 files, total_adds, total_rems); 220 files, total_adds, total_rems);
221 cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, 221 cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex,
222 NULL, NULL); 222 NULL, NULL);
223 html(")</div>"); 223 html(")</div>");
224 } 224 }
225 cgit_free_commitinfo(info); 225 cgit_free_commitinfo(info);
226} 226}
diff --git a/ui-diff.c b/ui-diff.c
index ac9a3fa..4fcf852 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -48,102 +48,102 @@ static void header(unsigned char *sha1, char *path1, int mode1,
48 html_txt(path2); 48 html_txt(path2);
49 49
50 if (is_null_sha1(sha1)) 50 if (is_null_sha1(sha1))
51 path1 = "dev/null"; 51 path1 = "dev/null";
52 if (is_null_sha1(sha2)) 52 if (is_null_sha1(sha2))
53 path2 = "dev/null"; 53 path2 = "dev/null";
54 54
55 if (mode1 == 0) 55 if (mode1 == 0)
56 htmlf("<br/>new file mode %.6o", mode2); 56 htmlf("<br/>new file mode %.6o", mode2);
57 57
58 if (mode2 == 0) 58 if (mode2 == 0)
59 htmlf("<br/>deleted file mode %.6o", mode1); 59 htmlf("<br/>deleted file mode %.6o", mode1);
60 60
61 if (!subproject) { 61 if (!subproject) {
62 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); 62 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
63 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); 63 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
64 htmlf("<br/>index %s..%s", abbrev1, abbrev2); 64 htmlf("<br/>index %s..%s", abbrev1, abbrev2);
65 free(abbrev1); 65 free(abbrev1);
66 free(abbrev2); 66 free(abbrev2);
67 if (mode1 != 0 && mode2 != 0) { 67 if (mode1 != 0 && mode2 != 0) {
68 htmlf(" %.6o", mode1); 68 htmlf(" %.6o", mode1);
69 if (mode2 != mode1) 69 if (mode2 != mode1)
70 htmlf("..%.6o", mode2); 70 htmlf("..%.6o", mode2);
71 } 71 }
72 html("<br/>--- a/"); 72 html("<br/>--- a/");
73 if (mode1 != 0) 73 if (mode1 != 0)
74 cgit_tree_link(path1, NULL, NULL, cgit_query_head, 74 cgit_tree_link(path1, NULL, NULL, cgit_query_head,
75 sha1_to_hex(old_rev_sha1), path1); 75 sha1_to_hex(old_rev_sha1), path1);
76 else 76 else
77 html_txt(path1); 77 html_txt(path1);
78 html("<br/>+++ b/"); 78 html("<br/>+++ b/");
79 if (mode2 != 0) 79 if (mode2 != 0)
80 cgit_tree_link(path2, NULL, NULL, cgit_query_head, 80 cgit_tree_link(path2, NULL, NULL, cgit_query_head,
81 sha1_to_hex(new_rev_sha1), path2); 81 sha1_to_hex(new_rev_sha1), path2);
82 else 82 else
83 html_txt(path2); 83 html_txt(path2);
84 } 84 }
85 html("</div>"); 85 html("</div>");
86} 86}
87 87
88static void filepair_cb(struct diff_filepair *pair) 88static void filepair_cb(struct diff_filepair *pair)
89{ 89{
90 header(pair->one->sha1, pair->one->path, pair->one->mode, 90 header(pair->one->sha1, pair->one->path, pair->one->mode,
91 pair->two->sha1, pair->two->path, pair->two->mode); 91 pair->two->sha1, pair->two->path, pair->two->mode);
92 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 92 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
93 if (S_ISGITLINK(pair->one->mode)) 93 if (S_ISGITLINK(pair->one->mode))
94 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 94 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
95 if (S_ISGITLINK(pair->two->mode)) 95 if (S_ISGITLINK(pair->two->mode))
96 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 96 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
97 return; 97 return;
98 } 98 }
99 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) 99 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
100 cgit_print_error("Error running diff"); 100 cgit_print_error("Error running diff");
101} 101}
102 102
103void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 103void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
104{ 104{
105 enum object_type type; 105 enum object_type type;
106 unsigned long size; 106 unsigned long size;
107 struct commit *commit, *commit2; 107 struct commit *commit, *commit2;
108 108
109 if (!new_rev) 109 if (!new_rev)
110 new_rev = cgit_query_head; 110 new_rev = cgit_query_head;
111 get_sha1(new_rev, new_rev_sha1); 111 get_sha1(new_rev, new_rev_sha1);
112 type = sha1_object_info(new_rev_sha1, &size); 112 type = sha1_object_info(new_rev_sha1, &size);
113 if (type == OBJ_BAD) { 113 if (type == OBJ_BAD) {
114 cgit_print_error(fmt("Bad object name: %s", new_rev)); 114 cgit_print_error(fmt("Bad object name: %s", new_rev));
115 return; 115 return;
116 } 116 }
117 if (type != OBJ_COMMIT) { 117 if (type != OBJ_COMMIT) {
118 cgit_print_error(fmt("Unhandled object type: %s", 118 cgit_print_error(fmt("Unhandled object type: %s",
119 typename(type))); 119 typename(type)));
120 return; 120 return;
121 } 121 }
122 122
123 commit = lookup_commit_reference(new_rev_sha1); 123 commit = lookup_commit_reference(new_rev_sha1);
124 if (!commit || parse_commit(commit)) 124 if (!commit || parse_commit(commit))
125 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); 125 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
126 126
127 if (old_rev) 127 if (old_rev)
128 get_sha1(old_rev, old_rev_sha1); 128 get_sha1(old_rev, old_rev_sha1);
129 else if (commit->parents && commit->parents->item) 129 else if (commit->parents && commit->parents->item)
130 hashcpy(old_rev_sha1, commit->parents->item->object.sha1); 130 hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
131 else 131 else
132 hashclr(old_rev_sha1); 132 hashclr(old_rev_sha1);
133 133
134 if (!is_null_sha1(old_rev_sha1)) { 134 if (!is_null_sha1(old_rev_sha1)) {
135 type = sha1_object_info(old_rev_sha1, &size); 135 type = sha1_object_info(old_rev_sha1, &size);
136 if (type == OBJ_BAD) { 136 if (type == OBJ_BAD) {
137 cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); 137 cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1)));
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 e5f3c57..a41d2b2 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,140 +1,140 @@
1/* ui-log.c: functions for log output 1/* ui-log.c: functions for log output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11int files, add_lines, rem_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) 15 if (size <= 0)
16 return; 16 return;
17 17
18 if (line[0] == '+') 18 if (line[0] == '+')
19 add_lines++; 19 add_lines++;
20 20
21 else if (line[0] == '-') 21 else if (line[0] == '-')
22 rem_lines++; 22 rem_lines++;
23} 23}
24 24
25void inspect_files(struct diff_filepair *pair) 25void inspect_files(struct diff_filepair *pair)
26{ 26{
27 files++; 27 files++;
28 if (cgit_repo->enable_log_linecount) 28 if (cgit_repo->enable_log_linecount)
29 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); 29 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
30} 30}
31 31
32void print_commit(struct commit *commit) 32void print_commit(struct commit *commit)
33{ 33{
34 struct commitinfo *info; 34 struct commitinfo *info;
35 35
36 info = cgit_parse_commit(commit); 36 info = cgit_parse_commit(commit);
37 html("<tr><td>"); 37 html("<tr><td>");
38 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 38 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
39 html("</td><td>"); 39 html("</td><td>");
40 cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, 40 cgit_commit_link(info->subject, NULL, NULL, cgit_query_head,
41 sha1_to_hex(commit->object.sha1)); 41 sha1_to_hex(commit->object.sha1));
42 if (cgit_repo->enable_log_filecount) { 42 if (cgit_repo->enable_log_filecount) {
43 files = 0; 43 files = 0;
44 add_lines = 0; 44 add_lines = 0;
45 rem_lines = 0; 45 rem_lines = 0;
46 cgit_diff_commit(commit, inspect_files); 46 cgit_diff_commit(commit, inspect_files);
47 html("</td><td class='right'>"); 47 html("</td><td class='right'>");
48 htmlf("%d", files); 48 htmlf("%d", files);
49 if (cgit_repo->enable_log_linecount) { 49 if (cgit_repo->enable_log_linecount) {
50 html("</td><td class='right'>"); 50 html("</td><td class='right'>");
51 htmlf("-%d/+%d", rem_lines, add_lines); 51 htmlf("-%d/+%d", rem_lines, add_lines);
52 } 52 }
53 } 53 }
54 html("</td><td>"); 54 html("</td><td>");
55 html_txt(info->author); 55 html_txt(info->author);
56 html("</td></tr>\n"); 56 html("</td></tr>\n");
57 cgit_free_commitinfo(info); 57 cgit_free_commitinfo(info);
58} 58}
59 59
60 60
61void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) 61void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager)
62{ 62{
63 struct rev_info rev; 63 struct rev_info rev;
64 struct commit *commit; 64 struct commit *commit;
65 const char *argv[] = {NULL, tip, NULL, NULL, NULL}; 65 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
66 int argc = 2; 66 int argc = 2;
67 int i; 67 int i;
68 68
69 if (!tip) 69 if (!tip)
70 argv[1] = cgit_query_head; 70 argv[1] = cgit_query_head;
71 71
72 if (grep && pattern && (!strcmp(grep, "grep") || 72 if (grep && pattern && (!strcmp(grep, "grep") ||
73 !strcmp(grep, "author") || 73 !strcmp(grep, "author") ||
74 !strcmp(grep, "committer"))) 74 !strcmp(grep, "committer")))
75 argv[argc++] = fmt("--%s=%s", grep, pattern); 75 argv[argc++] = fmt("--%s=%s", grep, pattern);
76 76
77 if (path) { 77 if (path) {
78 argv[argc++] = "--"; 78 argv[argc++] = "--";
79 argv[argc++] = path; 79 argv[argc++] = path;
80 } 80 }
81 init_revisions(&rev, NULL); 81 init_revisions(&rev, NULL);
82 rev.abbrev = DEFAULT_ABBREV; 82 rev.abbrev = DEFAULT_ABBREV;
83 rev.commit_format = CMIT_FMT_DEFAULT; 83 rev.commit_format = CMIT_FMT_DEFAULT;
84 rev.verbose_header = 1; 84 rev.verbose_header = 1;
85 rev.show_root_diff = 0; 85 rev.show_root_diff = 0;
86 setup_revisions(argc, argv, &rev, NULL); 86 setup_revisions(argc, argv, &rev, NULL);
87 if (rev.grep_filter) { 87 if (rev.grep_filter) {
88 rev.grep_filter->regflags |= REG_ICASE; 88 rev.grep_filter->regflags |= REG_ICASE;
89 compile_grep_patterns(rev.grep_filter); 89 compile_grep_patterns(rev.grep_filter);
90 } 90 }
91 prepare_revision_walk(&rev); 91 prepare_revision_walk(&rev);
92 92
93 html("<table class='list nowrap'>"); 93 html("<table summary='log' class='list nowrap'>");
94 html("<tr class='nohover'><th class='left'>Age</th>" 94 html("<tr class='nohover'><th class='left'>Age</th>"
95 "<th class='left'>Message</th>"); 95 "<th class='left'>Message</th>");
96 96
97 if (cgit_repo->enable_log_filecount) { 97 if (cgit_repo->enable_log_filecount) {
98 html("<th class='right'>Files</th>"); 98 html("<th class='right'>Files</th>");
99 if (cgit_repo->enable_log_linecount) 99 if (cgit_repo->enable_log_linecount)
100 html("<th class='right'>Lines</th>"); 100 html("<th class='right'>Lines</th>");
101 } 101 }
102 html("<th class='left'>Author</th></tr>\n"); 102 html("<th class='left'>Author</th></tr>\n");
103 103
104 if (ofs<0) 104 if (ofs<0)
105 ofs = 0; 105 ofs = 0;
106 106
107 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 107 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
108 free(commit->buffer); 108 free(commit->buffer);
109 commit->buffer = NULL; 109 commit->buffer = NULL;
110 free_commit_list(commit->parents); 110 free_commit_list(commit->parents);
111 commit->parents = NULL; 111 commit->parents = NULL;
112 } 112 }
113 113
114 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 114 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
115 print_commit(commit); 115 print_commit(commit);
116 free(commit->buffer); 116 free(commit->buffer);
117 commit->buffer = NULL; 117 commit->buffer = NULL;
118 free_commit_list(commit->parents); 118 free_commit_list(commit->parents);
119 commit->parents = NULL; 119 commit->parents = NULL;
120 } 120 }
121 html("</table>\n"); 121 html("</table>\n");
122 122
123 if (pager) { 123 if (pager) {
124 html("<div class='pager'>"); 124 html("<div class='pager'>");
125 if (ofs > 0) { 125 if (ofs > 0) {
126 cgit_log_link("[prev]", NULL, NULL, cgit_query_head, 126 cgit_log_link("[prev]", NULL, NULL, cgit_query_head,
127 cgit_query_sha1, cgit_query_path, 127 cgit_query_sha1, cgit_query_path,
128 ofs - cnt, cgit_query_grep, 128 ofs - cnt, cgit_query_grep,
129 cgit_query_search); 129 cgit_query_search);
130 html("&nbsp;"); 130 html("&nbsp;");
131 } 131 }
132 if ((commit = get_revision(&rev)) != NULL) { 132 if ((commit = get_revision(&rev)) != NULL) {
133 cgit_log_link("[next]", NULL, NULL, cgit_query_head, 133 cgit_log_link("[next]", NULL, NULL, cgit_query_head,
134 cgit_query_sha1, cgit_query_path, 134 cgit_query_sha1, cgit_query_path,
135 ofs + cnt, cgit_query_grep, 135 ofs + cnt, cgit_query_grep,
136 cgit_query_search); 136 cgit_query_search);
137 } 137 }
138 html("</div>"); 138 html("</div>");
139 } 139 }
140} 140}
diff --git a/ui-repolist.c b/ui-repolist.c
index 9aa5c1e..3e97ca9 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -1,110 +1,110 @@
1/* ui-repolist.c: functions for generating the repolist page 1/* ui-repolist.c: functions for generating the repolist page
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 <time.h> 10#include <time.h>
11 11
12 12
13time_t read_agefile(char *path) 13time_t read_agefile(char *path)
14{ 14{
15 FILE *f; 15 FILE *f;
16 static char buf[64], buf2[64]; 16 static char buf[64], buf2[64];
17 17
18 if (!(f = fopen(path, "r"))) 18 if (!(f = fopen(path, "r")))
19 return -1; 19 return -1;
20 fgets(buf, sizeof(buf), f); 20 fgets(buf, sizeof(buf), f);
21 fclose(f); 21 fclose(f);
22 if (parse_date(buf, buf2, sizeof(buf2))) 22 if (parse_date(buf, buf2, sizeof(buf2)))
23 return strtoul(buf2, NULL, 10); 23 return strtoul(buf2, NULL, 10);
24 else 24 else
25 return 0; 25 return 0;
26} 26}
27 27
28static void print_modtime(struct repoinfo *repo) 28static void print_modtime(struct repoinfo *repo)
29{ 29{
30 char *path; 30 char *path;
31 struct stat s; 31 struct stat s;
32 32
33 path = fmt("%s/%s", repo->path, cgit_agefile); 33 path = fmt("%s/%s", repo->path, cgit_agefile);
34 if (stat(path, &s) == 0) { 34 if (stat(path, &s) == 0) {
35 cgit_print_age(read_agefile(path), -1, NULL); 35 cgit_print_age(read_agefile(path), -1, NULL);
36 return; 36 return;
37 } 37 }
38 38
39 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); 39 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
40 if (stat(path, &s) != 0) 40 if (stat(path, &s) != 0)
41 return; 41 return;
42 cgit_print_age(s.st_mtime, -1, NULL); 42 cgit_print_age(s.st_mtime, -1, NULL);
43} 43}
44 44
45void cgit_print_repolist(struct cacheitem *item) 45void cgit_print_repolist(struct cacheitem *item)
46{ 46{
47 int i, columns = 4; 47 int i, columns = 4;
48 char *last_group = NULL; 48 char *last_group = NULL;
49 49
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 }
63 html("<tr class='nohover'>" 63 html("<tr class='nohover'>"
64 "<th class='left'>Name</th>" 64 "<th class='left'>Name</th>"
65 "<th class='left'>Description</th>" 65 "<th class='left'>Description</th>"
66 "<th class='left'>Owner</th>" 66 "<th class='left'>Owner</th>"
67 "<th class='left'>Idle</th>"); 67 "<th class='left'>Idle</th>");
68 if (cgit_enable_index_links) 68 if (cgit_enable_index_links)
69 html("<th>Links</th>"); 69 html("<th>Links</th>");
70 html("</tr>\n"); 70 html("</tr>\n");
71 71
72 for (i=0; i<cgit_repolist.count; i++) { 72 for (i=0; i<cgit_repolist.count; i++) {
73 cgit_repo = &cgit_repolist.repos[i]; 73 cgit_repo = &cgit_repolist.repos[i];
74 if ((last_group == NULL && cgit_repo->group != NULL) || 74 if ((last_group == NULL && cgit_repo->group != NULL) ||
75 (last_group != NULL && cgit_repo->group == NULL) || 75 (last_group != NULL && cgit_repo->group == NULL) ||
76 (last_group != NULL && cgit_repo->group != NULL && 76 (last_group != NULL && cgit_repo->group != NULL &&
77 strcmp(cgit_repo->group, last_group))) { 77 strcmp(cgit_repo->group, last_group))) {
78 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", 78 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
79 columns); 79 columns);
80 html_txt(cgit_repo->group); 80 html_txt(cgit_repo->group);
81 html("</td></tr>"); 81 html("</td></tr>");
82 last_group = cgit_repo->group; 82 last_group = cgit_repo->group;
83 } 83 }
84 htmlf("<tr><td class='%s'>", 84 htmlf("<tr><td class='%s'>",
85 cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); 85 cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
86 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); 86 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
87 html_txt(cgit_repo->name); 87 html_txt(cgit_repo->name);
88 html_link_close(); 88 html_link_close();
89 html("</td><td>"); 89 html("</td><td>");
90 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); 90 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
91 html("</td><td>"); 91 html("</td><td>");
92 html_txt(cgit_repo->owner); 92 html_txt(cgit_repo->owner);
93 html("</td><td>"); 93 html("</td><td>");
94 print_modtime(cgit_repo); 94 print_modtime(cgit_repo);
95 html("</td>"); 95 html("</td>");
96 if (cgit_enable_index_links) { 96 if (cgit_enable_index_links) {
97 html("<td>"); 97 html("<td>");
98 html_link_open(cgit_repourl(cgit_repo->url), 98 html_link_open(cgit_repourl(cgit_repo->url),
99 NULL, "button"); 99 NULL, "button");
100 html("summary</a>"); 100 html("summary</a>");
101 cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 101 cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
102 0, NULL, NULL); 102 0, NULL, NULL);
103 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); 103 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
104 html("</td>"); 104 html("</td>");
105 } 105 }
106 html("</tr>\n"); 106 html("</tr>\n");
107 } 107 }
108 html("</table>"); 108 html("</table>");
109 cgit_print_docend(); 109 cgit_print_docend();
110} 110}
diff --git a/ui-shared.c b/ui-shared.c
index 7c69f60..9ec646b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -265,273 +265,273 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
265 if (old_rev) { 265 if (old_rev) {
266 html(delim); 266 html(delim);
267 html("id2="); 267 html("id2=");
268 html_attr(old_rev); 268 html_attr(old_rev);
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_object_link(struct object *obj) 275void cgit_object_link(struct object *obj)
276{ 276{
277 char *page, *arg, *url; 277 char *page, *arg, *url;
278 278
279 if (obj->type == OBJ_COMMIT) { 279 if (obj->type == OBJ_COMMIT) {
280 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 280 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
281 cgit_query_head, sha1_to_hex(obj->sha1)); 281 cgit_query_head, sha1_to_hex(obj->sha1));
282 return; 282 return;
283 } else if (obj->type == OBJ_TREE) { 283 } else if (obj->type == OBJ_TREE) {
284 page = "tree"; 284 page = "tree";
285 arg = "id"; 285 arg = "id";
286 } else if (obj->type == OBJ_TAG) { 286 } else if (obj->type == OBJ_TAG) {
287 page = "tag"; 287 page = "tag";
288 arg = "id"; 288 arg = "id";
289 } else { 289 } else {
290 page = "blob"; 290 page = "blob";
291 arg = "id"; 291 arg = "id";
292 } 292 }
293 293
294 url = cgit_pageurl(cgit_query_repo, page, 294 url = cgit_pageurl(cgit_query_repo, page,
295 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 295 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
296 html_link_open(url, NULL, NULL); 296 html_link_open(url, NULL, NULL);
297 htmlf("%s %s", typename(obj->type), 297 htmlf("%s %s", typename(obj->type),
298 sha1_to_hex(obj->sha1)); 298 sha1_to_hex(obj->sha1));
299 html_link_close(); 299 html_link_close();
300} 300}
301 301
302void cgit_print_date(time_t secs, char *format) 302void cgit_print_date(time_t secs, char *format)
303{ 303{
304 char buf[64]; 304 char buf[64];
305 struct tm *time; 305 struct tm *time;
306 306
307 time = gmtime(&secs); 307 time = gmtime(&secs);
308 strftime(buf, sizeof(buf)-1, format, time); 308 strftime(buf, sizeof(buf)-1, format, time);
309 html_txt(buf); 309 html_txt(buf);
310} 310}
311 311
312void cgit_print_age(time_t t, time_t max_relative, char *format) 312void cgit_print_age(time_t t, time_t max_relative, char *format)
313{ 313{
314 time_t now, secs; 314 time_t now, secs;
315 315
316 time(&now); 316 time(&now);
317 secs = now - t; 317 secs = now - t;
318 318
319 if (secs > max_relative && max_relative >= 0) { 319 if (secs > max_relative && max_relative >= 0) {
320 cgit_print_date(t, format); 320 cgit_print_date(t, format);
321 return; 321 return;
322 } 322 }
323 323
324 if (secs < TM_HOUR * 2) { 324 if (secs < TM_HOUR * 2) {
325 htmlf("<span class='age-mins'>%.0f min.</span>", 325 htmlf("<span class='age-mins'>%.0f min.</span>",
326 secs * 1.0 / TM_MIN); 326 secs * 1.0 / TM_MIN);
327 return; 327 return;
328 } 328 }
329 if (secs < TM_DAY * 2) { 329 if (secs < TM_DAY * 2) {
330 htmlf("<span class='age-hours'>%.0f hours</span>", 330 htmlf("<span class='age-hours'>%.0f hours</span>",
331 secs * 1.0 / TM_HOUR); 331 secs * 1.0 / TM_HOUR);
332 return; 332 return;
333 } 333 }
334 if (secs < TM_WEEK * 2) { 334 if (secs < TM_WEEK * 2) {
335 htmlf("<span class='age-days'>%.0f days</span>", 335 htmlf("<span class='age-days'>%.0f days</span>",
336 secs * 1.0 / TM_DAY); 336 secs * 1.0 / TM_DAY);
337 return; 337 return;
338 } 338 }
339 if (secs < TM_MONTH * 2) { 339 if (secs < TM_MONTH * 2) {
340 htmlf("<span class='age-weeks'>%.0f weeks</span>", 340 htmlf("<span class='age-weeks'>%.0f weeks</span>",
341 secs * 1.0 / TM_WEEK); 341 secs * 1.0 / TM_WEEK);
342 return; 342 return;
343 } 343 }
344 if (secs < TM_YEAR * 2) { 344 if (secs < TM_YEAR * 2) {
345 htmlf("<span class='age-months'>%.0f months</span>", 345 htmlf("<span class='age-months'>%.0f months</span>",
346 secs * 1.0 / TM_MONTH); 346 secs * 1.0 / TM_MONTH);
347 return; 347 return;
348 } 348 }
349 htmlf("<span class='age-years'>%.0f years</span>", 349 htmlf("<span class='age-years'>%.0f years</span>",
350 secs * 1.0 / TM_YEAR); 350 secs * 1.0 / TM_YEAR);
351} 351}
352 352
353void cgit_print_docstart(char *title, struct cacheitem *item) 353void cgit_print_docstart(char *title, struct cacheitem *item)
354{ 354{
355 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 355 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
356 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 356 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
357 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 357 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
358 ttl_seconds(item->ttl))); 358 ttl_seconds(item->ttl)));
359 html("\n"); 359 html("\n");
360 html(cgit_doctype); 360 html(cgit_doctype);
361 html("<html>\n"); 361 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
362 html("<head>\n"); 362 html("<head>\n");
363 html("<title>"); 363 html("<title>");
364 html_txt(title); 364 html_txt(title);
365 html("</title>\n"); 365 html("</title>\n");
366 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 366 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
367 html("<link rel='stylesheet' type='text/css' href='"); 367 html("<link rel='stylesheet' type='text/css' href='");
368 html_attr(cgit_css); 368 html_attr(cgit_css);
369 html("'/>\n"); 369 html("'/>\n");
370 html("</head>\n"); 370 html("</head>\n");
371 html("<body>\n"); 371 html("<body>\n");
372} 372}
373 373
374void cgit_print_docend() 374void cgit_print_docend()
375{ 375{
376 html("</td>\n</tr>\n<table>\n</body>\n</html>\n"); 376 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
377} 377}
378 378
379int print_branch_option(const char *refname, const unsigned char *sha1, 379int print_branch_option(const char *refname, const unsigned char *sha1,
380 int flags, void *cb_data) 380 int flags, void *cb_data)
381{ 381{
382 char *name = (char *)refname; 382 char *name = (char *)refname;
383 html_option(name, name, cgit_query_head); 383 html_option(name, name, cgit_query_head);
384 return 0; 384 return 0;
385} 385}
386 386
387int print_archive_ref(const char *refname, const unsigned char *sha1, 387int print_archive_ref(const char *refname, const unsigned char *sha1,
388 int flags, void *cb_data) 388 int flags, void *cb_data)
389{ 389{
390 struct tag *tag; 390 struct tag *tag;
391 struct taginfo *info; 391 struct taginfo *info;
392 struct object *obj; 392 struct object *obj;
393 char buf[256], *url; 393 char buf[256], *url;
394 unsigned char fileid[20]; 394 unsigned char fileid[20];
395 int *header = (int *)cb_data; 395 int *header = (int *)cb_data;
396 396
397 if (prefixcmp(refname, "refs/archives")) 397 if (prefixcmp(refname, "refs/archives"))
398 return 0; 398 return 0;
399 strncpy(buf, refname+14, sizeof(buf)); 399 strncpy(buf, refname+14, sizeof(buf));
400 obj = parse_object(sha1); 400 obj = parse_object(sha1);
401 if (!obj) 401 if (!obj)
402 return 1; 402 return 1;
403 if (obj->type == OBJ_TAG) { 403 if (obj->type == OBJ_TAG) {
404 tag = lookup_tag(sha1); 404 tag = lookup_tag(sha1);
405 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 405 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
406 return 0; 406 return 0;
407 hashcpy(fileid, tag->tagged->sha1); 407 hashcpy(fileid, tag->tagged->sha1);
408 } else if (obj->type != OBJ_BLOB) { 408 } else if (obj->type != OBJ_BLOB) {
409 return 0; 409 return 0;
410 } else { 410 } else {
411 hashcpy(fileid, sha1); 411 hashcpy(fileid, sha1);
412 } 412 }
413 if (!*header) { 413 if (!*header) {
414 html("<p><h1>download</h1>"); 414 html("<p><h1>download</h1>");
415 *header = 1; 415 *header = 1;
416 } 416 }
417 url = cgit_pageurl(cgit_query_repo, "blob", 417 url = cgit_pageurl(cgit_query_repo, "blob",
418 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 418 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
419 buf)); 419 buf));
420 html_link_open(url, NULL, "menu"); 420 html_link_open(url, NULL, "menu");
421 html_txt(strlpart(buf, 20)); 421 html_txt(strlpart(buf, 20));
422 html_link_close(); 422 html_link_close();
423 return 0; 423 return 0;
424} 424}
425 425
426void add_hidden_formfields(int incl_head, int incl_search, char *page) 426void add_hidden_formfields(int incl_head, int incl_search, char *page)
427{ 427{
428 char *url; 428 char *url;
429 429
430 if (!cgit_virtual_root) { 430 if (!cgit_virtual_root) {
431 url = fmt("%s/%s", cgit_query_repo, page); 431 url = fmt("%s/%s", cgit_query_repo, page);
432 if (cgit_query_path) 432 if (cgit_query_path)
433 url = fmt("%s/%s", url, cgit_query_path); 433 url = fmt("%s/%s", url, cgit_query_path);
434 html_hidden("url", url); 434 html_hidden("url", url);
435 } 435 }
436 436
437 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) 437 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch))
438 html_hidden("h", cgit_query_head); 438 html_hidden("h", cgit_query_head);
439 439
440 if (cgit_query_sha1) 440 if (cgit_query_sha1)
441 html_hidden("id", cgit_query_sha1); 441 html_hidden("id", cgit_query_sha1);
442 if (cgit_query_sha2) 442 if (cgit_query_sha2)
443 html_hidden("id2", cgit_query_sha2); 443 html_hidden("id2", cgit_query_sha2);
444 444
445 if (incl_search) { 445 if (incl_search) {
446 if (cgit_query_grep) 446 if (cgit_query_grep)
447 html_hidden("qt", cgit_query_grep); 447 html_hidden("qt", cgit_query_grep);
448 if (cgit_query_search) 448 if (cgit_query_search)
449 html_hidden("q", cgit_query_search); 449 html_hidden("q", cgit_query_search);
450 } 450 }
451} 451}
452 452
453void cgit_print_pageheader(char *title, int show_search) 453void cgit_print_pageheader(char *title, int show_search)
454{ 454{
455 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 455 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
456 int header = 0; 456 int header = 0;
457 457
458 html("<div id='sidebar'>\n"); 458 html("<div id='sidebar'>\n");
459 html("<a href='"); 459 html("<div id='logo'><a href='");
460 html_attr(cgit_rooturl()); 460 html_attr(cgit_rooturl());
461 htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", 461 htmlf("'><img src='%s' alt='cgit'/></a></div>\n",
462 cgit_logo); 462 cgit_logo);
463 html("<div class='infobox'>"); 463 html("<div class='infobox'>");
464 if (cgit_query_repo) { 464 if (cgit_query_repo) {
465 html("<h1>"); 465 html("<h1 class='first'>");
466 html_txt(strrpart(cgit_repo->name, 20)); 466 html_txt(strrpart(cgit_repo->name, 20));
467 html("</h1>\n"); 467 html("</h1>\n");
468 html_txt(cgit_repo->desc); 468 html_txt(cgit_repo->desc);
469 if (cgit_repo->owner) { 469 if (cgit_repo->owner) {
470 html("<p>\n<h1>owner</h1>\n"); 470 html("<h1>owner</h1>\n");
471 html_txt(cgit_repo->owner); 471 html_txt(cgit_repo->owner);
472 } 472 }
473 html("<p>\n<h1>navigate</h1>\n"); 473 html("<h1>navigate</h1>\n");
474 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 474 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head,
475 NULL, NULL); 475 NULL, NULL);
476 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, 476 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL,
477 0, NULL, NULL); 477 0, NULL, NULL);
478 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 478 cgit_tree_link("tree", NULL, "menu", cgit_query_head,
479 cgit_query_sha1, NULL); 479 cgit_query_sha1, NULL);
480 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 480 cgit_commit_link("commit", NULL, "menu", cgit_query_head,
481 cgit_query_sha1); 481 cgit_query_sha1);
482 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 482 cgit_diff_link("diff", NULL, "menu", cgit_query_head,
483 cgit_query_sha1, cgit_query_sha2, NULL); 483 cgit_query_sha1, cgit_query_sha2, NULL);
484 484
485 for_each_ref(print_archive_ref, &header); 485 for_each_ref(print_archive_ref, &header);
486 486
487 html("<p>\n<h1>branch</h1>\n"); 487 html("<h1>branch</h1>\n");
488 html("<form method='get' action=''>\n"); 488 html("<form method='get' action=''>\n");
489 add_hidden_formfields(0, 1, cgit_query_page); 489 add_hidden_formfields(0, 1, cgit_query_page);
490 html("<table class='grid'><tr><td id='branch-dropdown-cell'>"); 490 html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
491 html("<select name='h' onchange='this.form.submit();'>\n"); 491 html("<select name='h' onchange='this.form.submit();'>\n");
492 for_each_branch_ref(print_branch_option, cgit_query_head); 492 for_each_branch_ref(print_branch_option, cgit_query_head);
493 html("</select>\n"); 493 html("</select>\n");
494 html("</td><td>"); 494 html("</td><td>");
495 html("<noscript><input type='submit' id='switch-btn' value='..'></noscript>\n"); 495 html("<noscript><input type='submit' id='switch-btn' value='..'/></noscript>\n");
496 html("</td></tr></table>"); 496 html("</td></tr></table>");
497 html("</form>\n"); 497 html("</form>\n");
498 498
499 html("<p>\n<h1>search</h1>\n"); 499 html("<h1>search</h1>\n");
500 html("<form method='get' action='"); 500 html("<form method='get' action='");
501 if (cgit_virtual_root) 501 if (cgit_virtual_root)
502 html_attr(cgit_fileurl(cgit_query_repo, "log", 502 html_attr(cgit_fileurl(cgit_query_repo, "log",
503 cgit_query_path, NULL)); 503 cgit_query_path, NULL));
504 html("'>\n"); 504 html("'>\n");
505 add_hidden_formfields(1, 0, "log"); 505 add_hidden_formfields(1, 0, "log");
506 html("<select name='qt'>\n"); 506 html("<select name='qt'>\n");
507 html_option("grep", "log msg", cgit_query_grep); 507 html_option("grep", "log msg", cgit_query_grep);
508 html_option("author", "author", cgit_query_grep); 508 html_option("author", "author", cgit_query_grep);
509 html_option("committer", "committer", cgit_query_grep); 509 html_option("committer", "committer", cgit_query_grep);
510 html("</select>\n"); 510 html("</select>\n");
511 html("<input class='txt' type='text' name='q' value='"); 511 html("<input class='txt' type='text' name='q' value='");
512 html_attr(cgit_query_search); 512 html_attr(cgit_query_search);
513 html("'/>\n"); 513 html("'/>\n");
514 html("</form>\n"); 514 html("</form>\n");
515 } else { 515 } else {
516 if (!cgit_index_info || html_include(cgit_index_info)) 516 if (!cgit_index_info || html_include(cgit_index_info))
517 html(default_info); 517 html(default_info);
518 } 518 }
519 519
520 html("</div>\n"); 520 html("</div>\n");
521 521
522 html("</div>\n<table class='grid'><tr><td id='content'>\n"); 522 html("</div>\n<table summary='page content' class='grid'><tr><td id='content'>\n");
523} 523}
524 524
525 525
526void cgit_print_snapshot_start(const char *mimetype, const char *filename, 526void cgit_print_snapshot_start(const char *mimetype, const char *filename,
527 struct cacheitem *item) 527 struct cacheitem *item)
528{ 528{
529 htmlf("Content-Type: %s\n", mimetype); 529 htmlf("Content-Type: %s\n", mimetype);
530 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 530 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
531 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 531 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
532 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 532 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
533 ttl_seconds(item->ttl))); 533 ttl_seconds(item->ttl)));
534 html("\n"); 534 html("\n");
535} 535}
536 536
537/* vim:set sw=8: */ 537/* vim:set sw=8: */
diff --git a/ui-summary.c b/ui-summary.c
index c856793..b96414e 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -97,104 +97,104 @@ static int print_tag(struct refinfo *ref)
97 url = cgit_pageurl(cgit_query_repo, "tag", 97 url = cgit_pageurl(cgit_query_repo, "tag",
98 fmt("id=%s", name)); 98 fmt("id=%s", name));
99 html_link_open(url, NULL, NULL); 99 html_link_open(url, NULL, NULL);
100 html_txt(name); 100 html_txt(name);
101 html_link_close(); 101 html_link_close();
102 html("</td><td>"); 102 html("</td><td>");
103 if (info->tagger_date > 0) 103 if (info->tagger_date > 0)
104 cgit_print_age(info->tagger_date, -1, NULL); 104 cgit_print_age(info->tagger_date, -1, NULL);
105 html("</td><td>"); 105 html("</td><td>");
106 if (info->tagger) 106 if (info->tagger)
107 html(info->tagger); 107 html(info->tagger);
108 html("</td><td>"); 108 html("</td><td>");
109 cgit_object_link(tag->tagged); 109 cgit_object_link(tag->tagged);
110 html("</td></tr>\n"); 110 html("</td></tr>\n");
111 } else { 111 } else {
112 if (!header) 112 if (!header)
113 print_tag_header(); 113 print_tag_header();
114 html("<tr><td>"); 114 html("<tr><td>");
115 html_txt(name); 115 html_txt(name);
116 html("</td><td colspan='2'/><td>"); 116 html("</td><td colspan='2'/><td>");
117 cgit_object_link(ref->object); 117 cgit_object_link(ref->object);
118 html("</td></tr>\n"); 118 html("</td></tr>\n");
119 } 119 }
120 return 0; 120 return 0;
121} 121}
122 122
123static void print_refs_link(char *path) 123static void print_refs_link(char *path)
124{ 124{
125 html("<tr class='nohover'><td colspan='4'>"); 125 html("<tr class='nohover'><td colspan='4'>");
126 cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); 126 cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path);
127 html("</td></tr>"); 127 html("</td></tr>");
128} 128}
129 129
130void cgit_print_branches(int maxcount) 130void cgit_print_branches(int maxcount)
131{ 131{
132 struct reflist list; 132 struct reflist list;
133 int i; 133 int i;
134 134
135 html("<tr class='nohover'><th class='left'>Branch</th>" 135 html("<tr class='nohover'><th class='left'>Branch</th>"
136 "<th class='left'>Idle</th>" 136 "<th class='left'>Idle</th>"
137 "<th class='left'>Author</th>" 137 "<th class='left'>Author</th>"
138 "<th class='left'>Head commit</th></tr>\n"); 138 "<th class='left'>Head commit</th></tr>\n");
139 139
140 list.refs = NULL; 140 list.refs = NULL;
141 list.alloc = list.count = 0; 141 list.alloc = list.count = 0;
142 for_each_branch_ref(cgit_refs_cb, &list); 142 for_each_branch_ref(cgit_refs_cb, &list);
143 143
144 if (maxcount == 0 || maxcount > list.count) 144 if (maxcount == 0 || maxcount > list.count)
145 maxcount = list.count; 145 maxcount = list.count;
146 146
147 if (maxcount < list.count) { 147 if (maxcount < list.count) {
148 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); 148 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
149 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); 149 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
150 } 150 }
151 151
152 for(i=0; i<maxcount; i++) 152 for(i=0; i<maxcount; i++)
153 print_branch(list.refs[i]); 153 print_branch(list.refs[i]);
154 154
155 if (maxcount < list.count) 155 if (maxcount < list.count)
156 print_refs_link("heads"); 156 print_refs_link("heads");
157} 157}
158 158
159void cgit_print_tags(int maxcount) 159void cgit_print_tags(int maxcount)
160{ 160{
161 struct reflist list; 161 struct reflist list;
162 int i; 162 int i;
163 163
164 header = 0; 164 header = 0;
165 list.refs = NULL; 165 list.refs = NULL;
166 list.alloc = list.count = 0; 166 list.alloc = list.count = 0;
167 for_each_tag_ref(cgit_refs_cb, &list); 167 for_each_tag_ref(cgit_refs_cb, &list);
168 if (list.count == 0) 168 if (list.count == 0)
169 return; 169 return;
170 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); 170 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
171 if (!maxcount) 171 if (!maxcount)
172 maxcount = list.count; 172 maxcount = list.count;
173 else if (maxcount > list.count) 173 else if (maxcount > list.count)
174 maxcount = list.count; 174 maxcount = list.count;
175 print_tag_header(); 175 print_tag_header();
176 for(i=0; i<maxcount; i++) 176 for(i=0; i<maxcount; i++)
177 print_tag(list.refs[i]); 177 print_tag(list.refs[i]);
178 178
179 if (maxcount < list.count) 179 if (maxcount < list.count)
180 print_refs_link("tags"); 180 print_refs_link("tags");
181} 181}
182 182
183void cgit_print_summary() 183void cgit_print_summary()
184{ 184{
185 if (cgit_repo->readme) { 185 if (cgit_repo->readme) {
186 html("<div id='summary'>"); 186 html("<div id='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>");
200} 200}
diff --git a/ui-tree.c b/ui-tree.c
index c22e30b..c138877 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,207 +1,207 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11char *curr_rev; 11char *curr_rev;
12char *match_path; 12char *match_path;
13int header = 0; 13int 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;
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 cgit_print_error(fmt("Error reading object %s", 31 cgit_print_error(fmt("Error reading object %s",
32 sha1_to_hex(sha1))); 32 sha1_to_hex(sha1)));
33 return; 33 return;
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';
47 htmlf(linefmt, ++lineno); 47 htmlf(linefmt, ++lineno);
48 html_txt(buf + start); 48 html_txt(buf + start);
49 html("</td></tr>\n"); 49 html("</td></tr>\n");
50 start = idx + 1; 50 start = idx + 1;
51 } 51 }
52 idx++; 52 idx++;
53 } 53 }
54 htmlf(linefmt, ++lineno); 54 htmlf(linefmt, ++lineno);
55 html_txt(buf + start); 55 html_txt(buf + start);
56 html("</td></tr>\n"); 56 html("</td></tr>\n");
57 html("</table>\n"); 57 html("</table>\n");
58} 58}
59 59
60 60
61static int ls_item(const unsigned char *sha1, const char *base, int baselen, 61static int ls_item(const unsigned char *sha1, const char *base, int baselen,
62 const char *pathname, unsigned int mode, int stage) 62 const char *pathname, unsigned int mode, int stage)
63{ 63{
64 char *name; 64 char *name;
65 char *fullpath; 65 char *fullpath;
66 enum object_type type; 66 enum object_type type;
67 unsigned long size = 0; 67 unsigned long size = 0;
68 68
69 name = xstrdup(pathname); 69 name = xstrdup(pathname);
70 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", 70 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
71 cgit_query_path ? "/" : "", name); 71 cgit_query_path ? "/" : "", name);
72 72
73 type = sha1_object_info(sha1, &size); 73 type = sha1_object_info(sha1, &size);
74 if (type == OBJ_BAD && !S_ISGITLINK(mode)) { 74 if (type == OBJ_BAD && !S_ISGITLINK(mode)) {
75 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 75 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
76 name, 76 name,
77 sha1_to_hex(sha1)); 77 sha1_to_hex(sha1));
78 return 0; 78 return 0;
79 } 79 }
80 80
81 html("<tr><td class='ls-mode'>"); 81 html("<tr><td class='ls-mode'>");
82 html_filemode(mode); 82 html_filemode(mode);
83 html("</td><td>"); 83 html("</td><td>");
84 if (S_ISGITLINK(mode)) { 84 if (S_ISGITLINK(mode)) {
85 htmlf("<a class='ls-mod' href='"); 85 htmlf("<a class='ls-mod' href='");
86 html_attr(fmt(cgit_repo->module_link, 86 html_attr(fmt(cgit_repo->module_link,
87 name, 87 name,
88 sha1_to_hex(sha1))); 88 sha1_to_hex(sha1)));
89 html("'>"); 89 html("'>");
90 html_txt(name); 90 html_txt(name);
91 html("</a>"); 91 html("</a>");
92 } else if (S_ISDIR(mode)) { 92 } else if (S_ISDIR(mode)) {
93 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, 93 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head,
94 curr_rev, fullpath); 94 curr_rev, fullpath);
95 } else { 95 } else {
96 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, 96 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head,
97 curr_rev, fullpath); 97 curr_rev, fullpath);
98 } 98 }
99 htmlf("</td><td class='ls-size'>%li</td>", size); 99 htmlf("</td><td class='ls-size'>%li</td>", size);
100 100
101 html("<td>"); 101 html("<td>");
102 cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, 102 cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev,
103 fullpath, 0, NULL, NULL); 103 fullpath, 0, NULL, NULL);
104 html("</td></tr>\n"); 104 html("</td></tr>\n");
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");
118 header = 1; 118 header = 1;
119} 119}
120 120
121static void ls_tail() 121static void ls_tail()
122{ 122{
123 if (!header) 123 if (!header)
124 return; 124 return;
125 html("</table>\n"); 125 html("</table>\n");
126 header = 0; 126 header = 0;
127} 127}
128 128
129static void ls_tree(const unsigned char *sha1, char *path) 129static void ls_tree(const unsigned char *sha1, char *path)
130{ 130{
131 struct tree *tree; 131 struct tree *tree;
132 132
133 tree = parse_tree_indirect(sha1); 133 tree = parse_tree_indirect(sha1);
134 if (!tree) { 134 if (!tree) {
135 cgit_print_error(fmt("Not a tree object: %s", 135 cgit_print_error(fmt("Not a tree object: %s",
136 sha1_to_hex(sha1))); 136 sha1_to_hex(sha1)));
137 return; 137 return;
138 } 138 }
139 139
140 ls_head(); 140 ls_head();
141 read_tree_recursive(tree, "", 0, 1, NULL, ls_item); 141 read_tree_recursive(tree, "", 0, 1, NULL, ls_item);
142 ls_tail(); 142 ls_tail();
143} 143}
144 144
145 145
146static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 146static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
147 const char *pathname, unsigned mode, int stage) 147 const char *pathname, unsigned mode, int stage)
148{ 148{
149 static int state; 149 static int state;
150 static char buffer[PATH_MAX]; 150 static char buffer[PATH_MAX];
151 char *url; 151 char *url;
152 152
153 if (state == 0) { 153 if (state == 0) {
154 memcpy(buffer, base, baselen); 154 memcpy(buffer, base, baselen);
155 strcpy(buffer+baselen, pathname); 155 strcpy(buffer+baselen, pathname);
156 url = cgit_pageurl(cgit_query_repo, "tree", 156 url = cgit_pageurl(cgit_query_repo, "tree",
157 fmt("h=%s&amp;path=%s", curr_rev, buffer)); 157 fmt("h=%s&amp;path=%s", curr_rev, buffer));
158 html("/"); 158 html("/");
159 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, 159 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head,
160 curr_rev, buffer); 160 curr_rev, buffer);
161 161
162 if (strcmp(match_path, buffer)) 162 if (strcmp(match_path, buffer))
163 return READ_TREE_RECURSIVE; 163 return READ_TREE_RECURSIVE;
164 164
165 if (S_ISDIR(mode)) { 165 if (S_ISDIR(mode)) {
166 state = 1; 166 state = 1;
167 ls_head(); 167 ls_head();
168 return READ_TREE_RECURSIVE; 168 return READ_TREE_RECURSIVE;
169 } else { 169 } else {
170 print_object(sha1, buffer); 170 print_object(sha1, buffer);
171 return 0; 171 return 0;
172 } 172 }
173 } 173 }
174 ls_item(sha1, base, baselen, pathname, mode, stage); 174 ls_item(sha1, base, baselen, pathname, mode, stage);
175 return 0; 175 return 0;
176} 176}
177 177
178 178
179/* 179/*
180 * Show a tree or a blob 180 * Show a tree or a blob
181 * rev: the commit pointing at the root tree object 181 * rev: the commit pointing at the root tree object
182 * path: path to tree or blob 182 * path: path to tree or blob
183 */ 183 */
184void cgit_print_tree(const char *rev, char *path) 184void cgit_print_tree(const char *rev, char *path)
185{ 185{
186 unsigned char sha1[20]; 186 unsigned char sha1[20];
187 struct commit *commit; 187 struct commit *commit;
188 const char *paths[] = {path, NULL}; 188 const char *paths[] = {path, NULL};
189 189
190 if (!rev) 190 if (!rev)
191 rev = cgit_query_head; 191 rev = cgit_query_head;
192 192
193 curr_rev = xstrdup(rev); 193 curr_rev = xstrdup(rev);
194 if (get_sha1(rev, sha1)) { 194 if (get_sha1(rev, sha1)) {
195 cgit_print_error(fmt("Invalid revision name: %s", rev)); 195 cgit_print_error(fmt("Invalid revision name: %s", rev));
196 return; 196 return;
197 } 197 }
198 commit = lookup_commit_reference(sha1); 198 commit = lookup_commit_reference(sha1);
199 if (!commit || parse_commit(commit)) { 199 if (!commit || parse_commit(commit)) {
200 cgit_print_error(fmt("Invalid commit reference: %s", rev)); 200 cgit_print_error(fmt("Invalid commit reference: %s", rev));
201 return; 201 return;
202 } 202 }
203 203
204 html("path: <a href='"); 204 html("path: <a href='");
205 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); 205 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev)));
206 html("'>root</a>"); 206 html("'>root</a>");
207 207