summaryrefslogtreecommitdiffabout
Unidiff
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.c5
-rw-r--r--html.h1
-rw-r--r--ui-plain.c82
-rw-r--r--ui-plain.h6
-rw-r--r--ui-shared.c2
9 files changed, 106 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 78aad10..a305894 100644
--- a/Makefile
+++ b/Makefile
@@ -40,48 +40,49 @@ endif
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-blob.o 58OBJECTS += ui-blob.o
59OBJECTS += ui-clone.o 59OBJECTS += ui-clone.o
60OBJECTS += ui-commit.o 60OBJECTS += ui-commit.o
61OBJECTS += ui-diff.o 61OBJECTS += ui-diff.o
62OBJECTS += ui-log.o 62OBJECTS += ui-log.o
63OBJECTS += ui-patch.o 63OBJECTS += ui-patch.o
64OBJECTS += ui-plain.o
64OBJECTS += ui-refs.o 65OBJECTS += ui-refs.o
65OBJECTS += ui-repolist.o 66OBJECTS += ui-repolist.o
66OBJECTS += ui-shared.o 67OBJECTS += ui-shared.o
67OBJECTS += ui-snapshot.o 68OBJECTS += ui-snapshot.o
68OBJECTS += ui-summary.o 69OBJECTS += ui-summary.o
69OBJECTS += ui-tag.o 70OBJECTS += ui-tag.o
70OBJECTS += ui-tree.o 71OBJECTS += ui-tree.o
71 72
72ifdef NEEDS_LIBICONV 73ifdef NEEDS_LIBICONV
73 EXTLIBS += -liconv 74 EXTLIBS += -liconv
74endif 75endif
75 76
76 77
77.PHONY: all git test install uninstall clean force-version get-git 78.PHONY: all git test install uninstall clean force-version get-git
78 79
79all: cgit 80all: cgit
80 81
81VERSION: force-version 82VERSION: force-version
82 @./gen-version.sh "$(CGIT_VERSION)" 83 @./gen-version.sh "$(CGIT_VERSION)"
83-include VERSION 84-include VERSION
84 85
85 86
86CFLAGS += -g -Wall -Igit 87CFLAGS += -g -Wall -Igit
87CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 88CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
diff --git a/cgit.c b/cgit.c
index f49fffa..497337b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -166,48 +166,49 @@ static void prepare_context(struct cgit_context *ctx)
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)
diff --git a/cgit.h b/cgit.h
index b01fa31..e2af0c2 100644
--- a/cgit.h
+++ b/cgit.h
@@ -144,48 +144,49 @@ struct cgit_config {
144 int cache_max_create_time; 144 int cache_max_create_time;
145 int cache_repo_ttl; 145 int cache_repo_ttl;
146 int cache_root_ttl; 146 int cache_root_ttl;
147 int cache_static_ttl; 147 int cache_static_ttl;
148 int enable_index_links; 148 int enable_index_links;
149 int enable_log_filecount; 149 int enable_log_filecount;
150 int enable_log_linecount; 150 int enable_log_linecount;
151 int local_time; 151 int local_time;
152 int max_repo_count; 152 int max_repo_count;
153 int max_commit_count; 153 int max_commit_count;
154 int max_lock_attempts; 154 int max_lock_attempts;
155 int max_msg_len; 155 int max_msg_len;
156 int max_repodesc_len; 156 int max_repodesc_len;
157 int nocache; 157 int nocache;
158 int renamelimit; 158 int renamelimit;
159 int snapshots; 159 int snapshots;
160 int summary_branches; 160 int summary_branches;
161 int summary_log; 161 int summary_log;
162 int summary_tags; 162 int summary_tags;
163}; 163};
164 164
165struct cgit_page { 165struct cgit_page {
166 time_t modified; 166 time_t modified;
167 time_t expires; 167 time_t expires;
168 size_t size;
168 char *mimetype; 169 char *mimetype;
169 char *charset; 170 char *charset;
170 char *filename; 171 char *filename;
171 char *title; 172 char *title;
172}; 173};
173 174
174struct cgit_context { 175struct cgit_context {
175 struct cgit_query qry; 176 struct cgit_query qry;
176 struct cgit_config cfg; 177 struct cgit_config cfg;
177 struct cgit_repo *repo; 178 struct cgit_repo *repo;
178 struct cgit_page page; 179 struct cgit_page page;
179}; 180};
180 181
181struct cgit_snapshot_format { 182struct cgit_snapshot_format {
182 const char *suffix; 183 const char *suffix;
183 const char *mimetype; 184 const char *mimetype;
184 write_archive_fn_t write_func; 185 write_archive_fn_t write_func;
185 int bit; 186 int bit;
186}; 187};
187 188
188extern const char *cgit_version; 189extern const char *cgit_version;
189 190
190extern struct cgit_repolist cgit_repolist; 191extern struct cgit_repolist cgit_repolist;
191extern struct cgit_context ctx; 192extern struct cgit_context ctx;
diff --git a/cmd.c b/cmd.c
index 03e165c..2b34189 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,42 +1,43 @@
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-blob.h" 13#include "ui-blob.h"
14#include "ui-clone.h" 14#include "ui-clone.h"
15#include "ui-commit.h" 15#include "ui-commit.h"
16#include "ui-diff.h" 16#include "ui-diff.h"
17#include "ui-log.h" 17#include "ui-log.h"
18#include "ui-patch.h" 18#include "ui-patch.h"
19#include "ui-plain.h"
19#include "ui-refs.h" 20#include "ui-refs.h"
20#include "ui-repolist.h" 21#include "ui-repolist.h"
21#include "ui-snapshot.h" 22#include "ui-snapshot.h"
22#include "ui-summary.h" 23#include "ui-summary.h"
23#include "ui-tag.h" 24#include "ui-tag.h"
24#include "ui-tree.h" 25#include "ui-tree.h"
25 26
26static void HEAD_fn(struct cgit_context *ctx) 27static void HEAD_fn(struct cgit_context *ctx)
27{ 28{
28 cgit_clone_head(ctx); 29 cgit_clone_head(ctx);
29} 30}
30 31
31static void about_fn(struct cgit_context *ctx) 32static void about_fn(struct cgit_context *ctx)
32{ 33{
33 if (ctx->repo) 34 if (ctx->repo)
34 cgit_print_repo_readme(); 35 cgit_print_repo_readme();
35 else 36 else
36 cgit_print_site_readme(); 37 cgit_print_site_readme();
37} 38}
38 39
39static void blob_fn(struct cgit_context *ctx) 40static void blob_fn(struct cgit_context *ctx)
40{ 41{
41 cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head); 42 cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head);
42} 43}
@@ -64,88 +65,94 @@ static void log_fn(struct cgit_context *ctx)
64 65
65static void ls_cache_fn(struct cgit_context *ctx) 66static void ls_cache_fn(struct cgit_context *ctx)
66{ 67{
67 ctx->page.mimetype = "text/plain"; 68 ctx->page.mimetype = "text/plain";
68 ctx->page.filename = "ls-cache.txt"; 69 ctx->page.filename = "ls-cache.txt";
69 cgit_print_http_headers(ctx); 70 cgit_print_http_headers(ctx);
70 cache_ls(ctx->cfg.cache_root); 71 cache_ls(ctx->cfg.cache_root);
71} 72}
72 73
73static void objects_fn(struct cgit_context *ctx) 74static void objects_fn(struct cgit_context *ctx)
74{ 75{
75 cgit_clone_objects(ctx); 76 cgit_clone_objects(ctx);
76} 77}
77 78
78static void repolist_fn(struct cgit_context *ctx) 79static void repolist_fn(struct cgit_context *ctx)
79{ 80{
80 cgit_print_repolist(); 81 cgit_print_repolist();
81} 82}
82 83
83static void patch_fn(struct cgit_context *ctx) 84static void patch_fn(struct cgit_context *ctx)
84{ 85{
85 cgit_print_patch(ctx->qry.sha1); 86 cgit_print_patch(ctx->qry.sha1);
86} 87}
87 88
89static void plain_fn(struct cgit_context *ctx)
90{
91 cgit_print_plain(ctx);
92}
93
88static void refs_fn(struct cgit_context *ctx) 94static void refs_fn(struct cgit_context *ctx)
89{ 95{
90 cgit_print_refs(); 96 cgit_print_refs();
91} 97}
92 98
93static void snapshot_fn(struct cgit_context *ctx) 99static void snapshot_fn(struct cgit_context *ctx)
94{ 100{
95 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, 101 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1,
96 cgit_repobasename(ctx->repo->url), ctx->qry.path, 102 cgit_repobasename(ctx->repo->url), ctx->qry.path,
97 ctx->repo->snapshots); 103 ctx->repo->snapshots);
98} 104}
99 105
100static void summary_fn(struct cgit_context *ctx) 106static void summary_fn(struct cgit_context *ctx)
101{ 107{
102 cgit_print_summary(); 108 cgit_print_summary();
103} 109}
104 110
105static void tag_fn(struct cgit_context *ctx) 111static void tag_fn(struct cgit_context *ctx)
106{ 112{
107 cgit_print_tag(ctx->qry.sha1); 113 cgit_print_tag(ctx->qry.sha1);
108} 114}
109 115
110static void tree_fn(struct cgit_context *ctx) 116static void tree_fn(struct cgit_context *ctx)
111{ 117{
112 cgit_print_tree(ctx->qry.sha1, ctx->qry.path); 118 cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
113} 119}
114 120
115#define def_cmd(name, want_repo, want_layout) \ 121#define def_cmd(name, want_repo, want_layout) \
116 {#name, name##_fn, want_repo, want_layout} 122 {#name, name##_fn, want_repo, want_layout}
117 123
118struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) 124struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
119{ 125{
120 static struct cgit_cmd cmds[] = { 126 static struct cgit_cmd cmds[] = {
121 def_cmd(HEAD, 1, 0), 127 def_cmd(HEAD, 1, 0),
122 def_cmd(about, 0, 1), 128 def_cmd(about, 0, 1),
123 def_cmd(blob, 1, 0), 129 def_cmd(blob, 1, 0),
124 def_cmd(commit, 1, 1), 130 def_cmd(commit, 1, 1),
125 def_cmd(diff, 1, 1), 131 def_cmd(diff, 1, 1),
126 def_cmd(info, 1, 0), 132 def_cmd(info, 1, 0),
127 def_cmd(log, 1, 1), 133 def_cmd(log, 1, 1),
128 def_cmd(ls_cache, 0, 0), 134 def_cmd(ls_cache, 0, 0),
129 def_cmd(objects, 1, 0), 135 def_cmd(objects, 1, 0),
130 def_cmd(patch, 1, 0), 136 def_cmd(patch, 1, 0),
137 def_cmd(plain, 1, 0),
131 def_cmd(refs, 1, 1), 138 def_cmd(refs, 1, 1),
132 def_cmd(repolist, 0, 0), 139 def_cmd(repolist, 0, 0),
133 def_cmd(snapshot, 1, 0), 140 def_cmd(snapshot, 1, 0),
134 def_cmd(summary, 1, 1), 141 def_cmd(summary, 1, 1),
135 def_cmd(tag, 1, 1), 142 def_cmd(tag, 1, 1),
136 def_cmd(tree, 1, 1), 143 def_cmd(tree, 1, 1),
137 }; 144 };
138 int i; 145 int i;
139 146
140 if (ctx->qry.page == NULL) { 147 if (ctx->qry.page == NULL) {
141 if (ctx->repo) 148 if (ctx->repo)
142 ctx->qry.page = "summary"; 149 ctx->qry.page = "summary";
143 else 150 else
144 ctx->qry.page = "repolist"; 151 ctx->qry.page = "repolist";
145 } 152 }
146 153
147 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) 154 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
148 if (!strcmp(ctx->qry.page, cmds[i].name)) 155 if (!strcmp(ctx->qry.page, cmds[i].name))
149 return &cmds[i]; 156 return &cmds[i];
150 return NULL; 157 return NULL;
151} 158}
diff --git a/html.c b/html.c
index 1237076..83fc7a9 100644
--- a/html.c
+++ b/html.c
@@ -14,48 +14,53 @@
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, int more_headers)
55{ 60{
56 htmlf("Status: %d\n", code); 61 htmlf("Status: %d\n", code);
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)
diff --git a/html.h b/html.h
index 2bde28d..49462a2 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, 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-plain.c b/ui-plain.c
new file mode 100644
index 0000000..28deae5
--- 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, 0);
26 return;
27 }
28
29 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) {
31 html_status(404, 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, 0);
70 return;
71 }
72 commit = lookup_commit_reference(sha1);
73 if (!commit || parse_commit(commit)) {
74 html_status(404, 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, 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 197ee37..4408969 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -397,48 +397,50 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
397 secs * 1.0 / TM_DAY); 397 secs * 1.0 / TM_DAY);
398 return; 398 return;
399 } 399 }
400 if (secs < TM_MONTH * 2) { 400 if (secs < TM_MONTH * 2) {
401 htmlf("<span class='age-weeks'>%.0f weeks</span>", 401 htmlf("<span class='age-weeks'>%.0f weeks</span>",
402 secs * 1.0 / TM_WEEK); 402 secs * 1.0 / TM_WEEK);
403 return; 403 return;
404 } 404 }
405 if (secs < TM_YEAR * 2) { 405 if (secs < TM_YEAR * 2) {
406 htmlf("<span class='age-months'>%.0f months</span>", 406 htmlf("<span class='age-months'>%.0f months</span>",
407 secs * 1.0 / TM_MONTH); 407 secs * 1.0 / TM_MONTH);
408 return; 408 return;
409 } 409 }
410 htmlf("<span class='age-years'>%.0f years</span>", 410 htmlf("<span class='age-years'>%.0f years</span>",
411 secs * 1.0 / TM_YEAR); 411 secs * 1.0 / TM_YEAR);
412} 412}
413 413
414void cgit_print_http_headers(struct cgit_context *ctx) 414void cgit_print_http_headers(struct cgit_context *ctx)
415{ 415{
416 if (ctx->page.mimetype && ctx->page.charset) 416 if (ctx->page.mimetype && ctx->page.charset)
417 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 417 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
418 ctx->page.charset); 418 ctx->page.charset);
419 else if (ctx->page.mimetype) 419 else if (ctx->page.mimetype)
420 htmlf("Content-Type: %s\n", ctx->page.mimetype); 420 htmlf("Content-Type: %s\n", ctx->page.mimetype);
421 if (ctx->page.size)
422 htmlf("Content-Length: %ld\n", ctx->page.size);
421 if (ctx->page.filename) 423 if (ctx->page.filename)
422 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 424 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
423 ctx->page.filename); 425 ctx->page.filename);
424 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 426 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
425 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 427 htmlf("Expires: %s\n", http_date(ctx->page.expires));
426 html("\n"); 428 html("\n");
427} 429}
428 430
429void cgit_print_docstart(struct cgit_context *ctx) 431void cgit_print_docstart(struct cgit_context *ctx)
430{ 432{
431 html(cgit_doctype); 433 html(cgit_doctype);
432 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 434 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
433 html("<head>\n"); 435 html("<head>\n");
434 html("<title>"); 436 html("<title>");
435 html_txt(ctx->page.title); 437 html_txt(ctx->page.title);
436 html("</title>\n"); 438 html("</title>\n");
437 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 439 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
438 if (ctx->cfg.robots && *ctx->cfg.robots) 440 if (ctx->cfg.robots && *ctx->cfg.robots)
439 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 441 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
440 html("<link rel='stylesheet' type='text/css' href='"); 442 html("<link rel='stylesheet' type='text/css' href='");
441 html_attr(ctx->cfg.css); 443 html_attr(ctx->cfg.css);
442 html("'/>\n"); 444 html("'/>\n");
443 if (ctx->cfg.favicon) { 445 if (ctx->cfg.favicon) {
444 html("<link rel='shortcut icon' href='"); 446 html("<link rel='shortcut icon' href='");