Skip to content

Commit 8ea3899

Browse files
add Fossil dep type
1 parent 8a2eb27 commit 8ea3899

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/common.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![
194194
try std.fs.deleteFileAbsolute(file_path);
195195
return p;
196196
},
197+
.fossil => {
198+
const dpath = if (d.version.len > 0) pv else p;
199+
if (!try u.does_folder_exist(dpath)) {
200+
try d.type.pull(d.path, dpath);
201+
} else {
202+
if (options.update) {
203+
try d.type.update(dpath, d.path);
204+
}
205+
}
206+
if (d.version.len > 0) {
207+
u.assert((try u.run_cmd(dpath, &.{ "fossil", "checkout", d.version })) == 0, "can't fossil checkout version {s}", .{ d.version });
208+
}
209+
return dpath;
210+
},
197211
}
198212
}
199213

src/util/dep_type.zig

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub const DepType = enum {
1414
hg, // https://www.mercurial-scm.org/
1515
http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
1616
// svn, // https://subversion.apache.org/
17-
// fossil, // https://fossil-scm.org/
17+
fossil, // https://fossil-scm.org/
1818
// cvs, // https://nongnu.org/cvs/
1919
// darcs, // http://darcs.net/
2020
// //
@@ -53,6 +53,10 @@ pub const DepType = enum {
5353
u.assert((try u.run_cmd(dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});
5454
}
5555
},
56+
.fossil => {
57+
try std.fs.cwd().makePath(dpath);
58+
u.assert((try u.run_cmd(dpath, &.{ "fossil", "open", rpath})) == 0, "fossil open {s} failed", .{rpath});
59+
}
5660
}
5761
}
5862

@@ -73,6 +77,10 @@ pub const DepType = enum {
7377
.http => {
7478
//
7579
},
80+
.fossil => {
81+
u.assert((try u.run_cmd(dpath, &.{ "fossil", "pull" })) == 0, "fossil pull failed", .{});
82+
u.assert((try u.run_cmd(dpath, &.{ "fossil", "update" })) == 0, "fossil update failed", .{});
83+
},
7684
}
7785
}
7886

@@ -86,6 +94,7 @@ pub const DepType = enum {
8694
.git => try std.fmt.allocPrint(gpa, "commit-{s}", .{(try u.git_rev_HEAD(gpa, mdir))}),
8795
.hg => "",
8896
.http => "",
97+
.fossil => getFossilCheckout(mpath),
8998
};
9099
}
91100
};
@@ -103,3 +112,21 @@ pub const GitVersionType = enum {
103112
};
104113
}
105114
};
115+
116+
117+
fn getFossilCheckout(mpath: []const u8) ![]const u8 {
118+
const result = try u.run_cmd_raw(mpath, &.{"fossil", "status"});
119+
gpa.free(result.stderr);
120+
defer gpa.free(result.stdout);
121+
122+
var iter = std.mem.tokenize(u8, result.stdout, " \n");
123+
while (iter.next()) |tk| {
124+
if (std.mem.eql(u8, tk, "checkout:")) {
125+
const co = iter.next() orelse return "";
126+
return try gpa.dupe(u8, co);
127+
}
128+
}
129+
130+
return "";
131+
}
132+

0 commit comments

Comments
 (0)