authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-10 18:09:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-10 18:09:38 -07:00
log4c50d70fc94e765b1bf7b5e13f629ee1eea887e4
treed653522ad4d91b5453812ddde1a0fee471c4a3da
parentb4add621bf8f306a27151db9699f7368d8da02c8

util- `git_rev_HEAD` now accepts a `std.fs.Dir`


2 files changed, 4 insertions(+), 3 deletions(-)

src/util/dep_type.zig+3-1
......@@ -75,10 +75,12 @@ pub const DepType = enum {
7575 }
7676
7777 pub fn exact_version(self: DepType, mpath: []const u8) ![]const u8 {
78 var mdir = try std.fs.cwd().openDir(mpath, .{});
79 defer mdir.close();
7880 return switch (self) {
7981 .local => "",
8082 .system_lib => "",
81 .git => try std.fmt.allocPrint(gpa, "commit-{s}", .{(try u.git_rev_HEAD(gpa, mpath))[0..7]}),
83 .git => try std.fmt.allocPrint(gpa, "commit-{s}", .{(try u.git_rev_HEAD(gpa, mdir))[0..7]}),
8284 .hg => "",
8385 .http => "",
8486 };
src/util/funcs.zig+1-2
......@@ -251,9 +251,8 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {
251251}
252252
253253/// Returns the result of running `git rev-parse HEAD`
254pub fn git_rev_HEAD(alloc: *std.mem.Allocator, path: []const u8) ![]const u8 {
254pub fn git_rev_HEAD(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]const u8 {
255255 const max = std.math.maxInt(usize);
256 const dir = try std.fs.cwd().openDir(path, .{});
257256 const dirg = try dir.openDir(".git", .{});
258257 const h = std.mem.trim(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n");
259258 const r = std.mem.trim(u8, try dirg.readFileAlloc(alloc, h[5..], max), "\n");