srctree

Gregory Mullen parent 62acc684 8f5bc6b5
update internals to work on zig v0.13

Originally an update to test stdlib's new TLS on v0.14-dev but that failed, and it just so happens this is where I update srctree to git v0.13.
.gitignore added: 98, removed: 94, total 4
@@ -1,5 +1,7 @@
repos/*
zig-*/*
zig-out/*
zig-cache/*
.zig-cache/*
data/*
 
config.ini
 
src/context.zig added: 98, removed: 94, total 4
@@ -1,6 +1,6 @@
pub const std = @import("std");
 
const Allocator = std.mem.Allocator;
const splitScalar = std.mem.splitScalar;
 
const zWSGI = @import("zwsgi.zig");
const Auth = @import("auth.zig");
@@ -44,7 +44,7 @@ pub fn init(a: Allocator, cfg: ?Config, req: Request, res: Response, reqdata: Re
.request = req,
.response = res,
.reqdata = reqdata,
.uri = std.mem.split(u8, req.uri[1..], "/"),
.uri = splitScalar(u8, req.uri[1..], '/'),
.cfg = cfg,
.auth = Auth.init(req.headers),
.template_ctx = Template.Context.init(a),
 
src/endpoints/admin.zig added: 98, removed: 94, total 4
@@ -86,7 +86,7 @@ fn postCloneUpstream(ctx: *Context) Error!void {
 
const udata = ctx.reqdata.post.?.validate(CloneUpstreamReq) catch return error.BadData;
std.debug.print("repo uri {s}\n", .{udata.repo_uri});
var nameitr = std.mem.splitBackwards(u8, udata.repo_uri, "/");
var nameitr = std.mem.splitBackwardsScalar(u8, udata.repo_uri, '/');
const name = nameitr.first();
std.debug.print("repo uri {s}\n", .{name});
 
 
src/endpoints/repos.zig added: 98, removed: 94, total 4
@@ -418,7 +418,7 @@ fn parseBlame(a: Allocator, blame_txt: []const u8) !struct {
 
const count = std.mem.count(u8, blame_txt, "\n\t");
const lines = try a.alloc(BlameLine, count);
var in_lines = std.mem.split(u8, blame_txt, "\n");
var in_lines = std.mem.splitScalar(u8, blame_txt, '\n');
for (lines) |*blm| {
const line = in_lines.next() orelse break;
if (line.len < 40) unreachable;
@@ -501,7 +501,7 @@ fn blame(ctx: *Context) Error!void {
break :fmt pre[28..][0 .. pre.len - 38];
} else Bleach.sanitizeAlloc(ctx.alloc, source_lines.items, .{}) catch return error.Unknown;
 
var litr = std.mem.split(u8, formatted, "\n");
var litr = std.mem.splitScalar(u8, formatted, '\n');
for (parsed.lines) |*line| {
if (litr.next()) |n| {
line.line = n;
@@ -553,7 +553,7 @@ fn wrapLineNumbers(a: Allocator, root_dom: *DOM, text: []const u8) !*DOM {
// TODO
 
var i: usize = 0;
var litr = std.mem.split(u8, text, "\n");
var litr = std.mem.splitScalar(u8, text, '\n');
while (litr.next()) |line| {
var pbuf: [12]u8 = undefined;
const b = std.fmt.bufPrint(&pbuf, "#L{}", .{i + 1}) catch unreachable;
@@ -664,7 +664,7 @@ fn htmlReadme(a: Allocator, readme: []const u8) ![]HTML.E {
dom = dom.open(HTML.element("readme", null, null));
dom.push(HTML.element("intro", "README.md", null));
dom = dom.open(HTML.element("code", null, null));
var litr = std.mem.split(u8, readme, "\n");
var litr = std.mem.splitScalar(u8, readme, '\n');
while (litr.next()) |dirty| {
const clean = Bleach.sanitizeAlloc(a, dirty, .{}) catch return error.Unknown;
dom.push(HTML.element("ln", clean, null));
 
src/endpoints/repos/diffs.zig added: 98, removed: 94, total 4
@@ -129,8 +129,9 @@ fn new(ctx: *Context) Error!void {
}
 
fn inNetwork(str: []const u8) bool {
if (!std.mem.startsWith(u8, str, "https://srctree.gr.ht")) return false;
for (str) |c| if (c == '@') return false;
//if (!std.mem.startsWith(u8, str, "https://srctree.gr.ht")) return false;
//for (str) |c| if (c == '@') return false;
_ = str;
return true;
}
 
@@ -157,37 +158,36 @@ fn createDiff(ctx: *Context) Error!void {
}
}
 
var delta = Delta.new(
rd.name,
udata.title,
udata.desc,
if (ctx.auth.valid())
(ctx.auth.user(ctx.alloc) catch unreachable).username
else
try allocPrint(ctx.alloc, "REMOTE_ADDR {s}", .{remote_addr}),
) catch unreachable;
delta.commit() catch unreachable;
 
if (inNetwork(udata.patch_uri)) {
std.debug.print("src {s}\ntitle {s}\ndesc {s}\naction {s}\n", .{
udata.patch_uri,
const data = Patch.loadRemote(ctx.alloc, udata.patch_uri) catch unreachable;
 
std.debug.print(
"src {s}\ntitle {s}\ndesc {s}\naction {s}\n",
.{ udata.patch_uri, udata.title, udata.desc, "unimplemented" },
);
var delta = Delta.new(
rd.name,
udata.title,
udata.desc,
"unimplemented",
});
const data = Patch.loadRemote(ctx.alloc, udata.patch_uri) catch unreachable;
const filename = std.fmt.allocPrint(
ctx.alloc,
"data/patch/{s}.{x}.patch",
.{ rd.name, delta.index },
if (ctx.auth.valid())
(ctx.auth.user(ctx.alloc) catch unreachable).username
else
try allocPrint(ctx.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", .{
rd.name,
delta.index,
}) catch unreachable;
var file = std.fs.cwd().createFile(filename, .{}) catch unreachable;
defer file.close();
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;
}
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 try new(ctx);
 
src/endpoints/repos/issues.zig added: 98, removed: 94, total 4
@@ -205,7 +205,7 @@ fn list(ctx: *Context) Error!void {
var default_search_buf: [0xFF]u8 = undefined;
const def_search = try bufPrint(&default_search_buf, "is:issue repo:{s} ", .{rd.name});
 
const meta_head = Template.Structs.MetaHeadHtml{
const meta_head = S.MetaHeadHtml{
.open_graph = .{},
};
 
 
src/endpoints/search.zig added: 98, removed: 94, total 4
@@ -1,5 +1,6 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const splitScalar = std.mem.splitScalar;
 
const Context = @import("../context.zig");
const Delta = @import("../types.zig").Delta;
@@ -42,7 +43,7 @@ fn custom(ctx: *Context, search_str: []const u8) Error!void {
 
var rules = std.ArrayList(Delta.SearchRule).init(ctx.alloc);
 
var itr = std.mem.split(u8, search_str, " ");
var itr = splitScalar(u8, search_str, ' ');
while (itr.next()) |r_line| {
var line = r_line;
line = std.mem.trim(u8, line, " ");
 
src/git.zig added: 98, removed: 94, total 4
@@ -406,7 +406,7 @@ pub const Repo = struct {
var buf: [2048]u8 = undefined;
const size = try file.readAll(&buf);
const b = buf[0..size];
var p_itr = std.mem.split(u8, b, "\n");
var p_itr = splitScalar(u8, b, '\n');
_ = p_itr.next();
while (p_itr.next()) |line| {
if (std.mem.indexOf(u8, line, "refs/heads")) |_| {
@@ -732,7 +732,7 @@ pub const Tag = struct {
var object: ?[]const u8 = null;
var ttype: ?TagType = null;
var actor: ?Actor = null;
var itr = std.mem.splitScalar(u8, blob, '\n');
var itr = splitScalar(u8, blob, '\n');
while (itr.next()) |line| {
if (startsWith(u8, line, "object ")) {
object = line[7..];
@@ -958,7 +958,7 @@ test "tree decom" {
 
test "tree child" {
var a = std.testing.allocator;
const child = try std.ChildProcess.run(.{
const child = try std.process.Child.run(.{
.allocator = a,
.argv = &[_][]const u8{
"git",
 
src/git/actor.zig added: 98, removed: 94, total 4
@@ -11,7 +11,7 @@ timestamp: i64 = 0,
tz: i64 = 0,
 
pub fn make(data: []const u8) !Actor {
var itr = std.mem.splitBackwards(u8, data, " ");
var itr = std.mem.splitBackwardsScalar(u8, data, ' ');
const tzstr = itr.next() orelse return error.ActorParse;
const epoch = itr.next() orelse return error.ActorParse;
const epstart = itr.index orelse return error.ActorParse;
 
src/git/agent.zig added: 98, removed: 94, total 4
@@ -102,7 +102,6 @@ pub fn formatPatch(self: Agent, sha: []const u8) ![]u8 {
"format-patch",
"--histogram",
"--stdout",
"-1",
sha,
});
}
@@ -133,10 +132,10 @@ pub fn blame(self: Agent, name: []const u8) ![]u8 {
});
}
 
fn execStdin(self: Agent, argv: []const []const u8, stdin: []const u8) !std.ChildProcess.RunResult {
fn execStdin(self: Agent, argv: []const []const u8, stdin: []const u8) !std.process.Child.RunResult {
std.debug.assert(std.mem.eql(u8, argv[0], "git"));
const cwd = if (self.cwd != null and self.cwd.?.fd != std.fs.cwd().fd) self.cwd else null;
var child = std.ChildProcess.init(argv, self.alloc);
var child = std.process.Child.init(argv, self.alloc);
 
child.stdin_behavior = .Pipe;
child.stdout_behavior = .Pipe;
@@ -169,7 +168,7 @@ fn execStdin(self: Agent, argv: []const []const u8, stdin: []const u8) !std.Chil
return err;
};
 
const res = std.ChildProcess.RunResult{
const res = std.process.Child.RunResult{
.term = try child.wait(),
.stdout = try stdout.toOwnedSlice(),
.stderr = try stderr.toOwnedSlice(),
@@ -178,10 +177,10 @@ fn execStdin(self: Agent, argv: []const []const u8, stdin: []const u8) !std.Chil
return res;
}
 
fn execCustom(self: Agent, argv: []const []const u8) !std.ChildProcess.RunResult {
fn execCustom(self: Agent, argv: []const []const u8) !std.process.Child.RunResult {
std.debug.assert(std.mem.eql(u8, argv[0], "git"));
const cwd = if (self.cwd != null and self.cwd.?.fd != std.fs.cwd().fd) self.cwd else null;
const child = std.ChildProcess.run(.{
const child = std.process.Child.run(.{
.cwd_dir = cwd,
.allocator = self.alloc,
.argv = argv,
 
src/git/commit.zig added: 98, removed: 94, total 4
@@ -65,7 +65,7 @@ fn gpgSig(_: *Commit, itr: *std.mem.SplitIterator(u8, .sequence)) !void {
 
pub fn init(sha: SHA, data: []const u8) !Commit {
if (std.mem.startsWith(u8, data, "commit")) unreachable;
var lines = std.mem.split(u8, data, "\n");
var lines = std.mem.splitSequence(u8, data, "\n");
var self: Commit = undefined;
// I don't like it either, but... lazy
self.parent = .{ null, null, null, null, null, null, null, null, null };
@@ -125,7 +125,7 @@ pub fn mkSubTree(self: Commit, a: Allocator, subpath: ?[]const u8, repo: *const
const rootpath = subpath orelse return self.mkTree(a, repo);
if (rootpath.len == 0) return self.mkTree(a, repo);
 
var itr = std.mem.split(u8, rootpath, "/");
var itr = std.mem.splitScalar(u8, rootpath, '/');
var root = try self.mkTree(a, repo);
root.path = try a.dupe(u8, rootpath);
iter: while (itr.next()) |path| {
 
src/gitweb.zig added: 98, removed: 94, total 4
@@ -68,7 +68,7 @@ fn gitUploadPack(ctx: *Context) Error!void {
try map.put("GIT_PROTOCOL", "version=2");
try map.put("GIT_HTTP_EXPORT_ALL", "true");
 
var child = std.ChildProcess.init(&[_][]const u8{ "git", "http-backend" }, ctx.alloc);
var child = std.process.Child.init(&[_][]const u8{ "git", "http-backend" }, ctx.alloc);
child.stdin_behavior = .Pipe;
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Ignore;
 
src/ini.zig added: 98, removed: 94, total 4
@@ -1,5 +1,6 @@
const std = @import("std");
const eql = std.mem.eql;
const splitScalar = std.mem.splitScalar;
 
const Allocator = std.mem.Allocator;
 
@@ -31,7 +32,7 @@ pub const Namespace = struct {
pub fn init(
a: Allocator,
name: []const u8,
itr: *std.mem.SplitIterator(u8, .sequence),
itr: *std.mem.SplitIterator(u8, .scalar),
) !Namespace {
var list = std.ArrayList(Setting).init(a);
const ns_start = itr.index.?;
@@ -142,7 +143,7 @@ pub fn initDupe(a: Allocator, ini: []const u8) !Config {
 
/// `data` must outlive returned Config, use initDupe otherwise
pub fn init(a: Allocator, data: []const u8) !Config {
var itr = std.mem.split(u8, data, "\n");
var itr = std.mem.splitScalar(u8, data, '\n');
 
var list = std.ArrayList(Namespace).init(a);
 
 
src/patch.zig added: 98, removed: 94, total 4
@@ -6,6 +6,7 @@ const assert = std.debug.assert;
const eql = std.mem.eql;
const indexOf = std.mem.indexOf;
const indexOfPos = std.mem.indexOfPos;
const splitScalar = std.mem.splitScalar;
 
const CURL = @import("curl.zig");
const Bleach = @import("bleach.zig");
@@ -343,25 +344,23 @@ pub fn patchStat(p: Patch) Stat {
}
 
fn fetch(a: Allocator, uri: []const u8) ![]u8 {
// disabled until tls1.2 is supported
// var client = std.http.client{
// .allocator = a,
// };
// defer client.deinit();
var client = std.http.Client{ .allocator = a };
//defer client.deinit();
 
// var request = client.fetch(a, .{
// .location = .{ .url = uri },
// });
// if (request) |*req| {
// defer req.deinit();
// std.debug.print("request code {}\n", .{req.status});
// if (req.body) |b| {
// std.debug.print("request body {s}\n", .{b});
// return a.dupe(u8, b);
// }
// } else |err| {
// std.debug.print("stdlib request failed with error {}\n", .{err});
// }
var response = std.ArrayList(u8).init(a);
defer response.clearAndFree();
const request = client.fetch(.{
.location = .{ .url = uri },
.response_storage = .{ .dynamic = &response },
.max_append_size = 0xffffff,
});
if (request) |req| {
std.debug.print("request code {}\n", .{req.status});
std.debug.print("request body {s}\n", .{response.items});
return try response.toOwnedSlice();
} else |err| {
std.debug.print("stdlib request failed with error {}\n", .{err});
}
 
const curl = try CURL.curlRequest(a, uri);
if (curl.code != 200) return error.UnexpectedResponseCode;
@@ -384,7 +383,7 @@ pub fn diffLineHtmlSplit(a: Allocator, diff: []const u8) ![]HTML.Element {
 
const clean = Bleach.sanitizeAlloc(a, diff, .{}) catch unreachable;
const line_count = std.mem.count(u8, clean, "\n");
var litr = std.mem.split(u8, clean, "\n");
var litr = std.mem.splitScalar(u8, clean, '\n');
const nbsp = "&nbsp;";
 
const LinePair = struct {
@@ -458,7 +457,7 @@ pub fn diffLineHtmlUnified(a: Allocator, diff: []const u8) []HTML.Element {
 
const clean = Bleach.sanitizeAlloc(a, diff, .{}) catch unreachable;
const line_count = std.mem.count(u8, clean, "\n");
var litr = std.mem.split(u8, clean, "\n");
var litr = splitScalar(u8, clean, '\n');
for (0..line_count + 1) |_| {
const a_add = &HTML.Attr.class("add");
const a_del = &HTML.Attr.class("del");
 
src/request_data.zig added: 98, removed: 94, total 4
@@ -2,6 +2,8 @@ const std = @import("std");
const Type = @import("builtin").Type;
const Allocator = std.mem.Allocator;
const eql = std.mem.eql;
const splitScalar = std.mem.splitScalar;
const splitSequence = std.mem.splitSequence;
 
const Data = @This();
 
@@ -112,7 +114,7 @@ pub const QueryData = struct {
 
/// TODO leaks on error
pub fn init(a: Allocator, query: []const u8) !QueryData {
var itr = std.mem.split(u8, query, "&");
var itr = splitScalar(u8, query, '&');
const count = std.mem.count(u8, query, "&") + 1;
const items = try a.alloc(DataItem, count);
for (items) |*item| {
@@ -319,7 +321,7 @@ fn parseApplication(a: Allocator, ap: ContentType.Application, data: []u8, htype
.@"x-www-form-urlencoded" => {
std.debug.assert(std.mem.startsWith(u8, htype, "application/x-www-form-urlencoded"));
 
var itr = std.mem.split(u8, data, "&");
var itr = splitScalar(u8, data, '&');
const count = std.mem.count(u8, data, "&") +| 1;
const items = try a.alloc(DataItem, count);
for (items) |*itm| {
@@ -380,7 +382,7 @@ const MultiData = struct {
};
 
fn parseMultiData(data: []const u8) !MultiData {
var extra = std.mem.split(u8, data, ";");
var extra = splitScalar(u8, data, ';');
const first = extra.first();
const header = try DataHeader.fromStr(first);
var mdata: MultiData = .{
@@ -406,7 +408,7 @@ fn parseMultiFormData(a: Allocator, data: []const u8) !DataItem {
};
 
post_item.headers = data[0..i];
var headeritr = std.mem.split(u8, post_item.headers.?, "\r\n");
var headeritr = splitSequence(u8, post_item.headers.?, "\r\n");
while (headeritr.next()) |header| {
if (header.len == 0) continue;
const md = try parseMultiData(header);
@@ -434,7 +436,7 @@ fn parseMulti(a: Allocator, mp: ContentType.MultiPart, data: []const u8, htype:
const boundry = boundry_buffer[0 .. bound_given.len + 2];
const count = std.mem.count(u8, data, boundry) -| 1;
const items = try a.alloc(DataItem, count);
var itr = std.mem.split(u8, data, boundry);
var itr = splitSequence(u8, data, boundry);
_ = itr.first(); // the RFC says I'm supposed to ignore the preamble :<
for (items) |*itm| {
itm.* = try parseMultiFormData(a, itr.next().?);
 
src/routes.zig added: 98, removed: 94, total 4
@@ -14,7 +14,7 @@ const StaticFile = @import("static-file.zig");
pub const Errors = @import("errors.zig");
pub const Error = Errors.ServerError || Errors.ClientError || Errors.NetworkError;
 
pub const UriIter = std.mem.SplitIterator(u8, .sequence);
pub const UriIter = std.mem.SplitIterator(u8, .scalar);
 
pub const Router = *const fn (*Context) Error!Callable;
pub const Callable = *const fn (*Context) Error!void;
 
src/syntax-highlight.zig added: 98, removed: 94, total 4
@@ -35,7 +35,7 @@ pub const Language = enum {
};
 
pub fn highlight(a: Allocator, lang: Language, text: []const u8) ![]u8 {
var child = std.ChildProcess.init(&[_][]const u8{
var child = std.process.Child.init(&[_][]const u8{
"pygmentize",
"-f",
"html",