srctree

this isn't an issue. this is a diff no really!

no patch provided... oops

src/endpoints/repos/diffs.zig added: 92, removed: 14, total 78
@@ -362,15 +362,13 @@ fn view(ctx: *Context) Error!void {
@panic("oops");
}
 
try ctx.putContext("Delta_id", .{ .slice = delta_id });
 
const udata = ctx.reqdata.query.validate(PatchView) catch return error.BadData;
const inline_html = udata.@"inline" orelse true;
 
var patch_formatted: ?Template.Structs.PatchHtml = null;
const filename = try std.fmt.allocPrint(ctx.alloc, "data/patch/{s}.{x}.patch", .{ rd.name, delta.index });
 
if (std.fs.cwd().openFile(filename, .{})) |f| {
const patch_filename = try std.fmt.allocPrint(ctx.alloc, "data/patch/{s}.{x}.patch", .{ rd.name, delta.index });
var patch_applies: bool = false;
if (std.fs.cwd().openFile(patch_filename, .{})) |f| {
const fdata = f.readToEndAlloc(ctx.alloc, 0xFFFFF) catch return error.Unknown;
var patch = Patch.Patch.init(fdata);
if (patchStruct(ctx.alloc, &patch, !inline_html)) |phtml| {
@@ -379,10 +377,27 @@ fn view(ctx: *Context) Error!void {
std.debug.print("Unable to generate patch {any}\n", .{err});
}
f.close();
 
var cwd = std.fs.cwd();
const filename = try allocPrint(ctx.alloc, "./repos/{s}", .{rd.name});
const dir = cwd.openDir(filename, .{}) catch return error.Unknown;
var repo = Git.Repo.init(dir) catch return error.Unknown;
repo.loadData(ctx.alloc) catch return error.Unknown;
defer repo.raze();
var agent = repo.getAgent(ctx.alloc);
const applies = agent.checkPatch(fdata) catch |err| apl: {
std.debug.print("git apply failed {any}\n", .{err});
break :apl null;
};
if (applies == null) patch_applies = true;
} else |err| {
std.debug.print("Unable to load patch {} {s}\n", .{ err, filename });
std.debug.print("Unable to load patch {} {s}\n", .{ err, patch_filename });
}
 
const username = if (ctx.auth.valid())
(ctx.auth.user(ctx.alloc) catch unreachable).username
else
"public";
var page = DiffViewPage.init(.{
.meta_head = .{
.open_graph = .{},
@@ -400,6 +415,8 @@ fn view(ctx: *Context) Error!void {
},
.comments = comments_,
.delta_id = delta_id,
.patch_does_not_apply = if (patch_applies) .{} else null,
.current_username = username,
});
 
try ctx.sendPage(&page);
 
src/git/agent.zig added: 92, removed: 14, total 78
@@ -105,6 +105,19 @@ pub fn formatPatch(self: Agent, sha: []const u8) ![]u8 {
});
}
 
pub fn checkPatch(self: Agent, patch: []const u8) !?[]u8 {
const res = try self.execStdin(&.{
"git",
"apply",
"--check",
"--",
}, patch);
 
if (res.term.Exited == 0) return null;
std.debug.print("git apply error {}\n", .{res.term.Exited});
return error.DoesNotApply;
}
 
pub fn blame(self: Agent, name: []const u8) ![]u8 {
std.debug.print("{s}\n", .{name});
return try self.exec(&[_][]const u8{
@@ -115,6 +128,51 @@ pub fn blame(self: Agent, name: []const u8) ![]u8 {
});
}
 
fn execStdin(self: Agent, argv: []const []const u8, stdin: []const u8) !std.ChildProcess.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);
 
child.stdin_behavior = .Pipe;
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;
child.cwd_dir = cwd;
 
var stdout = std.ArrayList(u8).init(self.alloc);
var stderr = std.ArrayList(u8).init(self.alloc);
errdefer {
stdout.deinit();
stderr.deinit();
}
 
try child.spawn();
if (child.stdin) |cstdin| {
try cstdin.writeAll(stdin);
cstdin.close();
child.stdin = null;
}
 
child.collectOutput(&stdout, &stderr, 0x1fffff) catch |err| {
const errstr =
\\git agent error:
\\error :: {}
\\argv ::
;
std.debug.print(errstr, .{err});
for (argv) |arg| std.debug.print("{s} ", .{arg});
std.debug.print("\n", .{});
return err;
};
 
const res = std.ChildProcess.RunResult{
.term = try child.wait(),
.stdout = try stdout.toOwnedSlice(),
.stderr = try stderr.toOwnedSlice(),
};
 
return res;
}
 
fn execCustom(self: Agent, argv: []const []const u8) !std.ChildProcess.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;
 
static/main.css added: 92, removed: 14, total 78
@@ -94,6 +94,10 @@ button {
border-radius: 3px;
font-family: 'Titillium Web', sans-serif;
padding: 6px 18px;
 
&.red {
color: red;
}
}
 
lines {
 
templates/delta-diff.html added: 92, removed: 14, total 78
@@ -24,10 +24,11 @@
<_comment.html>
</For>
<form class="pretty" action="add-comment" method="POST">
<context><Current_username ORNULL></context>
<context><CurrentUsername></context>
<textarea name="comment"></textarea>
<button type="submit" name="comment">Comment</button>
<input type="hidden" name="did" value="<Delta_id>" />
<With PatchDoesNotApply><button type="submit" name="no-apply" class="red">Patch Does Not Apply</button></With>
<input type="hidden" name="did" value="<DeltaId>" />
</form>
</comments>
</content>
-
.47.0
 
 
public