aboutsummaryrefslogtreecommitdiff
path: root/src/git.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.zig')
-rw-r--r--src/git.zig54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/git.zig b/src/git.zig
index 82e19b0..fc0d81b 100644
--- a/src/git.zig
+++ b/src/git.zig
@@ -19,14 +19,14 @@ pub const Commit = struct {
const s = std.mem.trim(u8, version_str, " \t");
if (s.len == 0) return .init_empty();
- const pos = std.mem.indexOfScalar(u8, s, '@') orelse return error.invalid_commit;
+ const pos = std.mem.findScalar(u8, s, '@') orelse return error.invalid_commit;
return .{
.hash = s[0..pos],
.timestamp = std.fmt.parseInt(u64, s[pos + 1 ..], 10) catch return error.invalid_commit,
};
}
- pub fn format(self: Commit, w: *std.io.Writer) std.io.Writer.Error!void {
+ pub fn format(self: Commit, w: *std.Io.Writer) std.Io.Writer.Error!void {
if (self.hash.len > 0) {
try w.print("{s}@{d}", .{ self.hash, self.timestamp });
}
@@ -38,8 +38,8 @@ pub const Repo = struct {
url: []const u8,
branch: []const u8,
- pub fn clone(self: Repo, env: Env) !void {
- const dir = try fs.dir_info(self.path);
+ pub fn clone(self: Repo, env: *const Env) !void {
+ const dir = try fs.dir_info(&self.path);
if (!dir.exists or dir.empty) {
var branch_buf: [std.fs.max_name_bytes]u8 = undefined;
const branch_param = branch_buf[0 .. 9 + self.branch.len];
@@ -50,58 +50,58 @@ pub const Repo = struct {
.argv = &.{ "git", "clone", "--quiet", "--depth=1", branch_param, self.url, self.path.name() },
});
switch (res) {
- .success => |out| env.dealloc(out),
+ .success => |out| if (out) |o| env.dealloc(o),
.failure => |out| {
env.err("failed to clone {s}\n", .{self.url});
- fatal("{s}", .{out});
+ fatal("{s}", .{out orelse ""});
},
}
}
}
- pub fn reset(self: Repo, env: Env) void {
+ pub fn reset(self: Repo, env: *const Env) void {
var res = shell.exec(.{
.env = env,
.argv = &.{ "git", "reset", "--hard" },
- .cwd = self.path,
+ .cwd = &self.path,
});
switch (res) {
- .success => |out| env.dealloc(out),
+ .success => |out| if (out) |o| env.dealloc(o),
.failure => |out| {
env.err("failed to reset repository: {s}\n", .{self.path.name()});
- fatal("{s}", .{out});
+ fatal("{s}", .{out orelse ""});
},
}
res = shell.exec(.{
.env = env,
.argv = &.{ "git", "clean", "-fdx" },
- .cwd = self.path,
+ .cwd = &self.path,
});
switch (res) {
- .success => |out| env.dealloc(out),
+ .success => |out| if (out) |o| env.dealloc(o),
.failure => |out| {
env.err("failed to clean repository: {s}\n", .{self.path.name()});
- fatal("{s}", .{out});
+ fatal("{s}", .{out orelse ""});
},
}
}
- pub fn update(self: Repo, env: Env) !Commit {
- const dir = try fs.dir_info(self.path);
+ pub fn update(self: Repo, env: *const Env) !Commit {
+ const dir = try fs.dir_info(&self.path);
if (!dir.exists or dir.empty) {
try self.clone(env);
} else {
var res = shell.exec(.{
.env = env,
.argv = &.{ "git", "fetch", "--quiet", "--depth=1", "origin", self.branch },
- .cwd = self.path,
+ .cwd = &self.path,
});
switch (res) {
- .success => |out| env.dealloc(out),
+ .success => |out| if (out) |o| env.dealloc(o),
.failure => |out| {
env.err("failed to fetch branch {s}: {s}\n", .{ self.branch, self.url });
- fatal("{s}", .{out});
+ fatal("{s}", .{out orelse ""});
},
}
@@ -109,20 +109,20 @@ pub const Repo = struct {
res = shell.exec(.{
.env = env,
.argv = &.{ "git", "reset", "--hard", branch_spec.name() },
- .cwd = self.path,
+ .cwd = &self.path,
});
switch (res) {
- .success => |out| env.dealloc(out),
+ .success => |out| if (out) |o| env.dealloc(o),
.failure => |out| {
env.err("failed to reset branch {s}: {s}\n", .{ self.branch, self.path.name() });
- fatal("{s}", .{out});
+ fatal("{s}", .{out orelse ""});
},
}
}
// We leak `out` intentionally here.
- const out = self.must_run(env, &.{ "git", "show", "--no-patch", "--format=format:%H %at", self.branch });
- const space = std.mem.indexOfScalar(u8, out, ' ') orelse {
+ const out = self.must_run(env, &.{ "git", "show", "--no-patch", "--format=format:%H %at", self.branch }).?;
+ const space = std.mem.findScalar(u8, out, ' ') orelse {
fatal("unexpected output for 'git show'", .{});
};
return .{
@@ -141,17 +141,17 @@ pub const Repo = struct {
};
}
- fn must_run(self: Repo, env: Env, argv: []const []const u8) []const u8 {
+ fn must_run(self: Repo, env: *const Env, argv: []const []const u8) ?[]const u8 {
const res = shell.exec(.{
.env = env,
.argv = argv,
- .cwd = self.path,
+ .cwd = &self.path,
});
switch (res) {
.success => |out| return out,
.failure => |out| {
- var errmsg = out;
- if (std.mem.indexOfScalar(u8, errmsg, '\n')) |eol| {
+ var errmsg = out orelse "";
+ if (std.mem.findScalar(u8, errmsg, '\n')) |eol| {
errmsg = errmsg[0..eol];
if (errmsg.len > 0 and errmsg[errmsg.len - 1] == '\r') {
errmsg = errmsg[0 .. errmsg.len - 1];