From 3584fa7b4fc76fda454bffe5b5491e2b3f6fc9bb Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 28 Apr 2023 18:40:48 -0700 Subject: [PATCH] add revList() --- git.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/git.zig b/git.zig index f95467c640af90090263caeb1ea71429f5d141ad..8b40329efebd141126c2e067040e2762b2864324 100644 --- a/git.zig +++ b/git.zig @@ -65,6 +65,26 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 { return try std.fmt.parseInt(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10); } +// TODO make this inspect .git/objects manually +// TODO make a version of this that accepts an array of sub_paths and searches all of them at once, so as to not lose spot in history when searching for many old paths +// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects +// https://git-scm.com/book/en/v2/Git-Internals-Packfiles +pub fn revList(alloc: std.mem.Allocator, dir: std.fs.Dir, comptime count: u31, from: CommitId, sub_path: string) !string { + const result = try std.ChildProcess.exec(.{ + .allocator = alloc, + .cwd_dir = dir, + .argv = &.{ + "git", + "rev-list", + "-" ++ std.fmt.comptimePrint("{d}", .{count}), + from.id, + "--", + sub_path, + }, + }); + return std.mem.trimRight(u8, result.stdout, "\n"); +} + 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