Skip to content

Commit

Permalink
pass allocator
Browse files Browse the repository at this point in the history
No longer assume `gpa` global allocator.
  • Loading branch information
javierguerragiraldez committed Feb 23, 2022
1 parent b8b75cd commit 98875eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
.fossil => {
const dpath = if (d.version.len > 0) pv else p;
if (!try u.does_folder_exist(dpath)) {
try d.type.pull(d.path, dpath);
try d.type.pull(options.alloc, d.path, dpath);
} else {
if (options.update) {
try d.type.update(dpath, d.path);
try d.type.update(options.alloc, dpath, d.path);
}
}
if (d.version.len > 0) {
u.assert((try u.run_cmd(dpath, &.{ "fossil", "checkout", d.version })) == 0, "can't fossil checkout version {s}", .{ d.version });
u.assert((try u.run_cmd(options.alloc, dpath, &.{ "fossil", "checkout", d.version })) == 0, "can't fossil checkout version {s}", .{d.version});
}
return dpath;
},
Expand Down
22 changes: 10 additions & 12 deletions src/util/dep_type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub const DepType = enum {
},
.fossil => {
try std.fs.cwd().makePath(dpath);
u.assert((try u.run_cmd(dpath, &.{ "fossil", "open", rpath})) == 0, "fossil open {s} failed", .{rpath});
}
u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "open", rpath })) == 0, "fossil open {s} failed", .{rpath});
},
}
}

Expand All @@ -78,8 +78,8 @@ pub const DepType = enum {
//
},
.fossil => {
u.assert((try u.run_cmd(dpath, &.{ "fossil", "pull" })) == 0, "fossil pull failed", .{});
u.assert((try u.run_cmd(dpath, &.{ "fossil", "update" })) == 0, "fossil update failed", .{});
u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "pull" })) == 0, "fossil pull failed", .{});
u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "update" })) == 0, "fossil update failed", .{});
},
}
}
Expand All @@ -94,7 +94,7 @@ pub const DepType = enum {
.git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
.hg => "",
.http => "",
.fossil => getFossilCheckout(mpath),
.fossil => getFossilCheckout(alloc, mpath),
};
}

Expand All @@ -113,20 +113,18 @@ pub const DepType = enum {
};
};


fn getFossilCheckout(mpath: []const u8) ![]const u8 {
const result = try u.run_cmd_raw(mpath, &.{"fossil", "status"});
gpa.free(result.stderr);
defer gpa.free(result.stdout);
fn getFossilCheckout(alloc: std.mem.Allocator, mpath: []const u8) ![]const u8 {
const result = try u.run_cmd_raw(mpath, &.{ "fossil", "status" });
alloc.free(result.stderr);
defer alloc.free(result.stdout);

var iter = std.mem.tokenize(u8, result.stdout, " \n");
while (iter.next()) |tk| {
if (std.mem.eql(u8, tk, "checkout:")) {
const co = iter.next() orelse return "";
return try gpa.dupe(u8, co);
return try alloc.dupe(u8, co);
}
}

return "";
}

0 comments on commit 98875eb

Please sign in to comment.