Skip to content

Commit

Permalink
add Fossil dep type
Browse files Browse the repository at this point in the history
  • Loading branch information
javierguerragiraldez authored and nektro committed Sep 15, 2021
1 parent 3f37f7d commit ee413e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
}
}

Expand Down
29 changes: 28 additions & 1 deletion src/util/dep_type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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/
// //
Expand Down Expand Up @@ -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});
}
}
}

Expand All @@ -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", .{});
},
}
}

Expand All @@ -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),
};
}
};
Expand All @@ -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 "";
}

0 comments on commit ee413e0

Please sign in to comment.