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
Dieser Commit ist enthalten in:
Commit
d532c4d161
1
Makefile
1
Makefile
@ -62,6 +62,7 @@ OBJECTS += ui-commit.o
|
|||||||
OBJECTS += ui-diff.o
|
OBJECTS += ui-diff.o
|
||||||
OBJECTS += ui-log.o
|
OBJECTS += ui-log.o
|
||||||
OBJECTS += ui-patch.o
|
OBJECTS += ui-patch.o
|
||||||
|
OBJECTS += ui-plain.o
|
||||||
OBJECTS += ui-refs.o
|
OBJECTS += ui-refs.o
|
||||||
OBJECTS += ui-repolist.o
|
OBJECTS += ui-repolist.o
|
||||||
OBJECTS += ui-shared.o
|
OBJECTS += ui-shared.o
|
||||||
|
1
cgit.c
1
cgit.c
@ -187,6 +187,7 @@ static void prepare_context(struct cgit_context *ctx)
|
|||||||
ctx->page.mimetype = "text/html";
|
ctx->page.mimetype = "text/html";
|
||||||
ctx->page.charset = PAGE_ENCODING;
|
ctx->page.charset = PAGE_ENCODING;
|
||||||
ctx->page.filename = NULL;
|
ctx->page.filename = NULL;
|
||||||
|
ctx->page.size = 0;
|
||||||
ctx->page.modified = time(NULL);
|
ctx->page.modified = time(NULL);
|
||||||
ctx->page.expires = ctx->page.modified;
|
ctx->page.expires = ctx->page.modified;
|
||||||
}
|
}
|
||||||
|
1
cgit.h
1
cgit.h
@ -166,6 +166,7 @@ struct cgit_config {
|
|||||||
struct cgit_page {
|
struct cgit_page {
|
||||||
time_t modified;
|
time_t modified;
|
||||||
time_t expires;
|
time_t expires;
|
||||||
|
size_t size;
|
||||||
char *mimetype;
|
char *mimetype;
|
||||||
char *charset;
|
char *charset;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
7
cmd.c
7
cmd.c
@ -17,6 +17,7 @@
|
|||||||
#include "ui-diff.h"
|
#include "ui-diff.h"
|
||||||
#include "ui-log.h"
|
#include "ui-log.h"
|
||||||
#include "ui-patch.h"
|
#include "ui-patch.h"
|
||||||
|
#include "ui-plain.h"
|
||||||
#include "ui-refs.h"
|
#include "ui-refs.h"
|
||||||
#include "ui-repolist.h"
|
#include "ui-repolist.h"
|
||||||
#include "ui-snapshot.h"
|
#include "ui-snapshot.h"
|
||||||
@ -91,6 +92,11 @@ static void patch_fn(struct cgit_context *ctx)
|
|||||||
cgit_print_patch(ctx->qry.sha1);
|
cgit_print_patch(ctx->qry.sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void plain_fn(struct cgit_context *ctx)
|
||||||
|
{
|
||||||
|
cgit_print_plain(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
static void refs_fn(struct cgit_context *ctx)
|
static void refs_fn(struct cgit_context *ctx)
|
||||||
{
|
{
|
||||||
cgit_print_refs();
|
cgit_print_refs();
|
||||||
@ -135,6 +141,7 @@ struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
|
|||||||
def_cmd(ls_cache, 0, 0),
|
def_cmd(ls_cache, 0, 0),
|
||||||
def_cmd(objects, 1, 0),
|
def_cmd(objects, 1, 0),
|
||||||
def_cmd(patch, 1, 0),
|
def_cmd(patch, 1, 0),
|
||||||
|
def_cmd(plain, 1, 0),
|
||||||
def_cmd(refs, 1, 1),
|
def_cmd(refs, 1, 1),
|
||||||
def_cmd(repolist, 0, 0),
|
def_cmd(repolist, 0, 0),
|
||||||
def_cmd(snapshot, 1, 0),
|
def_cmd(snapshot, 1, 0),
|
||||||
|
9
html.c
9
html.c
@ -35,6 +35,11 @@ char *fmt(const char *format, ...)
|
|||||||
return buf[bufidx];
|
return buf[bufidx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void html_raw(const char *data, size_t size)
|
||||||
|
{
|
||||||
|
write(htmlfd, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
void html(const char *txt)
|
void html(const char *txt)
|
||||||
{
|
{
|
||||||
write(htmlfd, txt, strlen(txt));
|
write(htmlfd, txt, strlen(txt));
|
||||||
@ -51,9 +56,9 @@ void htmlf(const char *format, ...)
|
|||||||
html(buf);
|
html(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void html_status(int code, int more_headers)
|
void html_status(int code, const char *msg, int more_headers)
|
||||||
{
|
{
|
||||||
htmlf("Status: %d\n", code);
|
htmlf("Status: %d %s\n", code, msg);
|
||||||
if (!more_headers)
|
if (!more_headers)
|
||||||
html("\n");
|
html("\n");
|
||||||
}
|
}
|
||||||
|
3
html.h
3
html.h
@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
extern int htmlfd;
|
extern int htmlfd;
|
||||||
|
|
||||||
|
extern void html_raw(const char *txt, size_t size);
|
||||||
extern void html(const char *txt);
|
extern void html(const char *txt);
|
||||||
extern void htmlf(const char *format,...);
|
extern void htmlf(const char *format,...);
|
||||||
extern void html_status(int code, int more_headers);
|
extern void html_status(int code, const char *msg, int more_headers);
|
||||||
extern void html_txt(char *txt);
|
extern void html_txt(char *txt);
|
||||||
extern void html_ntxt(int len, char *txt);
|
extern void html_ntxt(int len, char *txt);
|
||||||
extern void html_attr(char *txt);
|
extern void html_attr(char *txt);
|
||||||
|
10
ui-clone.c
10
ui-clone.c
@ -48,20 +48,18 @@ static void print_pack_info(struct cgit_context *ctx)
|
|||||||
static void send_file(struct cgit_context *ctx, char *path)
|
static void send_file(struct cgit_context *ctx, char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int err;
|
|
||||||
|
|
||||||
if (stat(path, &st)) {
|
if (stat(path, &st)) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case ENOENT:
|
case ENOENT:
|
||||||
err = 404;
|
html_status(404, "Not found", 0);
|
||||||
break;
|
break;
|
||||||
case EACCES:
|
case EACCES:
|
||||||
err = 403;
|
html_status(403, "Forbidden", 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = 400;
|
html_status(400, "Bad request", 0);
|
||||||
}
|
}
|
||||||
html_status(err, 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx->page.mimetype = "application/octet-stream";
|
ctx->page.mimetype = "application/octet-stream";
|
||||||
@ -86,7 +84,7 @@ void cgit_clone_info(struct cgit_context *ctx)
|
|||||||
void cgit_clone_objects(struct cgit_context *ctx)
|
void cgit_clone_objects(struct cgit_context *ctx)
|
||||||
{
|
{
|
||||||
if (!ctx->qry.path) {
|
if (!ctx->qry.path) {
|
||||||
html_status(400, 0);
|
html_status(400, "Bad request", 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
82
ui-plain.c
Normale Datei
82
ui-plain.c
Normale Datei
@ -0,0 +1,82 @@
|
|||||||
|
/* ui-plain.c: functions for output of plain blobs by path
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 Lars Hjemli
|
||||||
|
*
|
||||||
|
* Licensed under GNU General Public License v2
|
||||||
|
* (see COPYING for full license text)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cgit.h"
|
||||||
|
#include "html.h"
|
||||||
|
#include "ui-shared.h"
|
||||||
|
|
||||||
|
char *curr_rev;
|
||||||
|
char *match_path;
|
||||||
|
int match;
|
||||||
|
|
||||||
|
static void print_object(const unsigned char *sha1, const char *path)
|
||||||
|
{
|
||||||
|
enum object_type type;
|
||||||
|
char *buf;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
type = sha1_object_info(sha1, &size);
|
||||||
|
if (type == OBJ_BAD) {
|
||||||
|
html_status(404, "Not found", 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = read_sha1_file(sha1, &type, &size);
|
||||||
|
if (!buf) {
|
||||||
|
html_status(404, "Not found", 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ctx.page.mimetype = "text/plain";
|
||||||
|
ctx.page.filename = fmt("%s", path);
|
||||||
|
ctx.page.size = size;
|
||||||
|
cgit_print_http_headers(&ctx);
|
||||||
|
html_raw(buf, size);
|
||||||
|
match = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
|
||||||
|
const char *pathname, unsigned mode, int stage,
|
||||||
|
void *cbdata)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "[cgit] walk_tree.pathname=%s", pathname);
|
||||||
|
|
||||||
|
if (!pathname || strcmp(match_path, pathname))
|
||||||
|
return READ_TREE_RECURSIVE;
|
||||||
|
|
||||||
|
if (S_ISREG(mode))
|
||||||
|
print_object(sha1, pathname);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cgit_print_plain(struct cgit_context *ctx)
|
||||||
|
{
|
||||||
|
const char *rev = ctx->qry.sha1;
|
||||||
|
unsigned char sha1[20];
|
||||||
|
struct commit *commit;
|
||||||
|
const char *paths[] = {ctx->qry.path, NULL};
|
||||||
|
|
||||||
|
if (!rev)
|
||||||
|
rev = ctx->qry.head;
|
||||||
|
|
||||||
|
curr_rev = xstrdup(rev);
|
||||||
|
if (get_sha1(rev, sha1)) {
|
||||||
|
html_status(404, "Not found", 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commit = lookup_commit_reference(sha1);
|
||||||
|
if (!commit || parse_commit(commit)) {
|
||||||
|
html_status(404, "Not found", 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match_path = ctx->qry.path;
|
||||||
|
fprintf(stderr, "[cgit] match_path=%s", match_path);
|
||||||
|
read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL);
|
||||||
|
if (!match)
|
||||||
|
html_status(404, "Not found", 0);
|
||||||
|
}
|
6
ui-plain.h
Normale Datei
6
ui-plain.h
Normale Datei
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef UI_PLAIN_H
|
||||||
|
#define UI_PLAIN_H
|
||||||
|
|
||||||
|
extern void cgit_print_plain(struct cgit_context *ctx);
|
||||||
|
|
||||||
|
#endif /* UI_PLAIN_H */
|
@ -258,6 +258,12 @@ void cgit_tree_link(char *name, char *title, char *class, char *head,
|
|||||||
reporevlink("tree", name, title, class, head, rev, path);
|
reporevlink("tree", name, title, class, head, rev, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cgit_plain_link(char *name, char *title, char *class, char *head,
|
||||||
|
char *rev, char *path)
|
||||||
|
{
|
||||||
|
reporevlink("plain", name, title, class, head, rev, path);
|
||||||
|
}
|
||||||
|
|
||||||
void cgit_log_link(char *name, char *title, char *class, char *head,
|
void cgit_log_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev, char *path, int ofs, char *grep, char *pattern)
|
char *rev, char *path, int ofs, char *grep, char *pattern)
|
||||||
{
|
{
|
||||||
@ -433,6 +439,8 @@ void cgit_print_http_headers(struct cgit_context *ctx)
|
|||||||
ctx->page.charset);
|
ctx->page.charset);
|
||||||
else if (ctx->page.mimetype)
|
else if (ctx->page.mimetype)
|
||||||
htmlf("Content-Type: %s\n", ctx->page.mimetype);
|
htmlf("Content-Type: %s\n", ctx->page.mimetype);
|
||||||
|
if (ctx->page.size)
|
||||||
|
htmlf("Content-Length: %ld\n", ctx->page.size);
|
||||||
if (ctx->page.filename)
|
if (ctx->page.filename)
|
||||||
htmlf("Content-Disposition: inline; filename=\"%s\"\n",
|
htmlf("Content-Disposition: inline; filename=\"%s\"\n",
|
||||||
ctx->page.filename);
|
ctx->page.filename);
|
||||||
|
@ -12,6 +12,8 @@ extern void cgit_index_link(char *name, char *title, char *class,
|
|||||||
char *pattern, int ofs);
|
char *pattern, int ofs);
|
||||||
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
|
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev, char *path);
|
char *rev, char *path);
|
||||||
|
extern void cgit_plain_link(char *name, char *title, char *class, char *head,
|
||||||
|
char *rev, char *path);
|
||||||
extern void cgit_log_link(char *name, char *title, char *class, char *head,
|
extern void cgit_log_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev, char *path, int ofs, char *grep,
|
char *rev, char *path, int ofs, char *grep,
|
||||||
char *pattern);
|
char *pattern);
|
||||||
|
@ -35,10 +35,10 @@ static void print_object(const unsigned char *sha1, char *path)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
html(" blob: <a href='");
|
html(" (");
|
||||||
html_attr(cgit_pageurl(ctx.qry.repo, "blob",
|
cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
|
||||||
fmt("id=%s&path=%s", sha1_to_hex(sha1), path)));
|
curr_rev, path);
|
||||||
htmlf("'>%s</a>",sha1_to_hex(sha1));
|
htmlf(")<br/>blob: %s", sha1_to_hex(sha1));
|
||||||
|
|
||||||
html("<table summary='blob content' class='blob'>\n");
|
html("<table summary='blob content' class='blob'>\n");
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren