Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2377c041d9 | |||
| 6b7a176a70 |
3 changed files with 32 additions and 14 deletions
5
XD.1
5
XD.1
|
|
@ -26,6 +26,7 @@ tab(;) allbox;
|
||||||
c;l.
|
c;l.
|
||||||
:;default
|
:;default
|
||||||
\;;in a git repo
|
\;;in a git repo
|
||||||
|
=;in a git repo during a bisect
|
||||||
8;in a git repo with stashed changes
|
8;in a git repo with stashed changes
|
||||||
X;in a git repo during a merge
|
X;in a git repo during a merge
|
||||||
O;in a git repo during a rebase
|
O;in a git repo during a rebase
|
||||||
|
|
@ -56,8 +57,8 @@ c;l.
|
||||||
returns the number that was passed in to allow the user to re-run the program
|
returns the number that was passed in to allow the user to re-run the program
|
||||||
and get the same results. If there's an internal error
|
and get the same results. If there's an internal error
|
||||||
.Nm
|
.Nm
|
||||||
returns 1. If you wish to find out more infomation about the error enable ERR
|
returns 1. If you wish to find out more infomation about the error pass in
|
||||||
in the config.mk.
|
-Derr at build time.
|
||||||
.Sh OPTIONS
|
.Sh OPTIONS
|
||||||
.Ss -v
|
.Ss -v
|
||||||
Print version information to stdout and exit.
|
Print version information to stdout and exit.
|
||||||
|
|
|
||||||
34
src/Git.zig
34
src/Git.zig
|
|
@ -10,7 +10,7 @@ const std = @import("std");
|
||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
|
|
||||||
repo: ?*c.git_repository,
|
repo: ?*c.git_repository,
|
||||||
git_path: []const u8,
|
git_path: [:0]const u8,
|
||||||
repo_path: []const u8,
|
repo_path: []const u8,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
repo_state: c_int,
|
repo_state: c_int,
|
||||||
|
|
@ -43,7 +43,7 @@ pub fn init(allocator: std.mem.Allocator) !?*Git {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.repo_state = undefined,
|
.repo_state = undefined,
|
||||||
.repo_path = undefined,
|
.repo_path = undefined,
|
||||||
.cache = .init(self.allocator, self.git_path),
|
.cache = .init(self.allocator, std.mem.span(self.git_path.ptr)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (c.git_repository_open(&self.repo, repo_root.?.ptr) != 0) {
|
if (c.git_repository_open(&self.repo, repo_root.?.ptr) != 0) {
|
||||||
|
|
@ -114,6 +114,20 @@ pub fn inRebase(self: *Git) bool {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inBisect(self: *Git) bool {
|
||||||
|
const s = perf.s();
|
||||||
|
defer perf.e(s, @src());
|
||||||
|
|
||||||
|
const path = std.fs.path.join(self.allocator, &[_][]const u8{
|
||||||
|
std.mem.span(self.git_path.ptr),
|
||||||
|
"BISECT_LOG",
|
||||||
|
}) catch return false;
|
||||||
|
defer self.allocator.free(path);
|
||||||
|
|
||||||
|
std.fs.cwd().access(path, .{ .mode = .read_only }) catch return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hasStaged(self: *Git) bool {
|
pub fn hasStaged(self: *Git) bool {
|
||||||
const s = perf.s();
|
const s = perf.s();
|
||||||
defer perf.e(s, @src());
|
defer perf.e(s, @src());
|
||||||
|
|
@ -238,7 +252,7 @@ pub fn headIsDetached(self: *Git) bool {
|
||||||
return c.git_repository_head_detached(self.repo) == 1;
|
return c.git_repository_head_detached(self.repo) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn findRepoRoot(allocator: std.mem.Allocator) !?[]u8 {
|
fn findRepoRoot(allocator: std.mem.Allocator) !?[:0]u8 {
|
||||||
const s = perf.s();
|
const s = perf.s();
|
||||||
defer perf.e(s, @src());
|
defer perf.e(s, @src());
|
||||||
|
|
||||||
|
|
@ -260,20 +274,18 @@ fn findRepoRoot(allocator: std.mem.Allocator) !?[]u8 {
|
||||||
};
|
};
|
||||||
|
|
||||||
return switch (stat.kind) {
|
return switch (stat.kind) {
|
||||||
.directory => try allocator.dupe(u8, try cur_path.realpathZ(
|
.directory => try allocator.dupeZ(u8, try cur_path.realpath(
|
||||||
".git",
|
".git",
|
||||||
&buf,
|
&buf,
|
||||||
)),
|
)),
|
||||||
.file => {
|
.file => {
|
||||||
@branchHint(.cold);
|
@branchHint(.cold);
|
||||||
const f = try cur_path.openFile(".git", .{ .mode = .read_only });
|
|
||||||
const file_reader = f.reader(&buf);
|
|
||||||
var reader = file_reader.interface;
|
|
||||||
const read = try reader.readSliceShort(&buf);
|
|
||||||
const prefix = "gitdir: ";
|
const prefix = "gitdir: ";
|
||||||
if (std.mem.startsWith(u8, &buf, prefix)) {
|
var file_buf: [std.fs.max_path_bytes + prefix.len]u8 = undefined;
|
||||||
buf[read - 1] = 0; // remove the newline
|
const read = try cur_path.readFile(".git", &file_buf);
|
||||||
return try allocator.dupe(u8, buf[prefix.len..]);
|
|
||||||
|
if (read.len > 0 and std.mem.eql(u8, file_buf[0..prefix.len], prefix)) {
|
||||||
|
return try allocator.dupeZ(u8, read[prefix.len..read.len - 1]);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,12 @@ pub fn main() u8 {
|
||||||
var git = if (config.git) try @import("Git.zig").init(allocator) orelse null;
|
var git = if (config.git) try @import("Git.zig").init(allocator) orelse null;
|
||||||
defer if (config.git and git != null) git.?.deinit();
|
defer if (config.git and git != null) git.?.deinit();
|
||||||
if (config.git and git != null) {
|
if (config.git and git != null) {
|
||||||
if (git.?.hasStashes()) {
|
if (git.?.inBisect()) {
|
||||||
|
face[@intFromEnum(FaceParts.eyes)] = .{
|
||||||
|
.symbol = '=',
|
||||||
|
.explanation = "The current git repo is bisecting.",
|
||||||
|
};
|
||||||
|
} else if (git.?.hasStashes()) {
|
||||||
face[@intFromEnum(FaceParts.eyes)] = .{
|
face[@intFromEnum(FaceParts.eyes)] = .{
|
||||||
.symbol = '8',
|
.symbol = '8',
|
||||||
.explanation = "The current git repo has stashed changes.",
|
.explanation = "The current git repo has stashed changes.",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue