authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-14 16:22:15 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-14 16:22:15 -07:00
logaa32b286047d782c4aea3def44d8e20e328296d2
tree4d284699a7484c87e0936d636a94e9ce29657b7f
parentb8aab1f7bbda37a477646649af29aa73dbdfcd8a

add getBranches


1 files changed, 27 insertions(+), 0 deletions(-)

git.zig+27
...@@ -551,3 +551,30 @@ pub const TreeDiff = struct {...@@ -551,3 +551,30 @@ pub const TreeDiff = struct {
551 content: string,551 content: string,
552 };552 };
553};553};
554
555pub fn getBranches(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const Ref {
556 const result = try std.ChildProcess.exec(.{
557 .allocator = alloc,
558 .cwd_dir = dir,
559 .argv = &.{ "git", "show-ref", "--heads" },
560 .max_output_bytes = 1024 * 1024 * 1024,
561 });
562 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
563 const output = std.mem.trimRight(u8, result.stdout, "\n");
564 var iter = std.mem.split(u8, output, "\n");
565 var list = std.ArrayList(Ref).init(alloc);
566 errdefer list.deinit();
567 while (iter.next()) |line| {
568 var jter = std.mem.split(u8, line, " ");
569 try list.append(.{
570 .commit = ensureObjId(CommitId, jter.next().?),
571 .label = extras.trimPrefixEnsure(jter.rest(), "refs/heads/").?,
572 });
573 }
574 return list.toOwnedSlice();
575}
576
577pub const Ref = struct {
578 label: string,
579 commit: CommitId,
580};