summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2008-09-01 20:40:55 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-09-01 20:40:55 (UTC)
commitd532c4d1612c94347427fa1afda6afb7c34e512a (patch) (unidiff)
tree53f3f86ba8e78051bee96cb65a6219ef43d9adab
parent288d502b3d8e7fa916104b486bbb146521e5c716 (diff)
parent885096c189574b1cf2e0897cc05aadd7b092a677 (diff)
downloadcgit-d532c4d1612c94347427fa1afda6afb7c34e512a.zip
cgit-d532c4d1612c94347427fa1afda6afb7c34e512a.tar.gz
cgit-d532c4d1612c94347427fa1afda6afb7c34e512a.tar.bz2
Merge branch 'lh/plain'
* lh/plain: Supply status description to html_status() ui-tree: link to plain view instead of blob view Implement plain view
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile1
-rw-r--r--cgit.c1
-rw-r--r--cgit.h1
-rw-r--r--cmd.c7
-rw-r--r--html.c9
-rw-r--r--html.h3
-rw-r--r--ui-clone.c10
-rw-r--r--ui-plain.c82
-rw-r--r--ui-plain.h6
-rw-r--r--ui-shared.c8
-rw-r--r--ui-shared.h2
-rw-r--r--ui-tree.c8
12 files changed, 125 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index b002d44..e4265f7 100644
--- a/Makefile
+++ b/Makefile
@@ -17,96 +17,97 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
17# from git.git 17# from git.git
18# 18#
19QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir 19QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
20QUIET_SUBDIR1 = 20QUIET_SUBDIR1 =
21 21
22ifneq ($(findstring $(MAKEFLAGS),w),w) 22ifneq ($(findstring $(MAKEFLAGS),w),w)
23PRINT_DIR = --no-print-directory 23PRINT_DIR = --no-print-directory
24else # "make -w" 24else # "make -w"
25NO_SUBDIR = : 25NO_SUBDIR = :
26endif 26endif
27 27
28ifndef V 28ifndef V
29 QUIET_CC = @echo ' ' CC $@; 29 QUIET_CC = @echo ' ' CC $@;
30 QUIET_MM = @echo ' ' MM $@; 30 QUIET_MM = @echo ' ' MM $@;
31 QUIET_SUBDIR0 = +@subdir= 31 QUIET_SUBDIR0 = +@subdir=
32 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ 32 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
33 $(MAKE) $(PRINT_DIR) -C $$subdir 33 $(MAKE) $(PRINT_DIR) -C $$subdir
34endif 34endif
35 35
36# 36#
37# Define a pattern rule for automatic dependency building 37# Define a pattern rule for automatic dependency building
38# 38#
39%.d: %.c 39%.d: %.c
40 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ 40 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
41 41
42# 42#
43# Define a pattern rule for silent object building 43# Define a pattern rule for silent object building
44# 44#
45%.o: %.c 45%.o: %.c
46 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< 46 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
47 47
48 48
49EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto 49EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
50OBJECTS = 50OBJECTS =
51OBJECTS += cache.o 51OBJECTS += cache.o
52OBJECTS += cgit.o 52OBJECTS += cgit.o
53OBJECTS += cmd.o 53OBJECTS += cmd.o
54OBJECTS += configfile.o 54OBJECTS += configfile.o
55OBJECTS += html.o 55OBJECTS += html.o
56OBJECTS += parsing.o 56OBJECTS += parsing.o
57OBJECTS += shared.o 57OBJECTS += shared.o
58OBJECTS += ui-atom.o 58OBJECTS += ui-atom.o
59OBJECTS += ui-blob.o 59OBJECTS += ui-blob.o
60OBJECTS += ui-clone.o 60OBJECTS += ui-clone.o
61OBJECTS += ui-commit.o 61OBJECTS += ui-commit.o
62OBJECTS += ui-diff.o 62OBJECTS += ui-diff.o
63OBJECTS += ui-log.o 63OBJECTS += ui-log.o
64OBJECTS += ui-patch.o 64OBJECTS += ui-patch.o
65OBJECTS += ui-plain.o
65OBJECTS += ui-refs.o 66OBJECTS += ui-refs.o
66OBJECTS += ui-repolist.o 67OBJECTS += ui-repolist.o
67OBJECTS += ui-shared.o 68OBJECTS += ui-shared.o
68OBJECTS += ui-snapshot.o 69OBJECTS += ui-snapshot.o
69OBJECTS += ui-summary.o 70OBJECTS += ui-summary.o
70OBJECTS += ui-tag.o 71OBJECTS += ui-tag.o
71OBJECTS += ui-tree.o 72OBJECTS += ui-tree.o
72 73
73ifdef NEEDS_LIBICONV 74ifdef NEEDS_LIBICONV
74 EXTLIBS += -liconv 75 EXTLIBS += -liconv
75endif 76endif
76 77
77 78
78.PHONY: all libgit test install uninstall clean force-version get-git 79.PHONY: all libgit test install uninstall clean force-version get-git
79 80
80all: cgit 81all: cgit
81 82
82VERSION: force-version 83VERSION: force-version
83 @./gen-version.sh "$(CGIT_VERSION)" 84 @./gen-version.sh "$(CGIT_VERSION)"
84-include VERSION 85-include VERSION
85 86
86 87
87CFLAGS += -g -Wall -Igit 88CFLAGS += -g -Wall -Igit
88CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 89CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
89CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' 90CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
90CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' 91CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
91CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' 92CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
92CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' 93CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
93 94
94 95
95cgit: $(OBJECTS) libgit 96cgit: $(OBJECTS) libgit
96 $(QUIET_CC)$(CC) $(CFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) 97 $(QUIET_CC)$(CC) $(CFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
97 98
98cgit.o: VERSION 99cgit.o: VERSION
99 100
100-include $(OBJECTS:.o=.d) 101-include $(OBJECTS:.o=.d)
101 102
102libgit: 103libgit:
103 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a 104 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a
104 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a 105 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a
105 106
106test: all 107test: all
107 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all 108 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
108 109
109install: all 110install: all
110 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) 111 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
111 install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 112 install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
112 install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css 113 install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css
diff --git a/cgit.c b/cgit.c
index f49fffa..497337b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -142,96 +142,97 @@ static void querystring_cb(const char *name, const char *value)
142 ctx.qry.sha1 = xstrdup(value); 142 ctx.qry.sha1 = xstrdup(value);
143 ctx.qry.has_sha1 = 1; 143 ctx.qry.has_sha1 = 1;
144 } else if (!strcmp(name, "id2")) { 144 } else if (!strcmp(name, "id2")) {
145 ctx.qry.sha2 = xstrdup(value); 145 ctx.qry.sha2 = xstrdup(value);
146 ctx.qry.has_sha1 = 1; 146 ctx.qry.has_sha1 = 1;
147 } else if (!strcmp(name, "ofs")) { 147 } else if (!strcmp(name, "ofs")) {
148 ctx.qry.ofs = atoi(value); 148 ctx.qry.ofs = atoi(value);
149 } else if (!strcmp(name, "path")) { 149 } else if (!strcmp(name, "path")) {
150 ctx.qry.path = trim_end(value, '/'); 150 ctx.qry.path = trim_end(value, '/');
151 } else if (!strcmp(name, "name")) { 151 } else if (!strcmp(name, "name")) {
152 ctx.qry.name = xstrdup(value); 152 ctx.qry.name = xstrdup(value);
153 } else if (!strcmp(name, "mimetype")) { 153 } else if (!strcmp(name, "mimetype")) {
154 ctx.qry.mimetype = xstrdup(value); 154 ctx.qry.mimetype = xstrdup(value);
155 } 155 }
156} 156}
157 157
158static void prepare_context(struct cgit_context *ctx) 158static void prepare_context(struct cgit_context *ctx)
159{ 159{
160 memset(ctx, 0, sizeof(ctx)); 160 memset(ctx, 0, sizeof(ctx));
161 ctx->cfg.agefile = "info/web/last-modified"; 161 ctx->cfg.agefile = "info/web/last-modified";
162 ctx->cfg.nocache = 0; 162 ctx->cfg.nocache = 0;
163 ctx->cfg.cache_size = 0; 163 ctx->cfg.cache_size = 0;
164 ctx->cfg.cache_dynamic_ttl = 5; 164 ctx->cfg.cache_dynamic_ttl = 5;
165 ctx->cfg.cache_max_create_time = 5; 165 ctx->cfg.cache_max_create_time = 5;
166 ctx->cfg.cache_repo_ttl = 5; 166 ctx->cfg.cache_repo_ttl = 5;
167 ctx->cfg.cache_root = CGIT_CACHE_ROOT; 167 ctx->cfg.cache_root = CGIT_CACHE_ROOT;
168 ctx->cfg.cache_root_ttl = 5; 168 ctx->cfg.cache_root_ttl = 5;
169 ctx->cfg.cache_static_ttl = -1; 169 ctx->cfg.cache_static_ttl = -1;
170 ctx->cfg.css = "/cgit.css"; 170 ctx->cfg.css = "/cgit.css";
171 ctx->cfg.logo = "/git-logo.png"; 171 ctx->cfg.logo = "/git-logo.png";
172 ctx->cfg.local_time = 0; 172 ctx->cfg.local_time = 0;
173 ctx->cfg.max_repo_count = 50; 173 ctx->cfg.max_repo_count = 50;
174 ctx->cfg.max_commit_count = 50; 174 ctx->cfg.max_commit_count = 50;
175 ctx->cfg.max_lock_attempts = 5; 175 ctx->cfg.max_lock_attempts = 5;
176 ctx->cfg.max_msg_len = 80; 176 ctx->cfg.max_msg_len = 80;
177 ctx->cfg.max_repodesc_len = 80; 177 ctx->cfg.max_repodesc_len = 80;
178 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 178 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
179 ctx->cfg.renamelimit = -1; 179 ctx->cfg.renamelimit = -1;
180 ctx->cfg.robots = "index, nofollow"; 180 ctx->cfg.robots = "index, nofollow";
181 ctx->cfg.root_title = "Git repository browser"; 181 ctx->cfg.root_title = "Git repository browser";
182 ctx->cfg.root_desc = "a fast webinterface for the git dscm"; 182 ctx->cfg.root_desc = "a fast webinterface for the git dscm";
183 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 183 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
184 ctx->cfg.summary_branches = 10; 184 ctx->cfg.summary_branches = 10;
185 ctx->cfg.summary_log = 10; 185 ctx->cfg.summary_log = 10;
186 ctx->cfg.summary_tags = 10; 186 ctx->cfg.summary_tags = 10;
187 ctx->page.mimetype = "text/html"; 187 ctx->page.mimetype = "text/html";
188 ctx->page.charset = PAGE_ENCODING; 188 ctx->page.charset = PAGE_ENCODING;
189 ctx->page.filename = NULL; 189 ctx->page.filename = NULL;
190 ctx->page.size = 0;
190 ctx->page.modified = time(NULL); 191 ctx->page.modified = time(NULL);
191 ctx->page.expires = ctx->page.modified; 192 ctx->page.expires = ctx->page.modified;
192} 193}
193 194
194struct refmatch { 195struct refmatch {
195 char *req_ref; 196 char *req_ref;
196 char *first_ref; 197 char *first_ref;
197 int match; 198 int match;
198}; 199};
199 200
200int find_current_ref(const char *refname, const unsigned char *sha1, 201int find_current_ref(const char *refname, const unsigned char *sha1,
201 int flags, void *cb_data) 202 int flags, void *cb_data)
202{ 203{
203 struct refmatch *info; 204 struct refmatch *info;
204 205
205 info = (struct refmatch *)cb_data; 206 info = (struct refmatch *)cb_data;
206 if (!strcmp(refname, info->req_ref)) 207 if (!strcmp(refname, info->req_ref))
207 info->match = 1; 208 info->match = 1;
208 if (!info->first_ref) 209 if (!info->first_ref)
209 info->first_ref = xstrdup(refname); 210 info->first_ref = xstrdup(refname);
210 return info->match; 211 return info->match;
211} 212}
212 213
213char *find_default_branch(struct cgit_repo *repo) 214char *find_default_branch(struct cgit_repo *repo)
214{ 215{
215 struct refmatch info; 216 struct refmatch info;
216 char *ref; 217 char *ref;
217 218
218 info.req_ref = repo->defbranch; 219 info.req_ref = repo->defbranch;
219 info.first_ref = NULL; 220 info.first_ref = NULL;
220 info.match = 0; 221 info.match = 0;
221 for_each_branch_ref(find_current_ref, &info); 222 for_each_branch_ref(find_current_ref, &info);
222 if (info.match) 223 if (info.match)
223 ref = info.req_ref; 224 ref = info.req_ref;
224 else 225 else
225 ref = info.first_ref; 226 ref = info.first_ref;
226 if (ref) 227 if (ref)
227 ref = xstrdup(ref); 228 ref = xstrdup(ref);
228 return ref; 229 return ref;
229} 230}
230 231
231static int prepare_repo_cmd(struct cgit_context *ctx) 232static int prepare_repo_cmd(struct cgit_context *ctx)
232{ 233{
233 char *tmp; 234 char *tmp;
234 unsigned char sha1[20]; 235 unsigned char sha1[20];
235 int nongit = 0; 236 int nongit = 0;
236 237
237 setenv("GIT_DIR", ctx->repo->path, 1); 238 setenv("GIT_DIR", ctx->repo->path, 1);
diff --git a/cgit.h b/cgit.h
index a1fa841..1615616 100644
--- a/cgit.h
+++ b/cgit.h
@@ -121,96 +121,97 @@ struct cgit_query {
121 int ofs; 121 int ofs;
122}; 122};
123 123
124struct cgit_config { 124struct cgit_config {
125 char *agefile; 125 char *agefile;
126 char *cache_root; 126 char *cache_root;
127 char *clone_prefix; 127 char *clone_prefix;
128 char *css; 128 char *css;
129 char *favicon; 129 char *favicon;
130 char *footer; 130 char *footer;
131 char *index_header; 131 char *index_header;
132 char *index_info; 132 char *index_info;
133 char *logo; 133 char *logo;
134 char *logo_link; 134 char *logo_link;
135 char *module_link; 135 char *module_link;
136 char *repo_group; 136 char *repo_group;
137 char *robots; 137 char *robots;
138 char *root_title; 138 char *root_title;
139 char *root_desc; 139 char *root_desc;
140 char *root_readme; 140 char *root_readme;
141 char *script_name; 141 char *script_name;
142 char *virtual_root; 142 char *virtual_root;
143 int cache_size; 143 int cache_size;
144 int cache_dynamic_ttl; 144 int cache_dynamic_ttl;
145 int cache_max_create_time; 145 int cache_max_create_time;
146 int cache_repo_ttl; 146 int cache_repo_ttl;
147 int cache_root_ttl; 147 int cache_root_ttl;
148 int cache_static_ttl; 148 int cache_static_ttl;
149 int enable_index_links; 149 int enable_index_links;
150 int enable_log_filecount; 150 int enable_log_filecount;
151 int enable_log_linecount; 151 int enable_log_linecount;
152 int local_time; 152 int local_time;
153 int max_repo_count; 153 int max_repo_count;
154 int max_commit_count; 154 int max_commit_count;
155 int max_lock_attempts; 155 int max_lock_attempts;
156 int max_msg_len; 156 int max_msg_len;
157 int max_repodesc_len; 157 int max_repodesc_len;
158 int nocache; 158 int nocache;
159 int renamelimit; 159 int renamelimit;
160 int snapshots; 160 int snapshots;
161 int summary_branches; 161 int summary_branches;
162 int summary_log; 162 int summary_log;
163 int summary_tags; 163 int summary_tags;
164}; 164};
165 165
166struct cgit_page { 166struct cgit_page {
167 time_t modified; 167 time_t modified;
168 time_t expires; 168 time_t expires;
169 size_t size;
169 char *mimetype; 170 char *mimetype;
170 char *charset; 171 char *charset;
171 char *filename; 172 char *filename;
172 char *title; 173 char *title;
173}; 174};
174 175
175struct cgit_context { 176struct cgit_context {
176 struct cgit_query qry; 177 struct cgit_query qry;
177 struct cgit_config cfg; 178 struct cgit_config cfg;
178 struct cgit_repo *repo; 179 struct cgit_repo *repo;
179 struct cgit_page page; 180 struct cgit_page page;
180}; 181};
181 182
182struct cgit_snapshot_format { 183struct cgit_snapshot_format {
183 const char *suffix; 184 const char *suffix;
184 const char *mimetype; 185 const char *mimetype;
185 write_archive_fn_t write_func; 186 write_archive_fn_t write_func;
186 int bit; 187 int bit;
187}; 188};
188 189
189extern const char *cgit_version; 190extern const char *cgit_version;
190 191
191extern struct cgit_repolist cgit_repolist; 192extern struct cgit_repolist cgit_repolist;
192extern struct cgit_context ctx; 193extern struct cgit_context ctx;
193extern const struct cgit_snapshot_format cgit_snapshot_formats[]; 194extern const struct cgit_snapshot_format cgit_snapshot_formats[];
194 195
195extern struct cgit_repo *cgit_add_repo(const char *url); 196extern struct cgit_repo *cgit_add_repo(const char *url);
196extern struct cgit_repo *cgit_get_repoinfo(const char *url); 197extern struct cgit_repo *cgit_get_repoinfo(const char *url);
197extern void cgit_repo_config_cb(const char *name, const char *value); 198extern void cgit_repo_config_cb(const char *name, const char *value);
198 199
199extern int chk_zero(int result, char *msg); 200extern int chk_zero(int result, char *msg);
200extern int chk_positive(int result, char *msg); 201extern int chk_positive(int result, char *msg);
201extern int chk_non_negative(int result, char *msg); 202extern int chk_non_negative(int result, char *msg);
202 203
203extern char *trim_end(const char *str, char c); 204extern char *trim_end(const char *str, char c);
204extern char *strlpart(char *txt, int maxlen); 205extern char *strlpart(char *txt, int maxlen);
205extern char *strrpart(char *txt, int maxlen); 206extern char *strrpart(char *txt, int maxlen);
206 207
207extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); 208extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
208extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, 209extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
209 int flags, void *cb_data); 210 int flags, void *cb_data);
210 211
211extern void *cgit_free_commitinfo(struct commitinfo *info); 212extern void *cgit_free_commitinfo(struct commitinfo *info);
212 213
213extern int cgit_diff_files(const unsigned char *old_sha1, 214extern int cgit_diff_files(const unsigned char *old_sha1,
214 const unsigned char *new_sha1, 215 const unsigned char *new_sha1,
215 linediff_fn fn); 216 linediff_fn fn);
216 217
diff --git a/cmd.c b/cmd.c
index 40ac53e..a989220 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,158 +1,165 @@
1/* cmd.c: the cgit command dispatcher 1/* cmd.c: the cgit command dispatcher
2 * 2 *
3 * Copyright (C) 2008 Lars Hjemli 3 * Copyright (C) 2008 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cmd.h" 10#include "cmd.h"
11#include "cache.h" 11#include "cache.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13#include "ui-atom.h" 13#include "ui-atom.h"
14#include "ui-blob.h" 14#include "ui-blob.h"
15#include "ui-clone.h" 15#include "ui-clone.h"
16#include "ui-commit.h" 16#include "ui-commit.h"
17#include "ui-diff.h" 17#include "ui-diff.h"
18#include "ui-log.h" 18#include "ui-log.h"
19#include "ui-patch.h" 19#include "ui-patch.h"
20#include "ui-plain.h"
20#include "ui-refs.h" 21#include "ui-refs.h"
21#include "ui-repolist.h" 22#include "ui-repolist.h"
22#include "ui-snapshot.h" 23#include "ui-snapshot.h"
23#include "ui-summary.h" 24#include "ui-summary.h"
24#include "ui-tag.h" 25#include "ui-tag.h"
25#include "ui-tree.h" 26#include "ui-tree.h"
26 27
27static void HEAD_fn(struct cgit_context *ctx) 28static void HEAD_fn(struct cgit_context *ctx)
28{ 29{
29 cgit_clone_head(ctx); 30 cgit_clone_head(ctx);
30} 31}
31 32
32static void atom_fn(struct cgit_context *ctx) 33static void atom_fn(struct cgit_context *ctx)
33{ 34{
34 cgit_print_atom(ctx->qry.head, ctx->qry.path, 10); 35 cgit_print_atom(ctx->qry.head, ctx->qry.path, 10);
35} 36}
36 37
37static void about_fn(struct cgit_context *ctx) 38static void about_fn(struct cgit_context *ctx)
38{ 39{
39 if (ctx->repo) 40 if (ctx->repo)
40 cgit_print_repo_readme(); 41 cgit_print_repo_readme();
41 else 42 else
42 cgit_print_site_readme(); 43 cgit_print_site_readme();
43} 44}
44 45
45static void blob_fn(struct cgit_context *ctx) 46static void blob_fn(struct cgit_context *ctx)
46{ 47{
47 cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head); 48 cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head);
48} 49}
49 50
50static void commit_fn(struct cgit_context *ctx) 51static void commit_fn(struct cgit_context *ctx)
51{ 52{
52 cgit_print_commit(ctx->qry.sha1); 53 cgit_print_commit(ctx->qry.sha1);
53} 54}
54 55
55static void diff_fn(struct cgit_context *ctx) 56static void diff_fn(struct cgit_context *ctx)
56{ 57{
57 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); 58 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
58} 59}
59 60
60static void info_fn(struct cgit_context *ctx) 61static void info_fn(struct cgit_context *ctx)
61{ 62{
62 cgit_clone_info(ctx); 63 cgit_clone_info(ctx);
63} 64}
64 65
65static void log_fn(struct cgit_context *ctx) 66static void log_fn(struct cgit_context *ctx)
66{ 67{
67 cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, 68 cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count,
68 ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); 69 ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1);
69} 70}
70 71
71static void ls_cache_fn(struct cgit_context *ctx) 72static void ls_cache_fn(struct cgit_context *ctx)
72{ 73{
73 ctx->page.mimetype = "text/plain"; 74 ctx->page.mimetype = "text/plain";
74 ctx->page.filename = "ls-cache.txt"; 75 ctx->page.filename = "ls-cache.txt";
75 cgit_print_http_headers(ctx); 76 cgit_print_http_headers(ctx);
76 cache_ls(ctx->cfg.cache_root); 77 cache_ls(ctx->cfg.cache_root);
77} 78}
78 79
79static void objects_fn(struct cgit_context *ctx) 80static void objects_fn(struct cgit_context *ctx)
80{ 81{
81 cgit_clone_objects(ctx); 82 cgit_clone_objects(ctx);
82} 83}
83 84
84static void repolist_fn(struct cgit_context *ctx) 85static void repolist_fn(struct cgit_context *ctx)
85{ 86{
86 cgit_print_repolist(); 87 cgit_print_repolist();
87} 88}
88 89
89static void patch_fn(struct cgit_context *ctx) 90static void patch_fn(struct cgit_context *ctx)
90{ 91{
91 cgit_print_patch(ctx->qry.sha1); 92 cgit_print_patch(ctx->qry.sha1);
92} 93}
93 94
95static void plain_fn(struct cgit_context *ctx)
96{
97 cgit_print_plain(ctx);
98}
99
94static void refs_fn(struct cgit_context *ctx) 100static void refs_fn(struct cgit_context *ctx)
95{ 101{
96 cgit_print_refs(); 102 cgit_print_refs();
97} 103}
98 104
99static void snapshot_fn(struct cgit_context *ctx) 105static void snapshot_fn(struct cgit_context *ctx)
100{ 106{
101 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, 107 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1,
102 cgit_repobasename(ctx->repo->url), ctx->qry.path, 108 cgit_repobasename(ctx->repo->url), ctx->qry.path,
103 ctx->repo->snapshots); 109 ctx->repo->snapshots);
104} 110}
105 111
106static void summary_fn(struct cgit_context *ctx) 112static void summary_fn(struct cgit_context *ctx)
107{ 113{
108 cgit_print_summary(); 114 cgit_print_summary();
109} 115}
110 116
111static void tag_fn(struct cgit_context *ctx) 117static void tag_fn(struct cgit_context *ctx)
112{ 118{
113 cgit_print_tag(ctx->qry.sha1); 119 cgit_print_tag(ctx->qry.sha1);
114} 120}
115 121
116static void tree_fn(struct cgit_context *ctx) 122static void tree_fn(struct cgit_context *ctx)
117{ 123{
118 cgit_print_tree(ctx->qry.sha1, ctx->qry.path); 124 cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
119} 125}
120 126
121#define def_cmd(name, want_repo, want_layout) \ 127#define def_cmd(name, want_repo, want_layout) \
122 {#name, name##_fn, want_repo, want_layout} 128 {#name, name##_fn, want_repo, want_layout}
123 129
124struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) 130struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
125{ 131{
126 static struct cgit_cmd cmds[] = { 132 static struct cgit_cmd cmds[] = {
127 def_cmd(HEAD, 1, 0), 133 def_cmd(HEAD, 1, 0),
128 def_cmd(atom, 1, 0), 134 def_cmd(atom, 1, 0),
129 def_cmd(about, 0, 1), 135 def_cmd(about, 0, 1),
130 def_cmd(blob, 1, 0), 136 def_cmd(blob, 1, 0),
131 def_cmd(commit, 1, 1), 137 def_cmd(commit, 1, 1),
132 def_cmd(diff, 1, 1), 138 def_cmd(diff, 1, 1),
133 def_cmd(info, 1, 0), 139 def_cmd(info, 1, 0),
134 def_cmd(log, 1, 1), 140 def_cmd(log, 1, 1),
135 def_cmd(ls_cache, 0, 0), 141 def_cmd(ls_cache, 0, 0),
136 def_cmd(objects, 1, 0), 142 def_cmd(objects, 1, 0),
137 def_cmd(patch, 1, 0), 143 def_cmd(patch, 1, 0),
144 def_cmd(plain, 1, 0),
138 def_cmd(refs, 1, 1), 145 def_cmd(refs, 1, 1),
139 def_cmd(repolist, 0, 0), 146 def_cmd(repolist, 0, 0),
140 def_cmd(snapshot, 1, 0), 147 def_cmd(snapshot, 1, 0),
141 def_cmd(summary, 1, 1), 148 def_cmd(summary, 1, 1),
142 def_cmd(tag, 1, 1), 149 def_cmd(tag, 1, 1),
143 def_cmd(tree, 1, 1), 150 def_cmd(tree, 1, 1),
144 }; 151 };
145 int i; 152 int i;
146 153
147 if (ctx->qry.page == NULL) { 154 if (ctx->qry.page == NULL) {
148 if (ctx->repo) 155 if (ctx->repo)
149 ctx->qry.page = "summary"; 156 ctx->qry.page = "summary";
150 else 157 else
151 ctx->qry.page = "repolist"; 158 ctx->qry.page = "repolist";
152 } 159 }
153 160
154 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) 161 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
155 if (!strcmp(ctx->qry.page, cmds[i].name)) 162 if (!strcmp(ctx->qry.page, cmds[i].name))
156 return &cmds[i]; 163 return &cmds[i];
157 return NULL; 164 return NULL;
158} 165}
diff --git a/html.c b/html.c
index 1237076..36e9a2f 100644
--- a/html.c
+++ b/html.c
@@ -1,104 +1,109 @@
1/* html.c: helper functions for html output 1/* html.c: helper functions for html 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 <unistd.h> 9#include <unistd.h>
10#include <stdio.h> 10#include <stdio.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#include <stdarg.h> 12#include <stdarg.h>
13#include <string.h> 13#include <string.h>
14#include <errno.h> 14#include <errno.h>
15 15
16int htmlfd = STDOUT_FILENO; 16int htmlfd = STDOUT_FILENO;
17 17
18char *fmt(const char *format, ...) 18char *fmt(const char *format, ...)
19{ 19{
20 static char buf[8][1024]; 20 static char buf[8][1024];
21 static int bufidx; 21 static int bufidx;
22 int len; 22 int len;
23 va_list args; 23 va_list args;
24 24
25 bufidx++; 25 bufidx++;
26 bufidx &= 7; 26 bufidx &= 7;
27 27
28 va_start(args, format); 28 va_start(args, format);
29 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); 29 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
30 va_end(args); 30 va_end(args);
31 if (len>sizeof(buf[bufidx])) { 31 if (len>sizeof(buf[bufidx])) {
32 fprintf(stderr, "[html.c] string truncated: %s\n", format); 32 fprintf(stderr, "[html.c] string truncated: %s\n", format);
33 exit(1); 33 exit(1);
34 } 34 }
35 return buf[bufidx]; 35 return buf[bufidx];
36} 36}
37 37
38void html_raw(const char *data, size_t size)
39{
40 write(htmlfd, data, size);
41}
42
38void html(const char *txt) 43void html(const char *txt)
39{ 44{
40 write(htmlfd, txt, strlen(txt)); 45 write(htmlfd, txt, strlen(txt));
41} 46}
42 47
43void htmlf(const char *format, ...) 48void htmlf(const char *format, ...)
44{ 49{
45 static char buf[65536]; 50 static char buf[65536];
46 va_list args; 51 va_list args;
47 52
48 va_start(args, format); 53 va_start(args, format);
49 vsnprintf(buf, sizeof(buf), format, args); 54 vsnprintf(buf, sizeof(buf), format, args);
50 va_end(args); 55 va_end(args);
51 html(buf); 56 html(buf);
52} 57}
53 58
54void html_status(int code, int more_headers) 59void html_status(int code, const char *msg, int more_headers)
55{ 60{
56 htmlf("Status: %d\n", code); 61 htmlf("Status: %d %s\n", code, msg);
57 if (!more_headers) 62 if (!more_headers)
58 html("\n"); 63 html("\n");
59} 64}
60 65
61void html_txt(char *txt) 66void html_txt(char *txt)
62{ 67{
63 char *t = txt; 68 char *t = txt;
64 while(t && *t){ 69 while(t && *t){
65 int c = *t; 70 int c = *t;
66 if (c=='<' || c=='>' || c=='&') { 71 if (c=='<' || c=='>' || c=='&') {
67 write(htmlfd, txt, t - txt); 72 write(htmlfd, txt, t - txt);
68 if (c=='>') 73 if (c=='>')
69 html("&gt;"); 74 html("&gt;");
70 else if (c=='<') 75 else if (c=='<')
71 html("&lt;"); 76 html("&lt;");
72 else if (c=='&') 77 else if (c=='&')
73 html("&amp;"); 78 html("&amp;");
74 txt = t+1; 79 txt = t+1;
75 } 80 }
76 t++; 81 t++;
77 } 82 }
78 if (t!=txt) 83 if (t!=txt)
79 html(txt); 84 html(txt);
80} 85}
81 86
82void html_ntxt(int len, char *txt) 87void html_ntxt(int len, char *txt)
83{ 88{
84 char *t = txt; 89 char *t = txt;
85 while(t && *t && len--){ 90 while(t && *t && len--){
86 int c = *t; 91 int c = *t;
87 if (c=='<' || c=='>' || c=='&') { 92 if (c=='<' || c=='>' || c=='&') {
88 write(htmlfd, txt, t - txt); 93 write(htmlfd, txt, t - txt);
89 if (c=='>') 94 if (c=='>')
90 html("&gt;"); 95 html("&gt;");
91 else if (c=='<') 96 else if (c=='<')
92 html("&lt;"); 97 html("&lt;");
93 else if (c=='&') 98 else if (c=='&')
94 html("&amp;"); 99 html("&amp;");
95 txt = t+1; 100 txt = t+1;
96 } 101 }
97 t++; 102 t++;
98 } 103 }
99 if (t!=txt) 104 if (t!=txt)
100 write(htmlfd, txt, t - txt); 105 write(htmlfd, txt, t - txt);
101 if (len<0) 106 if (len<0)
102 html("..."); 107 html("...");
103} 108}
104 109
diff --git a/html.h b/html.h
index 2bde28d..3c32935 100644
--- a/html.h
+++ b/html.h
@@ -1,21 +1,22 @@
1#ifndef HTML_H 1#ifndef HTML_H
2#define HTML_H 2#define HTML_H
3 3
4extern int htmlfd; 4extern int htmlfd;
5 5
6extern void html_raw(const char *txt, size_t size);
6extern void html(const char *txt); 7extern void html(const char *txt);
7extern void htmlf(const char *format,...); 8extern void htmlf(const char *format,...);
8extern void html_status(int code, int more_headers); 9extern void html_status(int code, const char *msg, int more_headers);
9extern void html_txt(char *txt); 10extern void html_txt(char *txt);
10extern void html_ntxt(int len, char *txt); 11extern void html_ntxt(int len, char *txt);
11extern void html_attr(char *txt); 12extern void html_attr(char *txt);
12extern void html_hidden(char *name, char *value); 13extern void html_hidden(char *name, char *value);
13extern void html_option(char *value, char *text, char *selected_value); 14extern void html_option(char *value, char *text, char *selected_value);
14extern void html_link_open(char *url, char *title, char *class); 15extern void html_link_open(char *url, char *title, char *class);
15extern void html_link_close(void); 16extern void html_link_close(void);
16extern void html_fileperm(unsigned short mode); 17extern void html_fileperm(unsigned short mode);
17extern int html_include(const char *filename); 18extern int html_include(const char *filename);
18 19
19extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); 20extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value));
20 21
21#endif /* HTML_H */ 22#endif /* HTML_H */
diff --git a/ui-clone.c b/ui-clone.c
index 3a037ad..81e7a4e 100644
--- a/ui-clone.c
+++ b/ui-clone.c
@@ -3,102 +3,100 @@
3 * 3 *
4 * Copyright (C) 2008 Lars Hjemli 4 * Copyright (C) 2008 Lars Hjemli
5 * 5 *
6 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text) 7 * (see COPYING for full license text)
8 */ 8 */
9 9
10#include "cgit.h" 10#include "cgit.h"
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13 13
14static int print_ref_info(const char *refname, const unsigned char *sha1, 14static int print_ref_info(const char *refname, const unsigned char *sha1,
15 int flags, void *cb_data) 15 int flags, void *cb_data)
16{ 16{
17 struct object *obj; 17 struct object *obj;
18 18
19 if (!(obj = parse_object(sha1))) 19 if (!(obj = parse_object(sha1)))
20 return 0; 20 return 0;
21 21
22 if (!strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/")) 22 if (!strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/"))
23 htmlf("%s\t%s\n", sha1_to_hex(sha1), refname); 23 htmlf("%s\t%s\n", sha1_to_hex(sha1), refname);
24 else if (!prefixcmp(refname, "refs/tags") && obj->type == OBJ_TAG) { 24 else if (!prefixcmp(refname, "refs/tags") && obj->type == OBJ_TAG) {
25 if (!(obj = deref_tag(obj, refname, 0))) 25 if (!(obj = deref_tag(obj, refname, 0)))
26 return 0; 26 return 0;
27 htmlf("%s\t%s\n", sha1_to_hex(sha1), refname); 27 htmlf("%s\t%s\n", sha1_to_hex(sha1), refname);
28 htmlf("%s\t%s^{}\n", sha1_to_hex(obj->sha1), refname); 28 htmlf("%s\t%s^{}\n", sha1_to_hex(obj->sha1), refname);
29 } 29 }
30 return 0; 30 return 0;
31} 31}
32 32
33static void print_pack_info(struct cgit_context *ctx) 33static void print_pack_info(struct cgit_context *ctx)
34{ 34{
35 struct packed_git *pack; 35 struct packed_git *pack;
36 int ofs; 36 int ofs;
37 37
38 ctx->page.mimetype = "text/plain"; 38 ctx->page.mimetype = "text/plain";
39 ctx->page.filename = "objects/info/packs"; 39 ctx->page.filename = "objects/info/packs";
40 cgit_print_http_headers(ctx); 40 cgit_print_http_headers(ctx);
41 ofs = strlen(ctx->repo->path) + strlen("/objects/pack/"); 41 ofs = strlen(ctx->repo->path) + strlen("/objects/pack/");
42 prepare_packed_git(); 42 prepare_packed_git();
43 for (pack = packed_git; pack; pack = pack->next) 43 for (pack = packed_git; pack; pack = pack->next)
44 if (pack->pack_local) 44 if (pack->pack_local)
45 htmlf("P %s\n", pack->pack_name + ofs); 45 htmlf("P %s\n", pack->pack_name + ofs);
46} 46}
47 47
48static void send_file(struct cgit_context *ctx, char *path) 48static void send_file(struct cgit_context *ctx, char *path)
49{ 49{
50 struct stat st; 50 struct stat st;
51 int err;
52 51
53 if (stat(path, &st)) { 52 if (stat(path, &st)) {
54 switch (errno) { 53 switch (errno) {
55 case ENOENT: 54 case ENOENT:
56 err = 404; 55 html_status(404, "Not found", 0);
57 break; 56 break;
58 case EACCES: 57 case EACCES:
59 err = 403; 58 html_status(403, "Forbidden", 0);
60 break; 59 break;
61 default: 60 default:
62 err = 400; 61 html_status(400, "Bad request", 0);
63 } 62 }
64 html_status(err, 0);
65 return; 63 return;
66 } 64 }
67 ctx->page.mimetype = "application/octet-stream"; 65 ctx->page.mimetype = "application/octet-stream";
68 ctx->page.filename = path; 66 ctx->page.filename = path;
69 if (prefixcmp(ctx->repo->path, path)) 67 if (prefixcmp(ctx->repo->path, path))
70 ctx->page.filename += strlen(ctx->repo->path) + 1; 68 ctx->page.filename += strlen(ctx->repo->path) + 1;
71 cgit_print_http_headers(ctx); 69 cgit_print_http_headers(ctx);
72 html_include(path); 70 html_include(path);
73} 71}
74 72
75void cgit_clone_info(struct cgit_context *ctx) 73void cgit_clone_info(struct cgit_context *ctx)
76{ 74{
77 if (!ctx->qry.path || strcmp(ctx->qry.path, "refs")) 75 if (!ctx->qry.path || strcmp(ctx->qry.path, "refs"))
78 return; 76 return;
79 77
80 ctx->page.mimetype = "text/plain"; 78 ctx->page.mimetype = "text/plain";
81 ctx->page.filename = "info/refs"; 79 ctx->page.filename = "info/refs";
82 cgit_print_http_headers(ctx); 80 cgit_print_http_headers(ctx);
83 for_each_ref(print_ref_info, ctx); 81 for_each_ref(print_ref_info, ctx);
84} 82}
85 83
86void cgit_clone_objects(struct cgit_context *ctx) 84void cgit_clone_objects(struct cgit_context *ctx)
87{ 85{
88 if (!ctx->qry.path) { 86 if (!ctx->qry.path) {
89 html_status(400, 0); 87 html_status(400, "Bad request", 0);
90 return; 88 return;
91 } 89 }
92 90
93 if (!strcmp(ctx->qry.path, "info/packs")) { 91 if (!strcmp(ctx->qry.path, "info/packs")) {
94 print_pack_info(ctx); 92 print_pack_info(ctx);
95 return; 93 return;
96 } 94 }
97 95
98 send_file(ctx, git_path("objects/%s", ctx->qry.path)); 96 send_file(ctx, git_path("objects/%s", ctx->qry.path));
99} 97}
100 98
101void cgit_clone_head(struct cgit_context *ctx) 99void cgit_clone_head(struct cgit_context *ctx)
102{ 100{
103 send_file(ctx, git_path("%s", "HEAD")); 101 send_file(ctx, git_path("%s", "HEAD"));
104} 102}
diff --git a/ui-plain.c b/ui-plain.c
new file mode 100644
index 0000000..35888a0
--- a/dev/null
+++ b/ui-plain.c
@@ -0,0 +1,82 @@
1/* ui-plain.c: functions for output of plain blobs by path
2 *
3 * Copyright (C) 2008 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#include "html.h"
11#include "ui-shared.h"
12
13char *curr_rev;
14char *match_path;
15int match;
16
17static void print_object(const unsigned char *sha1, const char *path)
18{
19 enum object_type type;
20 char *buf;
21 size_t size;
22
23 type = sha1_object_info(sha1, &size);
24 if (type == OBJ_BAD) {
25 html_status(404, "Not found", 0);
26 return;
27 }
28
29 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) {
31 html_status(404, "Not found", 0);
32 return;
33 }
34 ctx.page.mimetype = "text/plain";
35 ctx.page.filename = fmt("%s", path);
36 ctx.page.size = size;
37 cgit_print_http_headers(&ctx);
38 html_raw(buf, size);
39 match = 1;
40}
41
42static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
43 const char *pathname, unsigned mode, int stage,
44 void *cbdata)
45{
46 fprintf(stderr, "[cgit] walk_tree.pathname=%s", pathname);
47
48 if (!pathname || strcmp(match_path, pathname))
49 return READ_TREE_RECURSIVE;
50
51 if (S_ISREG(mode))
52 print_object(sha1, pathname);
53
54 return 0;
55}
56
57void cgit_print_plain(struct cgit_context *ctx)
58{
59 const char *rev = ctx->qry.sha1;
60 unsigned char sha1[20];
61 struct commit *commit;
62 const char *paths[] = {ctx->qry.path, NULL};
63
64 if (!rev)
65 rev = ctx->qry.head;
66
67 curr_rev = xstrdup(rev);
68 if (get_sha1(rev, sha1)) {
69 html_status(404, "Not found", 0);
70 return;
71 }
72 commit = lookup_commit_reference(sha1);
73 if (!commit || parse_commit(commit)) {
74 html_status(404, "Not found", 0);
75 return;
76 }
77 match_path = ctx->qry.path;
78 fprintf(stderr, "[cgit] match_path=%s", match_path);
79 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL);
80 if (!match)
81 html_status(404, "Not found", 0);
82}
diff --git a/ui-plain.h b/ui-plain.h
new file mode 100644
index 0000000..4373118
--- a/dev/null
+++ b/ui-plain.h
@@ -0,0 +1,6 @@
1#ifndef UI_PLAIN_H
2#define UI_PLAIN_H
3
4extern void cgit_print_plain(struct cgit_context *ctx);
5
6#endif /* UI_PLAIN_H */
diff --git a/ui-shared.c b/ui-shared.c
index 37c60b2..4818e70 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -213,96 +213,102 @@ static char *repolink(char *title, char *class, char *page, char *head,
213 if (path) 213 if (path)
214 html_attr(path); 214 html_attr(path);
215 } 215 }
216 } else { 216 } else {
217 html(ctx.cfg.script_name); 217 html(ctx.cfg.script_name);
218 html("?url="); 218 html("?url=");
219 html_attr(ctx.repo->url); 219 html_attr(ctx.repo->url);
220 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 220 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
221 html("/"); 221 html("/");
222 if (page) { 222 if (page) {
223 html(page); 223 html(page);
224 html("/"); 224 html("/");
225 if (path) 225 if (path)
226 html_attr(path); 226 html_attr(path);
227 } 227 }
228 delim = "&amp;"; 228 delim = "&amp;";
229 } 229 }
230 if (head && strcmp(head, ctx.repo->defbranch)) { 230 if (head && strcmp(head, ctx.repo->defbranch)) {
231 html(delim); 231 html(delim);
232 html("h="); 232 html("h=");
233 html_attr(head); 233 html_attr(head);
234 delim = "&amp;"; 234 delim = "&amp;";
235 } 235 }
236 return fmt("%s", delim); 236 return fmt("%s", delim);
237} 237}
238 238
239static void reporevlink(char *page, char *name, char *title, char *class, 239static void reporevlink(char *page, char *name, char *title, char *class,
240 char *head, char *rev, char *path) 240 char *head, char *rev, char *path)
241{ 241{
242 char *delim; 242 char *delim;
243 243
244 delim = repolink(title, class, page, head, path); 244 delim = repolink(title, class, page, head, path);
245 if (rev && strcmp(rev, ctx.qry.head)) { 245 if (rev && strcmp(rev, ctx.qry.head)) {
246 html(delim); 246 html(delim);
247 html("id="); 247 html("id=");
248 html_attr(rev); 248 html_attr(rev);
249 } 249 }
250 html("'>"); 250 html("'>");
251 html_txt(name); 251 html_txt(name);
252 html("</a>"); 252 html("</a>");
253} 253}
254 254
255void cgit_tree_link(char *name, char *title, char *class, char *head, 255void cgit_tree_link(char *name, char *title, char *class, char *head,
256 char *rev, char *path) 256 char *rev, char *path)
257{ 257{
258 reporevlink("tree", name, title, class, head, rev, path); 258 reporevlink("tree", name, title, class, head, rev, path);
259} 259}
260 260
261void cgit_plain_link(char *name, char *title, char *class, char *head,
262 char *rev, char *path)
263{
264 reporevlink("plain", name, title, class, head, rev, path);
265}
266
261void cgit_log_link(char *name, char *title, char *class, char *head, 267void cgit_log_link(char *name, char *title, char *class, char *head,
262 char *rev, char *path, int ofs, char *grep, char *pattern) 268 char *rev, char *path, int ofs, char *grep, char *pattern)
263{ 269{
264 char *delim; 270 char *delim;
265 271
266 delim = repolink(title, class, "log", head, path); 272 delim = repolink(title, class, "log", head, path);
267 if (rev && strcmp(rev, ctx.qry.head)) { 273 if (rev && strcmp(rev, ctx.qry.head)) {
268 html(delim); 274 html(delim);
269 html("id="); 275 html("id=");
270 html_attr(rev); 276 html_attr(rev);
271 delim = "&"; 277 delim = "&";
272 } 278 }
273 if (grep && pattern) { 279 if (grep && pattern) {
274 html(delim); 280 html(delim);
275 html("qt="); 281 html("qt=");
276 html_attr(grep); 282 html_attr(grep);
277 delim = "&"; 283 delim = "&";
278 html(delim); 284 html(delim);
279 html("q="); 285 html("q=");
280 html_attr(pattern); 286 html_attr(pattern);
281 } 287 }
282 if (ofs > 0) { 288 if (ofs > 0) {
283 html(delim); 289 html(delim);
284 html("ofs="); 290 html("ofs=");
285 htmlf("%d", ofs); 291 htmlf("%d", ofs);
286 } 292 }
287 html("'>"); 293 html("'>");
288 html_txt(name); 294 html_txt(name);
289 html("</a>"); 295 html("</a>");
290} 296}
291 297
292void cgit_commit_link(char *name, char *title, char *class, char *head, 298void cgit_commit_link(char *name, char *title, char *class, char *head,
293 char *rev) 299 char *rev)
294{ 300{
295 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { 301 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
296 name[ctx.cfg.max_msg_len] = '\0'; 302 name[ctx.cfg.max_msg_len] = '\0';
297 name[ctx.cfg.max_msg_len - 1] = '.'; 303 name[ctx.cfg.max_msg_len - 1] = '.';
298 name[ctx.cfg.max_msg_len - 2] = '.'; 304 name[ctx.cfg.max_msg_len - 2] = '.';
299 name[ctx.cfg.max_msg_len - 3] = '.'; 305 name[ctx.cfg.max_msg_len - 3] = '.';
300 } 306 }
301 reporevlink("commit", name, title, class, head, rev, NULL); 307 reporevlink("commit", name, title, class, head, rev, NULL);
302} 308}
303 309
304void cgit_refs_link(char *name, char *title, char *class, char *head, 310void cgit_refs_link(char *name, char *title, char *class, char *head,
305 char *rev, char *path) 311 char *rev, char *path)
306{ 312{
307 reporevlink("refs", name, title, class, head, rev, path); 313 reporevlink("refs", name, title, class, head, rev, path);
308} 314}
@@ -388,96 +394,98 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
388 time_t now, secs; 394 time_t now, secs;
389 395
390 if (!t) 396 if (!t)
391 return; 397 return;
392 time(&now); 398 time(&now);
393 secs = now - t; 399 secs = now - t;
394 400
395 if (secs > max_relative && max_relative >= 0) { 401 if (secs > max_relative && max_relative >= 0) {
396 cgit_print_date(t, format, ctx.cfg.local_time); 402 cgit_print_date(t, format, ctx.cfg.local_time);
397 return; 403 return;
398 } 404 }
399 405
400 if (secs < TM_HOUR * 2) { 406 if (secs < TM_HOUR * 2) {
401 htmlf("<span class='age-mins'>%.0f min.</span>", 407 htmlf("<span class='age-mins'>%.0f min.</span>",
402 secs * 1.0 / TM_MIN); 408 secs * 1.0 / TM_MIN);
403 return; 409 return;
404 } 410 }
405 if (secs < TM_DAY * 2) { 411 if (secs < TM_DAY * 2) {
406 htmlf("<span class='age-hours'>%.0f hours</span>", 412 htmlf("<span class='age-hours'>%.0f hours</span>",
407 secs * 1.0 / TM_HOUR); 413 secs * 1.0 / TM_HOUR);
408 return; 414 return;
409 } 415 }
410 if (secs < TM_WEEK * 2) { 416 if (secs < TM_WEEK * 2) {
411 htmlf("<span class='age-days'>%.0f days</span>", 417 htmlf("<span class='age-days'>%.0f days</span>",
412 secs * 1.0 / TM_DAY); 418 secs * 1.0 / TM_DAY);
413 return; 419 return;
414 } 420 }
415 if (secs < TM_MONTH * 2) { 421 if (secs < TM_MONTH * 2) {
416 htmlf("<span class='age-weeks'>%.0f weeks</span>", 422 htmlf("<span class='age-weeks'>%.0f weeks</span>",
417 secs * 1.0 / TM_WEEK); 423 secs * 1.0 / TM_WEEK);
418 return; 424 return;
419 } 425 }
420 if (secs < TM_YEAR * 2) { 426 if (secs < TM_YEAR * 2) {
421 htmlf("<span class='age-months'>%.0f months</span>", 427 htmlf("<span class='age-months'>%.0f months</span>",
422 secs * 1.0 / TM_MONTH); 428 secs * 1.0 / TM_MONTH);
423 return; 429 return;
424 } 430 }
425 htmlf("<span class='age-years'>%.0f years</span>", 431 htmlf("<span class='age-years'>%.0f years</span>",
426 secs * 1.0 / TM_YEAR); 432 secs * 1.0 / TM_YEAR);
427} 433}
428 434
429void cgit_print_http_headers(struct cgit_context *ctx) 435void cgit_print_http_headers(struct cgit_context *ctx)
430{ 436{
431 if (ctx->page.mimetype && ctx->page.charset) 437 if (ctx->page.mimetype && ctx->page.charset)
432 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 438 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
433 ctx->page.charset); 439 ctx->page.charset);
434 else if (ctx->page.mimetype) 440 else if (ctx->page.mimetype)
435 htmlf("Content-Type: %s\n", ctx->page.mimetype); 441 htmlf("Content-Type: %s\n", ctx->page.mimetype);
442 if (ctx->page.size)
443 htmlf("Content-Length: %ld\n", ctx->page.size);
436 if (ctx->page.filename) 444 if (ctx->page.filename)
437 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 445 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
438 ctx->page.filename); 446 ctx->page.filename);
439 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 447 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
440 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 448 htmlf("Expires: %s\n", http_date(ctx->page.expires));
441 html("\n"); 449 html("\n");
442} 450}
443 451
444void cgit_print_docstart(struct cgit_context *ctx) 452void cgit_print_docstart(struct cgit_context *ctx)
445{ 453{
446 char *host = cgit_hosturl(); 454 char *host = cgit_hosturl();
447 html(cgit_doctype); 455 html(cgit_doctype);
448 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 456 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
449 html("<head>\n"); 457 html("<head>\n");
450 html("<title>"); 458 html("<title>");
451 html_txt(ctx->page.title); 459 html_txt(ctx->page.title);
452 html("</title>\n"); 460 html("</title>\n");
453 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 461 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
454 if (ctx->cfg.robots && *ctx->cfg.robots) 462 if (ctx->cfg.robots && *ctx->cfg.robots)
455 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 463 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
456 html("<link rel='stylesheet' type='text/css' href='"); 464 html("<link rel='stylesheet' type='text/css' href='");
457 html_attr(ctx->cfg.css); 465 html_attr(ctx->cfg.css);
458 html("'/>\n"); 466 html("'/>\n");
459 if (ctx->cfg.favicon) { 467 if (ctx->cfg.favicon) {
460 html("<link rel='shortcut icon' href='"); 468 html("<link rel='shortcut icon' href='");
461 html_attr(ctx->cfg.favicon); 469 html_attr(ctx->cfg.favicon);
462 html("'/>\n"); 470 html("'/>\n");
463 } 471 }
464 if (host && ctx->repo) { 472 if (host && ctx->repo) {
465 html("<link rel='alternate' title='Atom feed' href='http://"); 473 html("<link rel='alternate' title='Atom feed' href='http://");
466 html_attr(cgit_hosturl()); 474 html_attr(cgit_hosturl());
467 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, 475 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
468 fmt("h=%s", ctx->qry.head))); 476 fmt("h=%s", ctx->qry.head)));
469 html("' type='application/atom+xml'/>"); 477 html("' type='application/atom+xml'/>");
470 } 478 }
471 html("</head>\n"); 479 html("</head>\n");
472 html("<body>\n"); 480 html("<body>\n");
473} 481}
474 482
475void cgit_print_docend() 483void cgit_print_docend()
476{ 484{
477 html("</div>"); 485 html("</div>");
478 if (ctx.cfg.footer) 486 if (ctx.cfg.footer)
479 html_include(ctx.cfg.footer); 487 html_include(ctx.cfg.footer);
480 else { 488 else {
481 html("<div class='footer'>generated "); 489 html("<div class='footer'>generated ");
482 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); 490 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
483 htmlf(" by cgit %s", cgit_version); 491 htmlf(" by cgit %s", cgit_version);
diff --git a/ui-shared.h b/ui-shared.h
index f4123d3..747f092 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -1,41 +1,43 @@
1#ifndef UI_SHARED_H 1#ifndef UI_SHARED_H
2#define UI_SHARED_H 2#define UI_SHARED_H
3 3
4extern char *cgit_hosturl(); 4extern char *cgit_hosturl();
5extern char *cgit_repourl(const char *reponame); 5extern char *cgit_repourl(const char *reponame);
6extern char *cgit_fileurl(const char *reponame, const char *pagename, 6extern char *cgit_fileurl(const char *reponame, const char *pagename,
7 const char *filename, const char *query); 7 const char *filename, const char *query);
8extern char *cgit_pageurl(const char *reponame, const char *pagename, 8extern char *cgit_pageurl(const char *reponame, const char *pagename,
9 const char *query); 9 const char *query);
10 10
11extern void cgit_index_link(char *name, char *title, char *class, 11extern void cgit_index_link(char *name, char *title, char *class,
12 char *pattern, int ofs); 12 char *pattern, int ofs);
13extern void cgit_tree_link(char *name, char *title, char *class, char *head, 13extern void cgit_tree_link(char *name, char *title, char *class, char *head,
14 char *rev, char *path); 14 char *rev, char *path);
15extern void cgit_plain_link(char *name, char *title, char *class, char *head,
16 char *rev, char *path);
15extern void cgit_log_link(char *name, char *title, char *class, char *head, 17extern void cgit_log_link(char *name, char *title, char *class, char *head,
16 char *rev, char *path, int ofs, char *grep, 18 char *rev, char *path, int ofs, char *grep,
17 char *pattern); 19 char *pattern);
18extern void cgit_commit_link(char *name, char *title, char *class, char *head, 20extern void cgit_commit_link(char *name, char *title, char *class, char *head,
19 char *rev); 21 char *rev);
20extern void cgit_patch_link(char *name, char *title, char *class, char *head, 22extern void cgit_patch_link(char *name, char *title, char *class, char *head,
21 char *rev); 23 char *rev);
22extern void cgit_refs_link(char *name, char *title, char *class, char *head, 24extern void cgit_refs_link(char *name, char *title, char *class, char *head,
23 char *rev, char *path); 25 char *rev, char *path);
24extern void cgit_snapshot_link(char *name, char *title, char *class, 26extern void cgit_snapshot_link(char *name, char *title, char *class,
25 char *head, char *rev, char *archivename); 27 char *head, char *rev, char *archivename);
26extern void cgit_diff_link(char *name, char *title, char *class, char *head, 28extern void cgit_diff_link(char *name, char *title, char *class, char *head,
27 char *new_rev, char *old_rev, char *path); 29 char *new_rev, char *old_rev, char *path);
28extern void cgit_object_link(struct object *obj); 30extern void cgit_object_link(struct object *obj);
29 31
30extern void cgit_print_error(char *msg); 32extern void cgit_print_error(char *msg);
31extern void cgit_print_date(time_t secs, char *format, int local_time); 33extern void cgit_print_date(time_t secs, char *format, int local_time);
32extern void cgit_print_age(time_t t, time_t max_relative, char *format); 34extern void cgit_print_age(time_t t, time_t max_relative, char *format);
33extern void cgit_print_http_headers(struct cgit_context *ctx); 35extern void cgit_print_http_headers(struct cgit_context *ctx);
34extern void cgit_print_docstart(struct cgit_context *ctx); 36extern void cgit_print_docstart(struct cgit_context *ctx);
35extern void cgit_print_docend(); 37extern void cgit_print_docend();
36extern void cgit_print_pageheader(struct cgit_context *ctx); 38extern void cgit_print_pageheader(struct cgit_context *ctx);
37extern void cgit_print_filemode(unsigned short mode); 39extern void cgit_print_filemode(unsigned short mode);
38extern void cgit_print_snapshot_links(const char *repo, const char *head, 40extern void cgit_print_snapshot_links(const char *repo, const char *head,
39 const char *hex, int snapshots); 41 const char *hex, int snapshots);
40 42
41#endif /* UI_SHARED_H */ 43#endif /* UI_SHARED_H */
diff --git a/ui-tree.c b/ui-tree.c
index 9a837e2..79332fc 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,89 +1,89 @@
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#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13char *curr_rev; 13char *curr_rev;
14char *match_path; 14char *match_path;
15int header = 0; 15int header = 0;
16 16
17static void print_object(const unsigned char *sha1, char *path) 17static void print_object(const unsigned char *sha1, char *path)
18{ 18{
19 enum object_type type; 19 enum object_type type;
20 char *buf; 20 char *buf;
21 unsigned long size, lineno, start, idx; 21 unsigned long size, lineno, start, idx;
22 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'>"; 22 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'>";
23 23
24 type = sha1_object_info(sha1, &size); 24 type = sha1_object_info(sha1, &size);
25 if (type == OBJ_BAD) { 25 if (type == OBJ_BAD) {
26 cgit_print_error(fmt("Bad object name: %s", 26 cgit_print_error(fmt("Bad object name: %s",
27 sha1_to_hex(sha1))); 27 sha1_to_hex(sha1)));
28 return; 28 return;
29 } 29 }
30 30
31 buf = read_sha1_file(sha1, &type, &size); 31 buf = read_sha1_file(sha1, &type, &size);
32 if (!buf) { 32 if (!buf) {
33 cgit_print_error(fmt("Error reading object %s", 33 cgit_print_error(fmt("Error reading object %s",
34 sha1_to_hex(sha1))); 34 sha1_to_hex(sha1)));
35 return; 35 return;
36 } 36 }
37 37
38 html(" blob: <a href='"); 38 html(" (");
39 html_attr(cgit_pageurl(ctx.qry.repo, "blob", 39 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
40 fmt("id=%s&path=%s", sha1_to_hex(sha1), path))); 40 curr_rev, path);
41 htmlf("'>%s</a>",sha1_to_hex(sha1)); 41 htmlf(")<br/>blob: %s", sha1_to_hex(sha1));
42 42
43 html("<table summary='blob content' class='blob'>\n"); 43 html("<table summary='blob content' class='blob'>\n");
44 idx = 0; 44 idx = 0;
45 start = 0; 45 start = 0;
46 lineno = 0; 46 lineno = 0;
47 while(idx < size) { 47 while(idx < size) {
48 if (buf[idx] == '\n') { 48 if (buf[idx] == '\n') {
49 buf[idx] = '\0'; 49 buf[idx] = '\0';
50 htmlf(linefmt, ++lineno); 50 htmlf(linefmt, ++lineno);
51 html_txt(buf + start); 51 html_txt(buf + start);
52 html("</td></tr>\n"); 52 html("</td></tr>\n");
53 start = idx + 1; 53 start = idx + 1;
54 } 54 }
55 idx++; 55 idx++;
56 } 56 }
57 htmlf(linefmt, ++lineno); 57 htmlf(linefmt, ++lineno);
58 html_txt(buf + start); 58 html_txt(buf + start);
59 html("</td></tr>\n"); 59 html("</td></tr>\n");
60 html("</table>\n"); 60 html("</table>\n");
61} 61}
62 62
63 63
64static int ls_item(const unsigned char *sha1, const char *base, int baselen, 64static int ls_item(const unsigned char *sha1, const char *base, int baselen,
65 const char *pathname, unsigned int mode, int stage, 65 const char *pathname, unsigned int mode, int stage,
66 void *cbdata) 66 void *cbdata)
67{ 67{
68 char *name; 68 char *name;
69 char *fullpath; 69 char *fullpath;
70 enum object_type type; 70 enum object_type type;
71 unsigned long size = 0; 71 unsigned long size = 0;
72 72
73 name = xstrdup(pathname); 73 name = xstrdup(pathname);
74 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", 74 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
75 ctx.qry.path ? "/" : "", name); 75 ctx.qry.path ? "/" : "", name);
76 76
77 if (!S_ISGITLINK(mode)) { 77 if (!S_ISGITLINK(mode)) {
78 type = sha1_object_info(sha1, &size); 78 type = sha1_object_info(sha1, &size);
79 if (type == OBJ_BAD) { 79 if (type == OBJ_BAD) {
80 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 80 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
81 name, 81 name,
82 sha1_to_hex(sha1)); 82 sha1_to_hex(sha1));
83 return 0; 83 return 0;
84 } 84 }
85 } 85 }
86 86
87 html("<tr><td class='ls-mode'>"); 87 html("<tr><td class='ls-mode'>");
88 cgit_print_filemode(mode); 88 cgit_print_filemode(mode);
89 html("</td><td>"); 89 html("</td><td>");