Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pijul support #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/zig.mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The available `type`s are:
- `git`
- `hg`
- `http`
- `pijul`

For the full details on `Dep` types, you can check out the source where the enum is defined: https://github.com/nektro/zigmod/blob/master/src/util/dep_type.zig.

Expand All @@ -107,6 +108,8 @@ Version types available to each Dep type:
- `blake3`
- `sha256`
- `sha512`
- `pijul`
- `channel`

#### Dep `only_os`
- Type: `comma-split string[]`
Expand Down
39 changes: 39 additions & 0 deletions src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,45 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
try std.fs.deleteFileAbsolute(file_path);
return p;
},
.pijul => {
if (d.version.len > 0) {
const vers = u.parse_split(zigmod.DepType.Version.Pijul, "-").do(d.version) catch |e| switch (e) {
error.IterEmpty => unreachable,
error.NoMemberFound => {
const vtype = d.version[0..std.mem.indexOf(u8, d.version, "-").?];
u.fail("pijul: version type '{s}' is invalid.", .{vtype});
},
};
// this version is already pulled
if (try u.does_folder_exist(pv)) {
if (vers.id == .channel) {
if (options.update) {
// This does not work with pijul, have to use explicit channel name
// try d.type.update(options.alloc, pv, d.path);
if ((try u.run_cmd(options.alloc, pv, &.{ "pijul", "pull", "--all", "--from-channel", vers.string })) > 0) {
u.fail("pijul pull --from-channel {s}: did not succeed", .{vers.string});
}
}
}
return pv;
}
// version has not pulled yet
if ((try u.run_cmd(options.alloc, null, &.{ "pijul", "clone", "--channel", vers.string, d.path, pv })) > 0) {
u.fail("pijul clone --channel: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
}
return pv;
}

// no version string
if (!try u.does_folder_exist(p)) {
try d.type.pull(options.alloc, d.path, p);
} else {
if (options.update) {
try d.type.update(options.alloc, p, d.path);
}
}
return p;
},
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/util/dep_type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ pub const DepType = enum {
git, // https://git-scm.com/
hg, // https://www.mercurial-scm.org/
http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
pijul, // https://pijul.org/
// svn, // https://subversion.apache.org/
// fossil, // https://fossil-scm.org/
// cvs, // https://nongnu.org/cvs/
// darcs, // http://darcs.net/
// //
// bazaar, // https://bazaar.canonical.com/en/
// //
// ftp, // https://en.wikipedia.org/wiki/File_Transfer_Protocol
// ssh, // https://www.ssh.com/ssh/
// onion, // https://www.torproject.org/
// i2p, // https://geti2p.net/en/
// torrent, // https://en.wikipedia.org/wiki/BitTorrent
// magnet, // https://en.wikipedia.org/wiki/BitTorrent
// dat, // https://www.datprotocol.com/
// ipfs, // https://www.ipfs.com/
// hypercore, // https://hypercore-protocol.org/

// zig fmt: on
pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {
Expand All @@ -38,6 +55,9 @@ pub const DepType = enum {
u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});
}
},
.pijul => {
u.assert((try u.run_cmd(alloc, null, &.{ "pijul", "clone", rpath, dpath })) == 0, "pijul clone {s} {s} failed", .{ rpath, dpath });
},
}
}

Expand All @@ -58,6 +78,9 @@ pub const DepType = enum {
.http => {
//
},
.pijul => {
u.assert((try u.run_cmd(alloc, dpath, &.{ "pijul", "pull" })) == 0, "pijul pull failed", .{});
},
}
}

Expand All @@ -71,6 +94,7 @@ pub const DepType = enum {
.git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
.hg => "",
.http => "",
.pijul => "",
};
}

Expand All @@ -82,6 +106,7 @@ pub const DepType = enum {
.git => false,
.hg => false,
.http => false,
.pijul => false,
};
}

Expand All @@ -92,6 +117,7 @@ pub const DepType = enum {
git: Git,
hg: void,
http: void,
pijul: Pijul,

pub const Git = enum {
branch,
Expand All @@ -106,5 +132,8 @@ pub const DepType = enum {
};
}
};
pub const Pijul = enum {
channel,
};
};
};