authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-04 20:32:56 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-04 20:32:56 -07:00
log9124e4cd420d766d6fd38edab9a2c99f3f580e05
treeefb95ef347985e8be16db1add93af78c588a86f7
parent8cac0cbd46ecdd17bc76b3e136724e2b67f5d55b

add isType


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

git.zig+14
...@@ -73,6 +73,20 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 {...@@ -73,6 +73,20 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 {
73 return try std.fmt.parseInt(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10);73 return try std.fmt.parseInt(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10);
74}74}
7575
76// TODO make this inspect .git manually
77// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
78// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
79pub fn isType(alloc: std.mem.Allocator, dir: std.fs.Dir, maybeobj: Id, typ: Tree.Object.Id.Tag) !?bool {
80 const result = try std.ChildProcess.exec(.{
81 .allocator = alloc,
82 .cwd_dir = dir,
83 .argv = &.{ "git", "cat-file", "-t", maybeobj },
84 });
85 if (result.term != .Exited or result.term.Exited != 0) return null;
86 const output = std.mem.trimRight(u8, result.stdout, "\n");
87 return std.meta.stringToEnum(Tree.Object.Id.Tag, output).? == typ;
88}
89
76// TODO make this inspect .git/objects manually90// TODO make this inspect .git/objects manually
77// TODO make this return a Reader when we implement it ourselves91// TODO make this return a Reader when we implement it ourselves
78// 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 paths92// 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