authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-28 18:40:48 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-28 18:40:48 -07:00
log3584fa7b4fc76fda454bffe5b5491e2b3f6fc9bb
tree75575d70cf5c7708d9a22384969040bab8cb63e1
parent845c968360532acd1533f6156ee9bbca3c1ef02f

add revList()


1 files changed, 20 insertions(+), 0 deletions(-)

git.zig+20
...@@ -65,6 +65,26 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 {...@@ -65,6 +65,26 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 {
65 return try std.fmt.parseInt(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10);65 return try std.fmt.parseInt(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10);
66}66}
6767
68// TODO make this inspect .git/objects manually
69// 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
70// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
71// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
72pub fn revList(alloc: std.mem.Allocator, dir: std.fs.Dir, comptime count: u31, from: CommitId, sub_path: string) !string {
73 const result = try std.ChildProcess.exec(.{
74 .allocator = alloc,
75 .cwd_dir = dir,
76 .argv = &.{
77 "git",
78 "rev-list",
79 "-" ++ std.fmt.comptimePrint("{d}", .{count}),
80 from.id,
81 "--",
82 sub_path,
83 },
84 });
85 return std.mem.trimRight(u8, result.stdout, "\n");
86}
87
68pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit {88pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit {
69 var iter = std.mem.split(u8, commitfile, "\n");89 var iter = std.mem.split(u8, commitfile, "\n");
70 var result: Commit = undefined;90 var result: Commit = undefined;