author | Lars Hjemli <hjemli@gmail.com> | 2008-08-06 08:53:50 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-08-06 09:21:30 (UTC) |
commit | e5da4bca54574522b28f88cab0dc8ebad9e35a73 (patch) (unidiff) | |
tree | 08e02b9e0962a12040faab27e7841a74a800ddf2 /cgit.c | |
parent | 02a545e63454530c1639014d3239c14ced2022c6 (diff) | |
download | cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.zip cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.tar.gz cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.tar.bz2 |
Implement plain view
This implements a way to access plain blobs by path (similar to the
tree view) instead of by sha1.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -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 | ||
158 | static void prepare_context(struct cgit_context *ctx) | 158 | static 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 | ||
194 | struct refmatch { | 195 | struct 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 | ||
200 | int find_current_ref(const char *refname, const unsigned char *sha1, | 201 | int 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 | ||
213 | char *find_default_branch(struct cgit_repo *repo) | 214 | char *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 | ||
231 | static int prepare_repo_cmd(struct cgit_context *ctx) | 232 | static 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); |