From 845c968360532acd1533f6156ee9bbca3c1ef02f Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 28 Apr 2023 18:40:40 -0700 Subject: [PATCH] add getObjectSize() --- git.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git.zig b/git.zig index 3597ec55b14215d6563c914db2e4bedd9cd8ba25..f95467c640af90090263caeb1ea71429f5d141ad 100644 --- a/git.zig +++ b/git.zig @@ -53,6 +53,18 @@ pub fn getObject(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !string { return std.mem.trimRight(u8, result.stdout, "\n"); } +// TODO make this inspect .git/objects manually +// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects +// https://git-scm.com/book/en/v2/Git-Internals-Packfiles +pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 { + const result = try std.ChildProcess.exec(.{ + .allocator = alloc, + .cwd_dir = dir, + .argv = &.{ "git", "cat-file", "-s", obj }, + }); + return try std.fmt.parseInt(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10); +} + pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { var iter = std.mem.split(u8, commitfile, "\n"); var result: Commit = undefined; -- 2.54.0