srctree

Gregory Mullen parent 99f544a8 fb38da37
verse update

src/api.zig added: 72, removed: 76, total 0
@@ -34,37 +34,37 @@ const APIRouteData = struct {
}
};
 
pub fn router(ctx: *Verse) Router.Error!Router.Callable {
const uri_api = ctx.uri.next() orelse return heartbeat;
pub fn router(vrs: *Verse) Router.Error!Router.BuildFn {
const uri_api = vrs.uri.next() orelse return heartbeat;
if (!std.mem.eql(u8, uri_api, "api")) return heartbeat;
const rd = try APIRouteData.init(ctx.alloc);
ctx.route_ctx = rd;
const rd = try APIRouteData.init(vrs.alloc);
vrs.route_ctx = rd;
 
return Router.router(ctx, &endpoints);
return Router.router(vrs, &endpoints);
}
 
const Diff = struct {
sha: []const u8,
};
 
fn diff(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON([0]Diff{});
fn diff(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]Diff{});
}
 
const HeartBeat = struct {
nice: usize = 0,
};
 
fn heartbeat(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON(HeartBeat{ .nice = 69 });
fn heartbeat(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON(HeartBeat{ .nice = 69 });
}
 
const Issue = struct {
index: usize,
};
 
fn issue(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON([0]Issue{});
fn issue(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]Issue{});
}
 
/// Likely to be renamed
@@ -82,16 +82,16 @@ const Network = struct {
networks: []RemotePeer,
};
 
fn network(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON(Network{ .networks = [0].{} });
fn network(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON(Network{ .networks = [0].{} });
}
 
const Patch = struct {
patch: []const u8,
};
 
fn patch(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON(Patch{ .patch = [0].{} });
fn patch(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON(Patch{ .patch = [0].{} });
}
 
const Flex = struct {
@@ -102,8 +102,8 @@ const Flex = struct {
};
};
 
fn flex(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON([0]Flex{});
fn flex(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]Flex{});
}
 
const User = struct {
@@ -111,6 +111,6 @@ const User = struct {
email: []const u8,
};
 
fn user(ctx: *Verse) Router.Error!void {
return try ctx.sendJSON([0]User{});
fn user(vrs: *Verse) Router.Error!void {
return try vrs.sendJSON([0]User{});
}
 
src/api/repo.zig added: 72, removed: 76, total 0
@@ -14,7 +14,7 @@ const endpoints = [_]Router.Match{
ROUTE("tags", repoTags),
};
 
pub fn router(ctx: *API.Verse) Router.Error!Router.Callable {
pub fn router(ctx: *API.Verse) Router.Error!Router.BuildFn {
const uri_api = ctx.uri.next() orelse return repo;
if (!std.mem.eql(u8, uri_api, "repo")) return repo;
 
 
src/endpoints/gist.zig added: 72, removed: 76, total 0
@@ -9,15 +9,15 @@ const Allocator = std.mem.Allocator;
 
const Gist = @import("../types.zig").Gist;
 
const Routes = Verse.Router;
const Error = Routes.Error;
const POST = Routes.POST;
const GET = Routes.GET;
const Router = Verse.Router;
const Error = Router.Error;
const POST = Router.POST;
const GET = Router.GET;
 
const GistPage = Template.PageData("gist.html");
const GistNewPage = Template.PageData("gist_new.html");
 
const endpoints = [_]Routes.Match{
const endpoints = [_]Router.Match{
GET("", new),
GET("gist", view),
GET("new", new),
@@ -25,7 +25,7 @@ const endpoints = [_]Routes.Match{
POST("post", post),
};
 
pub fn router(ctx: *Verse) Error!Routes.Callable {
pub fn router(ctx: *Verse) Error!Router.BuildFn {
if (!std.mem.eql(u8, ctx.uri.next() orelse "", "gist")) return error.Unrouteable;
 
if (ctx.uri.peek()) |peek| {
@@ -41,7 +41,7 @@ pub fn router(ctx: *Verse) Error!Routes.Callable {
}
} else return new;
 
return Routes.router(ctx, &endpoints);
return Router.router(ctx, &endpoints);
}
 
const GistPost = struct {
 
src/endpoints/repos.zig added: 72, removed: 76, total 0
@@ -122,7 +122,7 @@ pub fn navButtons(ctx: *Verse) ![2]Template.Structs.NavButtons {
return btns;
}
 
pub fn router(ctx: *Verse) Error!Route.Callable {
pub fn router(ctx: *Verse) Error!Route.BuildFn {
const rd = RouteData.make(&ctx.uri) orelse return list;
 
if (rd.exists()) {
 
src/endpoints/repos/commits.zig added: 72, removed: 76, total 0
@@ -45,7 +45,7 @@ const AddComment = struct {
text: []const u8,
};
 
pub fn router(ctx: *Verse) Error!Route.Callable {
pub fn router(ctx: *Verse) Error!Route.BuildFn {
const rd = RouteData.make(&ctx.uri) orelse return commitsView;
if (rd.verb != null and std.mem.eql(u8, "commit", rd.verb.?))
return viewCommit;
 
src/endpoints/repos/diffs.zig added: 72, removed: 76, total 0
@@ -52,7 +52,7 @@ fn isHex(input: []const u8) ?usize {
return std.fmt.parseInt(usize, input, 16) catch null;
}
 
pub fn router(ctx: *Verse) Error!Route.Callable {
pub fn router(ctx: *Verse) Error!Route.BuildFn {
if (!eql(u8, "diffs", ctx.uri.next() orelse return error.Unrouteable))
return error.Unrouteable;
const verb = ctx.uri.peek() orelse return Route.router(ctx, &routes);
 
src/endpoints/repos/issues.zig added: 72, removed: 76, total 0
@@ -37,7 +37,7 @@ fn isHex(input: []const u8) ?usize {
return std.fmt.parseInt(usize, input, 16) catch null;
}
 
pub fn router(ctx: *Verse) Error!Route.Callable {
pub fn router(ctx: *Verse) Error!Route.BuildFn {
std.debug.assert(std.mem.eql(u8, "issues", ctx.uri.next().?));
const verb = ctx.uri.peek() orelse return Route.router(ctx, &routes);
 
 
src/endpoints/search.zig added: 72, removed: 76, total 0
@@ -19,7 +19,7 @@ pub const routes = [_]Routes.Match{
ROUTE("inbox", inbox),
};
 
pub fn router(ctx: *Verse) Error!Routes.Callable {
pub fn router(ctx: *Verse) Error!Routes.BuildFn {
return Routes.router(ctx, &routes);
}
 
 
src/gitweb.zig added: 72, removed: 76, total 0
@@ -22,16 +22,16 @@ const Humanize = @import("humanize.zig");
const Bleach = @import("bleach.zig");
 
pub const endpoints = [_]Route.Match{
.{ .name = "objects", .match = .{ .call = gitUploadPack } },
.{ .name = "objects", .match = .{ .build = gitUploadPack } },
.{ .name = "info", .match = .{ .simple = &[_]Route.Match{
.{ .name = "", .match = .{ .call = gitUploadPack } },
.{ .name = "refs", .match = .{ .call = gitUploadPack } },
.{ .name = "", .match = .{ .build = gitUploadPack } },
.{ .name = "refs", .match = .{ .build = gitUploadPack } },
} } },
 
.{ .name = "git-upload-pack", .methods = .{ .POST = true }, .match = .{ .call = gitUploadPack } },
.{ .name = "git-upload-pack", .methods = .{ .POST = true }, .match = .{ .build = gitUploadPack } },
};
 
pub fn router(ctx: *Verse) Error!Route.Callable {
pub fn router(ctx: *Verse) Error!Route.BuildFn {
std.debug.print("gitweb router {s}\n{any}, {any} \n", .{ ctx.ctx.uri.peek().?, ctx.ctx.uri, ctx.request.method });
return Route.router(ctx, &endpoints);
}
 
src/main.zig added: 72, removed: 76, total 0
@@ -1,15 +1,14 @@
const std = @import("std");
const Verse = @import("verse");
 
const Allocator = std.mem.Allocator;
const Thread = std.Thread;
const Server = std.http.Server;
const Verse = @import("verse");
const print = std.debug.print;
const Server = Verse.Server;
 
const Database = @import("database.zig");
//const HTML = Verse.HTML;
const Route = Verse.Router;
const Repos = @import("repos.zig");
const zWSGI = Verse.zWSGI;
 
// TODO FIXME revert to internal config instead of Verse version
// but I don't want to lose track of origin, and that's where the
@@ -25,11 +24,11 @@ test "main" {
std.testing.refAllDecls(@import("git.zig"));
}
 
// TODO make thread safe
const print = std.debug.print;
pub const std_options = .{
.log_level = .info,
};
 
var arg0: []const u8 = undefined;
 
fn usage(long: bool) noreturn {
print(
\\{s} [type]
@@ -67,14 +66,12 @@ const Options = struct {
source_path: []const u8,
};
 
// TODO delete me
 
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{ .stack_trace_frames = 12 }){};
defer _ = gpa.deinit();
const a = gpa.allocator();
 
var runmode: zWSGI.RunMode = .unix;
var runmode: Verse.Server.RunMode = .unix;
 
var args = std.process.args();
arg0 = args.next() orelse "srctree";
@@ -128,15 +125,14 @@ pub fn main() !void {
const thread = try Thread.spawn(.{}, Repos.updateThread, .{&agent_config});
defer thread.join();
 
var zwsgi: zWSGI = .{
.alloc = a,
.config = config,
.routefn = Srctree.router,
.buildfn = Srctree.build,
.runmode = runmode,
};
var server = try Verse.Server.init(
a,
runmode,
.{ .routefn = Srctree.router, .buildfn = Srctree.build },
.{ .file = "./srctree.sock" },
);
 
zwsgi.serve() catch {
server.serve() catch {
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
}
 
src/srctree.zig added: 72, removed: 76, total 0
@@ -1,14 +1,14 @@
const Verse = @import("verse");
const Routes = Verse.Router;
const Router = Verse.Router;
const Template = Verse.Template;
const Api = @import("api.zig");
//const Types = @import("types.zig");
 
const ROUTE = Routes.ROUTE;
const GET = Routes.GET;
const STATIC = Routes.STATIC;
const Match = Routes.Match;
const Callable = Routes.Callable;
const ROUTE = Router.ROUTE;
const GET = Router.GET;
const STATIC = Router.STATIC;
const Match = Router.Match;
const BuildFn = Router.BuildFn;
 
const commitFlex = @import("endpoints/commit-flex.zig").commitFlex;
 
@@ -39,7 +39,7 @@ pub const routes = [_]Match{
 
const E404Page = Template.PageData("4XX.html");
 
fn notFound(ctx: *Verse) Routes.Error!void {
fn notFound(ctx: *Verse) Router.Error!void {
// TODO fix this
@import("std").debug.print("404 for route\n", .{});
ctx.response.status = .not_found;
@@ -47,7 +47,7 @@ fn notFound(ctx: *Verse) Routes.Error!void {
ctx.sendPage(&page) catch unreachable;
}
 
pub fn router(ctx: *Verse) Callable {
pub fn router(ctx: *Verse) Router.Error!BuildFn {
// var i_count: usize = 0;
// var itr = Types.Delta.iterator(ctx.alloc, "");
// while (itr.next()) |it| {
@@ -55,11 +55,11 @@ pub fn router(ctx: *Verse) Callable {
// it.raze(ctx.alloc);
// }
 
return Routes.router(ctx, &routes);
return Router.router(ctx, &routes);
}
 
// TODO replace with better API
pub fn build(ctx: *Verse, call: Callable) Routes.Error!void {
pub fn build(ctx: *Verse, call: BuildFn) Router.Error!void {
return call(ctx) catch |err| switch (err) {
error.InvalidURI,
error.Unrouteable,