srctree

Gregory Mullen parent 3c604b7f fb224d73
update to newest verse api

src/api.zig added: 71, removed: 80, total 0
@@ -48,7 +48,7 @@ const Diff = struct {
};
 
fn diff(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]Diff{});
return try vrs.sendJSON([0]Diff{}, .ok);
}
 
const HeartBeat = struct {
@@ -56,7 +56,7 @@ const HeartBeat = struct {
};
 
fn heartbeat(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON(HeartBeat{ .nice = 69 });
return try vrs.sendJSON(HeartBeat{ .nice = 69 }, .ok);
}
 
const Issue = struct {
@@ -64,7 +64,7 @@ const Issue = struct {
};
 
fn issue(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]Issue{});
return try vrs.sendJSON([0]Issue{}, .ok);
}
 
/// Likely to be renamed
@@ -83,7 +83,7 @@ const Network = struct {
};
 
fn network(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON(Network{ .networks = [0].{} });
return try vrs.sendJSON(Network{ .networks = [0].{} }, .ok);
}
 
const Patch = struct {
@@ -91,7 +91,7 @@ const Patch = struct {
};
 
fn patch(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON(Patch{ .patch = [0].{} });
return try vrs.sendJSON(Patch{ .patch = [0].{} }, .ok);
}
 
const Flex = struct {
@@ -103,7 +103,7 @@ const Flex = struct {
};
 
fn flex(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]Flex{});
return try vrs.sendJSON([0]Flex{}, .ok);
}
 
const User = struct {
@@ -112,5 +112,5 @@ const User = struct {
};
 
fn user(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]User{});
return try vrs.sendJSON([0]User{}, .ok);
}
 
src/api/repo.zig added: 71, removed: 80, total 0
@@ -51,12 +51,12 @@ pub fn repo(ctx: *API.Verse) API.Router.Error!void {
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
error.FileNotFound => {
ctx.response.status = .not_found;
return try ctx.sendJSON([0]Repo{});
ctx.status = .not_found;
return try ctx.sendJSON([0]Repo{}, .ok);
},
else => {
ctx.response.status = .service_unavailable;
return try ctx.sendJSON([0]Repo{});
ctx.status = .service_unavailable;
return try ctx.sendJSON([0]Repo{}, .ok);
},
};
defer gitrepo.raze();
@@ -71,7 +71,7 @@ pub fn repo(ctx: *API.Verse) API.Router.Error!void {
.name = req.name,
.head = head.hex[0..],
.updated = "undefined",
}});
}}, .ok);
}
 
pub const RepoBranches = struct {
@@ -90,12 +90,12 @@ pub fn repoBranches(ctx: *API.Verse) API.Router.Error!void {
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
error.FileNotFound => {
ctx.response.status = .not_found;
return try ctx.sendJSON([0]RepoBranches{});
ctx.status = .not_found;
return try ctx.sendJSON([0]RepoBranches{}, .ok);
},
else => {
ctx.response.status = .service_unavailable;
return try ctx.sendJSON([0]RepoBranches{});
ctx.status = .service_unavailable;
return try ctx.sendJSON([0]RepoBranches{}, .ok);
},
};
defer gitrepo.raze();
@@ -112,7 +112,7 @@ pub fn repoBranches(ctx: *API.Verse) API.Router.Error!void {
.name = req.name,
.updated = "undefined",
.branches = branches[0..],
}});
}}, .ok);
}
 
pub const RepoTags = struct {
@@ -127,12 +127,12 @@ pub fn repoTags(ctx: *API.Verse) API.Router.Error!void {
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
error.FileNotFound => {
ctx.response.status = .not_found;
return try ctx.sendJSON([0]RepoTags{});
ctx.status = .not_found;
return try ctx.sendJSON([0]RepoTags{}, .ok);
},
else => {
ctx.response.status = .service_unavailable;
return try ctx.sendJSON([0]RepoTags{});
ctx.status = .service_unavailable;
return try ctx.sendJSON([0]RepoTags{}, .ok);
},
};
defer gitrepo.raze();
@@ -141,7 +141,7 @@ pub fn repoTags(ctx: *API.Verse) API.Router.Error!void {
.name = req.name,
.updated = "undefined",
.tags = &.{},
}});
}}, .ok);
 
const tstack = try ctx.alloc.alloc([]const u8, repotags.len);
 
@@ -152,5 +152,5 @@ pub fn repoTags(ctx: *API.Verse) API.Router.Error!void {
.name = req.name,
.updated = "undefined",
.tags = tstack,
}});
}}, .ok);
}
 
src/endpoints/gist.zig added: 71, removed: 80, total 0
@@ -87,7 +87,7 @@ fn post(ctx: *Verse) Error!void {
 
const hash_str: [64]u8 = Gist.new(username, files) catch return error.Unknown;
 
return ctx.response.redirect("/gist/" ++ hash_str, true) catch unreachable;
return ctx.redirect("/gist/" ++ hash_str, true) catch unreachable;
}
 
fn new(ctx: *Verse) Error!void {
 
src/endpoints/repos.zig added: 71, removed: 80, total 0
@@ -7,7 +7,6 @@ const startsWith = std.mem.startsWith;
const splitScalar = std.mem.splitScalar;
 
const Verse = @import("verse");
const Response = Verse.Response;
const Request = Verse.Request;
const Template = Verse.Template;
const HTML = Template.HTML;
@@ -325,7 +324,7 @@ fn dupeDir(a: Allocator, name: []const u8) ![]u8 {
 
const NewRepoPage = Template.PageData("repo-new.html");
fn newRepo(ctx: *Verse) Error!void {
ctx.response.status = .ok;
ctx.status = .ok;
 
return error.NotImplemented;
}
@@ -502,7 +501,7 @@ fn blame(ctx: *Verse) Error!void {
.blame_lines = wrapped_blames,
});
 
ctx.response.status = .ok;
ctx.status = .ok;
try ctx.sendPage(&page);
}
 
@@ -601,7 +600,7 @@ fn blob(ctx: *Verse, repo: *Git.Repo, pfiles: Git.Tree) Error!void {
_ = ctx.uri.next();
const uri_filename = Bleach.Html.sanitizeAlloc(ctx.alloc, ctx.uri.rest()) catch return error.Unknown;
 
ctx.response.status = .ok;
ctx.status = .ok;
 
var btns = navButtons(ctx) catch return error.Unknown;
 
 
src/endpoints/repos/commits.zig added: 71, removed: 80, total 0
@@ -8,7 +8,6 @@ const eql = std.mem.eql;
const Verse = @import("verse");
const DOM = Verse.DOM;
const HTML = Verse.HTML;
const Response = Verse.Response;
const Route = Verse.Router;
const Template = Verse.Template;
const RequestData = Verse.RequestData;
@@ -178,7 +177,7 @@ fn commitHtml(ctx: *Verse, sha: []const u8, repo_name: []const u8, repo: Git.Rep
.patch = Diffs.patchStruct(ctx.alloc, &patch, !inline_html) catch return error.Unknown,
});
 
ctx.response.status = .ok;
ctx.status = .ok;
return ctx.sendPage(&page) catch unreachable;
}
 
@@ -193,11 +192,10 @@ pub fn commitPatch(ctx: *Verse, sha: []const u8, repo: Git.Repo) Error!void {
//if (std.mem.indexOf(u8, diff, "diff")) |i| {
// diff = diff[i..];
//}
ctx.response.status = .ok;
ctx.response.headersAdd("Content-Type", "text/x-patch") catch unreachable; // Firefox is trash
ctx.response.start() catch return Error.Unknown;
ctx.response.send(diff) catch return Error.Unknown;
ctx.response.finish() catch return Error.Unknown;
ctx.status = .ok;
ctx.headersAdd("Content-Type", "text/x-patch") catch unreachable; // Firefox is trash
ctx.quickStart() catch return Error.Unknown;
ctx.sendRawSlice(diff) catch return Error.Unknown;
}
}
 
 
src/endpoints/repos/diffs.zig added: 71, removed: 80, total 0
@@ -159,21 +159,17 @@ const DiffCreateReq = struct {
//},
};
 
fn createDiff(ctx: *Verse) Error!void {
const rd = Repos.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
if (ctx.reqdata.post) |post| {
fn createDiff(vrs: *Verse) Error!void {
const rd = Repos.RouteData.make(&vrs.uri) orelse return error.Unrouteable;
if (vrs.reqdata.post) |post| {
const udata = post.validate(DiffCreateReq) catch return error.BadData;
if (udata.title.len == 0) return error.BadData;
 
var remote_addr: []const u8 = "unknown";
for (ctx.request.headers.items) |head| {
if (eql(u8, head.name, "REMOTE_ADDR")) {
remote_addr = head.val;
}
}
remote_addr = vrs.request.remote_addr;
 
if (inNetwork(udata.patch_uri)) {
const data = Patch.loadRemote(ctx.alloc, udata.patch_uri) catch unreachable;
const data = Patch.loadRemote(vrs.alloc, udata.patch_uri) catch unreachable;
 
std.debug.print(
"src {s}\ntitle {s}\ndesc {s}\naction {s}\n",
@@ -183,15 +179,15 @@ fn createDiff(ctx: *Verse) Error!void {
rd.name,
udata.title,
udata.desc,
if (ctx.auth.valid())
(ctx.auth.current_user orelse unreachable).username
if (vrs.auth.valid())
(vrs.auth.current_user orelse unreachable).username
else
try allocPrint(ctx.alloc, "REMOTE_ADDR {s}", .{remote_addr}),
try allocPrint(vrs.alloc, "REMOTE_ADDR {s}", .{remote_addr}),
) catch unreachable;
delta.commit() catch unreachable;
std.debug.print("commit id {x}\n", .{delta.index});
 
const filename = allocPrint(ctx.alloc, "data/patch/{s}.{x}.patch", .{
const filename = allocPrint(vrs.alloc, "data/patch/{s}.{x}.patch", .{
rd.name,
delta.index,
}) catch unreachable;
@@ -200,11 +196,11 @@ fn createDiff(ctx: *Verse) Error!void {
file.writer().writeAll(data.blob) catch unreachable;
var buf: [2048]u8 = undefined;
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/diffs/{x}", .{ rd.name, delta.index });
return ctx.response.redirect(loc, true) catch unreachable;
return vrs.redirect(loc, true) catch unreachable;
}
}
 
return try new(ctx);
return try new(vrs);
}
 
fn newComment(ctx: *Verse) Error!void {
@@ -217,7 +213,7 @@ fn newComment(ctx: *Verse) Error!void {
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/diffs/{x}", .{ rd.name, delta_index });
 
const msg = try valid.require("comment");
if (msg.value.len < 2) return ctx.response.redirect(loc, true) catch unreachable;
if (msg.value.len < 2) return ctx.redirect(loc, true) catch unreachable;
 
var delta = Delta.open(ctx.alloc, rd.name, delta_index) catch unreachable orelse return error.Unrouteable;
const username = if (ctx.auth.valid())
@@ -228,7 +224,7 @@ fn newComment(ctx: *Verse) Error!void {
thread.newComment(ctx.alloc, .{ .author = username, .message = msg.value }) catch unreachable;
// TODO record current revision at comment time
delta.commit() catch unreachable;
return ctx.response.redirect(loc, true) catch unreachable;
return ctx.redirect(loc, true) catch unreachable;
}
return error.Unknown;
}
 
src/endpoints/repos/issues.zig added: 71, removed: 80, total 0
@@ -86,11 +86,11 @@ fn newPost(ctx: *Verse) Error!void {
delta.commit() catch unreachable;
 
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/issues/{x}", .{ rd.name, delta.index });
return ctx.response.redirect(loc, true) catch unreachable;
return ctx.redirect(loc, true) catch unreachable;
}
 
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/issue/new", .{rd.name});
return ctx.response.redirect(loc, true) catch unreachable;
return ctx.redirect(loc, true) catch unreachable;
}
 
fn newComment(ctx: *Verse) Error!void {
@@ -116,7 +116,7 @@ fn newComment(ctx: *Verse) Error!void {
delta.commit() catch unreachable;
var buf: [2048]u8 = undefined;
const loc = try std.fmt.bufPrint(&buf, "/repo/{s}/issues/{x}", .{ rd.name, issue_index });
ctx.response.redirect(loc, true) catch unreachable;
ctx.redirect(loc, true) catch unreachable;
return;
}
return error.Unknown;
 
src/endpoints/settings.zig added: 71, removed: 80, total 0
@@ -57,5 +57,5 @@ fn post(ctx: *Verse) Router.Error!void {
std.debug.print("block data:\nname '{s}'\ntext '''{s}'''\n", .{ name, text });
}
 
return ctx.response.redirect("/settings", true) catch unreachable;
return ctx.redirect("/settings", true) catch unreachable;
}
 
src/gitweb.zig added: 71, removed: 80, total 0
@@ -3,7 +3,6 @@ const Allocator = std.mem.Allocator;
const POLL = std.posix.POLL;
 
const Verse = @import("verse");
const Response = Verse.Response;
const Request = Verse.Request;
const HTML = Verse.HTML;
const elm = HTML.element;
@@ -70,7 +69,7 @@ fn gitUploadPack(ctx: *Verse) Error!void {
child.env_map = &map;
child.expand_arg0 = .no_expand;
 
ctx.response.status = .ok;
ctx.status = .ok;
 
child.spawn() catch unreachable;
 
@@ -96,10 +95,10 @@ fn gitUploadPack(ctx: *Verse) Error!void {
const amt = std.posix.read(poll_fd[0].fd, buf) catch unreachable;
if (amt == 0) break;
if (headers_required) {
_ = ctx.response.write("HTTP/1.1 200 OK\r\n") catch unreachable;
_ = ctx.sendRawSlice("HTTP/1.1 200 OK\r\n") catch unreachable;
headers_required = false;
}
ctx.response.writeAll(buf[0..amt]) catch unreachable;
ctx.sendRawSlice(buf[0..amt]) catch unreachable;
} else if (poll_fd[0].revents & err_mask != 0) {
break;
}
@@ -135,10 +134,9 @@ fn __objects(ctx: *Verse) Error!void {
 
//var data = repo.findBlob(ctx.alloc, &sha) catch unreachable;
 
ctx.response.status = .ok;
ctx.response.start() catch return Error.Unknown;
ctx.response.write(data) catch return Error.Unknown;
ctx.response.finish() catch return Error.Unknown;
ctx.status = .ok;
ctx.quickStart() catch return Error.Unknown;
ctx.sendRawSlice(data) catch return Error.Unknown;
}
 
fn __info(ctx: *Verse) Error!void {
@@ -171,8 +169,8 @@ fn __info(ctx: *Verse) Error!void {
 
const data = try adata.toOwnedSlice();
 
ctx.response.status = .ok;
ctx.response.start() catch return Error.Unknown;
ctx.response.write(data) catch return Error.Unknown;
ctx.response.finish() catch return Error.Unknown;
ctx.status = .ok;
ctx.start() catch return Error.Unknown;
ctx.write(data) catch return Error.Unknown;
ctx.finish() catch return Error.Unknown;
}
 
src/srctree.zig added: 71, removed: 80, total 0
@@ -43,7 +43,7 @@ const E404Page = Template.PageData("4XX.html");
fn notFound(ctx: *Verse) Router.Error!void {
// TODO fix this
@import("std").debug.print("404 for route\n", .{});
ctx.response.status = .not_found;
ctx.status = .not_found;
var page = E404Page.init(.{});
ctx.sendPage(&page) catch unreachable;
}
@@ -62,7 +62,7 @@ pub fn router(ctx: *Verse) Router.Error!BuildFn {
pub fn builder(ctx: *Verse, call: BuildFn) void {
return call(ctx) catch |err| switch (err) {
error.InvalidURI => builder(ctx, notFound), // TODO catch inline
error.NetworkCrash => std.debug.print("client disconnect", .{}),
error.BrokenPipe => std.debug.print("client disconnect", .{}),
error.Unrouteable => {
std.debug.print("Unrouteable", .{});
if (@errorReturnTrace()) |trace| {