| ... | @@ -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 | } |
| 75 | | 75 | |
| | 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 |
| | 79 | pub 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 manually | 90 | // TODO make this inspect .git/objects manually |
| 77 | // TODO make this return a Reader when we implement it ourselves | 91 | // 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 paths | 92 | // 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 |