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 {...@@ -75,10 +75,12 @@ pub const DepType = enum {
75 }75 }
7676
77 pub fn exact_version(self: DepType, mpath: []const u8) ![]const u8 {77 pub fn exact_version(self: DepType, mpath: []const u8) ![]const u8 {
78 var mdir = try std.fs.cwd().openDir(mpath, .{});
79 defer mdir.close();
78 return switch (self) {80 return switch (self) {
79 .local => "",81 .local => "",
80 .system_lib => "",82 .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]}),
82 .hg => "",84 .hg => "",
83 .http => "",85 .http => "",
84 };86 };
src/util/funcs.zig+1-2
...@@ -251,9 +251,8 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {...@@ -251,9 +251,8 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {
251}251}
252252
253/// Returns the result of running `git rev-parse HEAD`253/// 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 {
255 const max = std.math.maxInt(usize);255 const max = std.math.maxInt(usize);
256 const dir = try std.fs.cwd().openDir(path, .{});
257 const dirg = try dir.openDir(".git", .{});256 const dirg = try dir.openDir(".git", .{});
258 const h = std.mem.trim(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n");257 const h = std.mem.trim(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n");
259 const r = std.mem.trim(u8, try dirg.readFileAlloc(alloc, h[5..], max), "\n");258 const r = std.mem.trim(u8, try dirg.readFileAlloc(alloc, h[5..], max), "\n");