From ee413e0b9672c1774b4af5b9122f29079dc98731 Mon Sep 17 00:00:00 2001 From: Javier Guerra Date: Wed, 1 Sep 2021 18:45:26 -0500 Subject: [PATCH] add Fossil dep type --- src/common.zig | 14 ++++++++++++++ src/util/dep_type.zig | 29 ++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/common.zig b/src/common.zig index 976bed3..81a9596 100644 --- a/src/common.zig +++ b/src/common.zig @@ -194,6 +194,20 @@ pub fn get_modpath(cachepath: []const u8, d: u.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(d.path, dpath); + } else { + if (options.update) { + try d.type.update(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 }); + } + return dpath; + }, } } diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index 435f589..14b9597 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -14,7 +14,7 @@ pub const DepType = enum { hg, // https://www.mercurial-scm.org/ http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol // svn, // https://subversion.apache.org/ - // fossil, // https://fossil-scm.org/ + fossil, // https://fossil-scm.org/ // cvs, // https://nongnu.org/cvs/ // darcs, // http://darcs.net/ // // @@ -53,6 +53,10 @@ pub const DepType = enum { u.assert((try u.run_cmd(dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f}); } }, + .fossil => { + try std.fs.cwd().makePath(dpath); + u.assert((try u.run_cmd(dpath, &.{ "fossil", "open", rpath})) == 0, "fossil open {s} failed", .{rpath}); + } } } @@ -73,6 +77,10 @@ pub const DepType = enum { .http => { // }, + .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", .{}); + }, } } @@ -86,6 +94,7 @@ pub const DepType = enum { .git => try std.fmt.allocPrint(gpa, "commit-{s}", .{(try u.git_rev_HEAD(gpa, mdir))}), .hg => "", .http => "", + .fossil => getFossilCheckout(mpath), }; } }; @@ -103,3 +112,21 @@ pub const GitVersionType = 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); + + 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 ""; +} +