From 686b598e608c15fe86f871113c0fd7f47fab9d26 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 14 Mar 2026 04:47:26 -0700 Subject: [PATCH] add some nprint impls --- git.zig | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/git.zig b/git.zig index c403d55f5df2b6d32992a4ca304ec132a8791fca..ece5647d243797ad88fe78b1855efe1141172a7b 100644 --- a/git.zig +++ b/git.zig @@ -415,12 +415,18 @@ pub const Tree = struct { pub fn format(self: Mode, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void { _ = fmt; _ = options; - try writer.print("{}", .{self.type}); try writer.print("{}", .{self.perm_user}); try writer.print("{}", .{self.perm_group}); try writer.print("{}", .{self.perm_other}); } + + pub fn nprint(self: Mode, writer: anytype) !void { + try self.type.nprint(writer); + try self.perm_user.nprint(writer); + try self.perm_group.nprint(writer); + try self.perm_other.nprint(writer); + } }; pub const Type = enum(u16) { @@ -433,7 +439,6 @@ pub const Tree = struct { pub fn format(self: Type, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void { _ = fmt; _ = options; - try writer.writeByte(switch (self) { .file => '-', .directory => 'd', @@ -442,6 +447,16 @@ pub const Tree = struct { .none => '-', }); } + + pub fn nprint(self: Type, writer: anytype) !void { + try writer.writeAll(&.{switch (self) { + .file => '-', + .directory => 'd', + .submodule => 'm', + .symlink => '-', + .none => '-', + }}); + } }; pub const Perm = packed struct(u3) { @@ -452,11 +467,18 @@ pub const Tree = struct { pub fn format(self: Perm, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void { _ = fmt; _ = options; - try writer.writeByte(if (self.read) 'r' else '-'); try writer.writeByte(if (self.write) 'w' else '-'); try writer.writeByte(if (self.execute) 'x' else '-'); } + + pub fn nprint(self: Perm, writer: anytype) !void { + try writer.writeAll(&.{ + if (self.read) 'r' else '-', + if (self.write) 'w' else '-', + if (self.execute) 'x' else '-', + }); + } }; }; }; -- 2.54.0