diff --git a/src/common.zig b/src/common.zig index 06b3337..9ec3718 100644 --- a/src/common.zig +++ b/src/common.zig @@ -205,6 +205,20 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! try std.fs.deleteFileAbsolute(file_path); return p; }, + .fossil => { + const dpath = if (d.version.len > 0) pv else p; + if (!try u.does_folder_exist(dpath)) { + try d.type.pull(options.alloc, d.path, dpath); + } else { + if (options.update) { + try d.type.update(options.alloc, dpath, d.path); + } + } + if (d.version.len > 0) { + u.assert((try u.run_cmd(options.alloc, dpath, &.{ "fossil", "checkout", d.version })) == 0, "can't fossil checkout version {s}", .{d.version}); + } + return dpath; + }, } } diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index 865b826..a72d5b3 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -14,6 +14,7 @@ pub const DepType = enum { git, // https://git-scm.com/ hg, // https://www.mercurial-scm.org/ http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol + fossil, // https://fossil-scm.org/ // zig fmt: on pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void { @@ -38,6 +39,10 @@ pub const DepType = enum { u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f}); } }, + .fossil => { + try std.fs.cwd().makePath(dpath); + u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "open", rpath })) == 0, "fossil open {s} failed", .{rpath}); + }, } } @@ -58,6 +63,10 @@ pub const DepType = enum { .http => { // }, + .fossil => { + 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", .{}); + }, } } @@ -71,6 +80,7 @@ pub const DepType = enum { .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}), .hg => "", .http => "", + .fossil => getFossilCheckout(alloc, mpath), }; } @@ -82,6 +92,7 @@ pub const DepType = enum { .git => false, .hg => false, .http => false, + .fossil => false, }; } @@ -92,6 +103,7 @@ pub const DepType = enum { git: Git, hg: void, http: void, + fossil: void, pub const Git = enum { branch, @@ -108,3 +120,19 @@ pub const DepType = enum { }; }; }; + +fn getFossilCheckout(alloc: std.mem.Allocator, mpath: []const u8) ![]const u8 { + const result = try u.run_cmd_raw(alloc, 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 alloc.dupe(u8, co); + } + } + + return ""; +}