-
-
Save kbd/791687547f2271f85bf272b091d64fbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ zig build-exe evented_test_case.zig | |
broken LLVM module found: Basic Block in function 'std.child_process.ChildProcess.spawnPosix' does not have terminator! | |
label %OkResume | |
Instruction does not dominate all uses! | |
%28 = load { %std.child_process.Term, i16 }*, { %std.child_process.Term, i16 }** %6, align 8, !dbg !6264 | |
%41 = bitcast { %std.child_process.Term, i16 }* %28 to i8*, !dbg !6264 | |
This is a bug in the Zig compiler. | |
Unable to dump stack trace: debug info stripped | |
zsh: abort zig build-exe evented_test_case.zig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const stdout = std.io.getStdOut().writer(); | |
const print = stdout.print; | |
const Allocator = std.mem.Allocator; | |
const Str = []const u8; | |
pub var A: *Allocator = undefined; | |
pub const io_mode = .evented; | |
const GitStatus = struct { | |
// state: Str, | |
branch: Str, | |
status: Str, | |
// stash: Table[Str, int] | |
}; | |
fn run(argv: []const Str) !std.ChildProcess.ExecResult { | |
return try std.ChildProcess.exec(.{ | |
.allocator = A, | |
.argv = argv, | |
}); | |
} | |
fn concatStringArray(lists: []const []Str) ![]Str { | |
return try std.mem.concat(A, Str, lists); | |
} | |
fn gitCmd(args: []Str, workingdir: Str) !std.ChildProcess.ExecResult { | |
var gitcmd = [_]Str{"git", "-C", workingdir}; | |
var cmd_parts = [_][]Str{ &gitcmd, args }; | |
var cmd = try concatStringArray(&cmd_parts); | |
return try run(cmd); | |
} | |
fn getBranch(dir: Str) !Str { | |
var cmd1 = [_]Str{"symbolic-ref", "HEAD", "--short"}; | |
var result = try gitCmd(&cmd1, dir); | |
if (result.term.Exited == 0) | |
return result.stdout; | |
var cmd2 = [_]Str{"describe", "--all", "--contains", "--always", "HEAD"}; | |
result = try gitCmd(&cmd2, dir); | |
return result.stdout; | |
} | |
fn getStatus(dir: Str) !Str { | |
// get and parse status codes | |
var cmd = [_]Str{"status", "-zb"}; | |
var result = try gitCmd(&cmd, dir); | |
if (result.term.Exited != 0) | |
return error.GitStatusFailed; | |
return result.stdout; | |
} | |
fn getFullRepoStatus(dir: Str) !GitStatus { | |
var branch = async getBranch(dir); | |
var status = async getStatus(dir); | |
return GitStatus{ | |
// .state = getState(dir), | |
.branch = try await branch, | |
.status = try await status, | |
// .stash = getRepoStashCounts(dir), | |
}; | |
} | |
pub fn main() !u8 { | |
// allocator setup | |
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
defer arena.deinit(); | |
A = &arena.allocator; | |
var dir: Str = "."; | |
var status = try getFullRepoStatus(dir); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiles and runs if you comment out: