Compare commits

...

2 commits

2 changed files with 16 additions and 18 deletions

View file

@ -20,26 +20,16 @@ pub fn workspace_path(context_: usize) Error!void {
pub fn current_branch(context_: usize) Error!void { pub fn current_branch(context_: usize) Error!void {
const fn_name = @src().fn_name; const fn_name = @src().fn_name;
if (current_branch_cache) |p| {
tp.self_pid().send(.{ module_name, context_, fn_name, p.branch }) catch {};
return;
}
try git(context_, .{ "rev-parse", "--abbrev-ref", "HEAD" }, struct { try git(context_, .{ "rev-parse", "--abbrev-ref", "HEAD" }, struct {
fn result(context: usize, parent: tp.pid_ref, output: []const u8) void { fn result(context: usize, parent: tp.pid_ref, output: []const u8) void {
var it = std.mem.splitScalar(u8, output, '\n'); var it = std.mem.splitScalar(u8, output, '\n');
while (it.next()) |value| if (value.len > 0) { while (it.next()) |value| if (value.len > 0) {
blk: {
current_branch_cache = .{ .branch = allocator.dupeZ(u8, value) catch break :blk };
}
parent.send(.{ module_name, context, fn_name, value }) catch {}; parent.send(.{ module_name, context, fn_name, value }) catch {};
return; return;
}; };
} }
}.result, exit_null_on_error(fn_name)); }.result, exit_null_on_error(fn_name));
} }
var current_branch_cache: ?struct {
branch: ?[:0]const u8 = null,
} = null;
pub fn workspace_files(context: usize) Error!void { pub fn workspace_files(context: usize) Error!void {
return git_line_output( return git_line_output(

View file

@ -169,20 +169,25 @@ const Process = struct {
} }
fn deinit(self: *Process) void { fn deinit(self: *Process) void {
if (self.sp) |*sp| sp.deinit(); if (self.sp) |*sp| {
defer self.sp = null;
sp.deinit();
}
self.parent.deinit(); self.parent.deinit();
self.logger.deinit(); self.logger.deinit();
self.allocator.free(self.arg0); self.allocator.free(self.arg0);
self.allocator.free(self.argv.buf); self.allocator.free(self.argv.buf);
self.close() catch {};
self.allocator.destroy(self); self.allocator.destroy(self);
} }
fn close(self: *Process) tp.result { fn close(self: *Process) void {
if (self.sp) |*sp| { defer self.sp = null;
defer self.sp = null; if (self.sp) |*sp| sp.close() catch {};
try sp.close(); }
}
fn term(self: *Process) void {
defer self.sp = null;
if (self.sp) |*sp| sp.term() catch {};
} }
fn start(self: *Process) tp.result { fn start(self: *Process) tp.result {
@ -204,14 +209,17 @@ const Process = struct {
const sp = self.sp orelse return tp.exit_error(error.Closed, null); const sp = self.sp orelse return tp.exit_error(error.Closed, null);
try sp.send(bytes); try sp.send(bytes);
} else if (try m.match(.{"close"})) { } else if (try m.match(.{"close"})) {
try self.close(); self.close();
} else if (try m.match(.{ module_name, "stdout", tp.extract(&bytes) })) { } else if (try m.match(.{ module_name, "stdout", tp.extract(&bytes) })) {
self.handlers.out(self.handlers.context, self.parent.ref(), self.arg0, bytes); self.handlers.out(self.handlers.context, self.parent.ref(), self.arg0, bytes);
} else if (try m.match(.{ module_name, "stderr", tp.extract(&bytes) })) { } else if (try m.match(.{ module_name, "stderr", tp.extract(&bytes) })) {
(self.handlers.err orelse self.handlers.out)(self.handlers.context, self.parent.ref(), self.arg0, bytes); (self.handlers.err orelse self.handlers.out)(self.handlers.context, self.parent.ref(), self.arg0, bytes);
} else if (try m.match(.{ module_name, "term", tp.more })) { } else if (try m.match(.{ module_name, "term", tp.more })) {
defer self.sp = null;
self.handle_terminated(m) catch |e| return tp.exit_error(e, @errorReturnTrace()); self.handle_terminated(m) catch |e| return tp.exit_error(e, @errorReturnTrace());
return tp.exit_normal();
} else if (try m.match(.{ "exit", "normal" })) { } else if (try m.match(.{ "exit", "normal" })) {
self.term();
return tp.exit_normal(); return tp.exit_normal();
} else { } else {
self.logger.err("receive", tp.unexpected(m)); self.logger.err("receive", tp.unexpected(m));