From 3d408725231b4c6b45ccc9ba5a050d4a5ab1a3b7 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 10 May 2026 16:43:48 -0700 Subject: [PATCH] add Tree.Object.Mode.intbytes() reconstructs the 6 byte string used in cat-file etc --- git.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/git.zig b/git.zig index 54986adf0da12a41592583d782abbfdabc657f80..5d0f186a32607830a6cd7a59430a57c2dcce8432 100644 --- a/git.zig +++ b/git.zig @@ -1416,6 +1416,21 @@ pub const Tree = struct { if (self.perm_other != other.perm_other) return false; return true; } + + pub fn intbytes(self: Mode) [6]u8 { + var b: [6]u8 = @splat('-'); + @memcpy(b[0..3], switch (self.type) { + .file => "100", + .directory => "040", + .submodule => "160", + .symlink => "120", + .none => "000", + }); + b[3] = @as(u8, @as(u3, @bitCast(self.perm_user))) + '0'; + b[4] = @as(u8, @as(u3, @bitCast(self.perm_group))) + '0'; + b[5] = @as(u8, @as(u3, @bitCast(self.perm_other))) + '0'; + return b; + } }; pub const Type = enum(u8) { -- 2.54.0