mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
fix new "var never mutated" error on Zig 0.12.0-dev.1663+6b1a823b2
Fixes these errors (introduced in https://github.com/ziglang/zig/pull/18017
and 6b1a823b2b ):
```
src/main.zig:290:13: error: local variable is never mutated
var line_ = line_fbs.getWritten();
^~~~~
src/main.zig:290:13: note: consider using 'const'
src/main.zig:450:17: error: local variable is never mutated
var path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable;
^~~~
src/main.zig:450:17: note: consider using 'const'
...
```
Will be included in future Zig 0.12, this fix is backward compatible:
ncdu still builds and runs fine on Zig 0.11.0.
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
This commit is contained in:
parent
115de253a8
commit
c83159f076
6 changed files with 19 additions and 19 deletions
|
|
@ -349,8 +349,8 @@ const info = struct {
|
|||
var links_idx: usize = 0;
|
||||
|
||||
fn lt(_: void, a: *model.Link, b: *model.Link) bool {
|
||||
var pa = a.path(false);
|
||||
var pb = b.path(false);
|
||||
const pa = a.path(false);
|
||||
const pb = b.path(false);
|
||||
defer main.allocator.free(pa);
|
||||
defer main.allocator.free(pb);
|
||||
return std.mem.lessThan(u8, pa, pb);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ const Pattern = struct {
|
|||
|
||||
fn parse(pat_: []const u8) *const Pattern {
|
||||
var pat = std.mem.trimLeft(u8, pat_, "/");
|
||||
var top = main.allocator.create(Pattern) catch unreachable;
|
||||
const top = main.allocator.create(Pattern) catch unreachable;
|
||||
var tail = top;
|
||||
tail.sub = null;
|
||||
while (std.mem.indexOfScalar(u8, pat, '/')) |idx| {
|
||||
|
|
@ -147,7 +147,7 @@ fn PatternList(comptime withsub: bool) type {
|
|||
fn append(self: *Self, pat: *const Pattern) void {
|
||||
std.debug.assert((pat.sub != null) == withsub);
|
||||
if (pat.isliteral) {
|
||||
var e = self.literals.getOrPut(main.allocator, pat) catch unreachable;
|
||||
const e = self.literals.getOrPut(main.allocator, pat) catch unreachable;
|
||||
if (!e.found_existing) {
|
||||
e.key_ptr.* = pat;
|
||||
e.value_ptr.* = if (withsub) .{} else {};
|
||||
|
|
@ -250,16 +250,16 @@ pub fn getPatterns(path_: []const u8) Patterns {
|
|||
var pat = root;
|
||||
defer pat.deinit();
|
||||
while (std.mem.indexOfScalar(u8, path, '/')) |idx| {
|
||||
var name = main.allocator.dupeZ(u8, path[0..idx]) catch unreachable;
|
||||
const name = main.allocator.dupeZ(u8, path[0..idx]) catch unreachable;
|
||||
defer main.allocator.free(name);
|
||||
path = path[idx+1..];
|
||||
|
||||
var sub = pat.enter(name);
|
||||
const sub = pat.enter(name);
|
||||
pat.deinit();
|
||||
pat = sub;
|
||||
}
|
||||
|
||||
var name = main.allocator.dupeZ(u8, path) catch unreachable;
|
||||
const name = main.allocator.dupeZ(u8, path) catch unreachable;
|
||||
defer main.allocator.free(name);
|
||||
return pat.enter(name);
|
||||
}
|
||||
|
|
|
|||
12
src/main.zig
12
src/main.zig
|
|
@ -287,7 +287,7 @@ fn tryReadArgsFile(path: [:0]const u8) void {
|
|||
error.EndOfStream => if (line_fbs.getPos() catch unreachable == 0) break,
|
||||
else => |e| ui.die("Error reading from {s}: {s}\nRun with --ignore-config to skip reading config files.\n", .{ path, ui.errorString(e) }),
|
||||
};
|
||||
var line_ = line_fbs.getWritten();
|
||||
const line_ = line_fbs.getWritten();
|
||||
|
||||
var line = std.mem.trim(u8, line_, &std.ascii.whitespace);
|
||||
if (line.len == 0 or line[0] == '#') continue;
|
||||
|
|
@ -447,11 +447,11 @@ pub fn main() void {
|
|||
tryReadArgsFile("/etc/ncdu.conf");
|
||||
|
||||
if (std.os.getenvZ("XDG_CONFIG_HOME")) |p| {
|
||||
var path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable;
|
||||
const path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable;
|
||||
defer allocator.free(path);
|
||||
tryReadArgsFile(path);
|
||||
} else if (std.os.getenvZ("HOME")) |p| {
|
||||
var path = std.fs.path.joinZ(allocator, &.{p, ".config", "ncdu", "config"}) catch unreachable;
|
||||
const path = std.fs.path.joinZ(allocator, &.{p, ".config", "ncdu", "config"}) catch unreachable;
|
||||
defer allocator.free(path);
|
||||
tryReadArgsFile(path);
|
||||
}
|
||||
|
|
@ -462,7 +462,7 @@ pub fn main() void {
|
|||
var export_file: ?[:0]const u8 = null;
|
||||
var quit_after_scan = false;
|
||||
{
|
||||
var arglist = std.process.argsAlloc(allocator) catch unreachable;
|
||||
const arglist = std.process.argsAlloc(allocator) catch unreachable;
|
||||
defer std.process.argsFree(allocator, arglist);
|
||||
var args = Args.init(arglist);
|
||||
_ = args.next(); // program name
|
||||
|
|
@ -506,7 +506,7 @@ pub fn main() void {
|
|||
event_delay_timer = std.time.Timer.start() catch unreachable;
|
||||
defer ui.deinit();
|
||||
|
||||
var out_file = if (export_file) |f| (
|
||||
const out_file = if (export_file) |f| (
|
||||
if (std.mem.eql(u8, f, "-")) stdout
|
||||
else std.fs.cwd().createFileZ(f, .{})
|
||||
catch |e| ui.die("Error opening export file: {s}.\n", .{ui.errorString(e)})
|
||||
|
|
@ -573,7 +573,7 @@ pub fn handleEvent(block: bool, force_draw: bool) void {
|
|||
|
||||
var firstblock = block;
|
||||
while (true) {
|
||||
var ch = ui.getch(firstblock);
|
||||
const ch = ui.getch(firstblock);
|
||||
if (ch == 0) return;
|
||||
if (ch == -1) return handleEvent(firstblock, true);
|
||||
switch (state) {
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ pub const devices = struct {
|
|||
var lookup = std.AutoHashMap(u64, DevId).init(main.allocator);
|
||||
|
||||
pub fn getId(dev: u64) DevId {
|
||||
var d = lookup.getOrPut(dev) catch unreachable;
|
||||
const d = lookup.getOrPut(dev) catch unreachable;
|
||||
if (!d.found_existing) {
|
||||
d.value_ptr.* = @as(DevId, @intCast(list.items.len));
|
||||
list.append(dev) catch unreachable;
|
||||
|
|
@ -400,7 +400,7 @@ pub const inodes = struct {
|
|||
nlink += 1;
|
||||
var parent: ?*Dir = it.parent;
|
||||
while (parent) |p| : (parent = p.parent) {
|
||||
var de = dirs.getOrPut(p) catch unreachable;
|
||||
const de = dirs.getOrPut(p) catch unreachable;
|
||||
if (de.found_existing) de.value_ptr.* += 1
|
||||
else de.value_ptr.* = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ const Context = struct {
|
|||
wr.print("{d}", .{std.time.timestamp()}) catch |e| writeErr(e);
|
||||
wr.writeByte('}') catch |e| writeErr(e);
|
||||
|
||||
var self = main.allocator.create(Self) catch unreachable;
|
||||
const self = main.allocator.create(Self) catch unreachable;
|
||||
self.* = .{ .wr = buf };
|
||||
return self;
|
||||
}
|
||||
|
|
@ -555,7 +555,7 @@ pub fn setupRefresh(parent: *model.Dir) void {
|
|||
// To be called after setupRefresh() (or from scanRoot())
|
||||
pub fn scan() void {
|
||||
defer active_context.deinit();
|
||||
var dir_ = std.fs.cwd().openDirZ(active_context.pathZ(), .{}, true) catch |e| {
|
||||
const dir_ = std.fs.cwd().openDirZ(active_context.pathZ(), .{}, true) catch |e| {
|
||||
active_context.last_error = main.allocator.dupeZ(u8, active_context.path.items) catch unreachable;
|
||||
active_context.fatal_error = e;
|
||||
while (main.state == .refresh or main.state == .scan)
|
||||
|
|
|
|||
|
|
@ -342,9 +342,9 @@ pub fn init() void {
|
|||
if (inited) return;
|
||||
clearScr();
|
||||
if (main.config.nc_tty) {
|
||||
var tty = c.fopen("/dev/tty", "r+");
|
||||
const tty = c.fopen("/dev/tty", "r+");
|
||||
if (tty == null) die("Error opening /dev/tty: {s}.\n", .{ c.strerror(@intFromEnum(std.c.getErrno(-1))) });
|
||||
var term = c.newterm(null, tty, tty);
|
||||
const term = c.newterm(null, tty, tty);
|
||||
if (term == null) die("Error initializing ncurses.\n", .{});
|
||||
_ = c.set_term(term);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue