authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-09 13:41:44 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-09 13:41:44 -07:00
log8c3b8d96a56bbabed9209ecf822235ef774da01f
treefb33f47baeb76047e0759bfbcfaa17884397eaea
parentbc26c340f602dd61cf3e84b3ba84e8d9f22ae327
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

rework getBranches and getTags


1 files changed, 10 insertions(+), 36 deletions(-)

git.zig+10-36
......@@ -770,7 +770,7 @@ pub const TreeDiff = struct {
770770 };
771771};
772772
773pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref {
773pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]Ref {
774774 const t = tracer.trace(@src(), "", .{});
775775 defer t.end();
776776
......@@ -788,15 +788,14 @@ pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref {
788788 while (iter.next()) |line| {
789789 var jter = std.mem.splitScalar(u8, line, ' ');
790790 try list.append(Ref{
791 .commit = ensureObjId(CommitId, jter.next().?),
791 .oid = ensureObjId(CommitId, jter.next().?).id,
792792 .label = extras.trimPrefixEnsure(jter.rest(), "refs/heads/").?,
793 .tag = null,
794793 });
795794 }
796795 return list.toOwnedSlice();
797796}
798797
799pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref {
798pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]Ref {
800799 const t = tracer.trace(@src(), "", .{});
801800 defer t.end();
802801
......@@ -807,7 +806,7 @@ pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref {
807806 const result = try std.process.Child.run(.{
808807 .allocator = alloc,
809808 .cwd_dir = dir.to_std(),
810 .argv = &.{ "git", "show-ref", "--tags", "--dereference" },
809 .argv = &.{ "git", "show-ref", "--tags" },
811810 .max_output_bytes = 1024 * 1024 * 1024,
812811 });
813812 if (result.term == .Exited and result.term.Exited == 1) return &.{}; // show-ref exits 1 when there are no tags
......@@ -820,43 +819,18 @@ pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref {
820819 var jter = std.mem.splitScalar(u8, line, ' ');
821820 const id = ensureObjId(CommitId, jter.next().?).id;
822821 const label = extras.trimPrefixEnsure(jter.rest(), "refs/tags/").?;
823 extras.assertLog(!std.mem.endsWith(u8, label, "^{}"), "{s}", .{label});
824
825 switch (try getType(alloc, dir, id)) {
826 .tree => continue,
827 .blob => unreachable,
828 .commit => {
829 try list.append(Ref{
830 .label = label,
831 .commit = ensureObjId(CommitId, id),
832 .tag = null,
833 });
834 },
835 .tag => {
836 const derefline = iter.next().?;
837 var kter = std.mem.splitScalar(u8, derefline, ' ');
838 const id2 = ensureObjId(CommitId, kter.next().?).id;
839 const label2 = extras.trimPrefixEnsure(kter.rest(), "refs/tags/").?;
840 extras.assertLog(std.mem.endsWith(u8, label2, "^{}"), "{s}", .{label2});
841 std.debug.assert(std.mem.eql(u8, label, extras.trimSuffixEnsure(label2, "^{}").?));
842 // extras.assertLog(try isType(alloc, dir, id2, .commit), id2); // linux kernel has a single tag that points at a tree
843 if (!try isType(alloc, dir, id2, .commit)) continue;
844
845 try list.append(Ref{
846 .label = label,
847 .commit = ensureObjId(CommitId, id2),
848 .tag = ensureObjId(TagId, id),
849 });
850 },
851 }
822
823 try list.append(Ref{
824 .oid = id,
825 .label = label,
826 });
852827 }
853828 return list.toOwnedSlice();
854829}
855830
856831pub const Ref = struct {
832 oid: Id,
857833 label: string,
858 commit: CommitId,
859 tag: ?TagId,
860834};
861835
862836// TODO make this inspect .git/objects