From 5157579ff7f9ae0cfc3c7629e953da05bce340fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Nov 2026 00:52:52 -0300 Subject: tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Db.zig | 68 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'src/Db.zig') diff --git a/src/Db.zig b/src/Db.zig index 73e6480a..f7966ee0 100644 --- a/src/Db.zig +++ b/src/Db.zig @@ -95,40 +95,6 @@ pub fn statePath(buf: []u8, dir_setting: []const u8) ?[]const u8 { return std.fmt.bufPrint(buf, "{s}/" ++ file_name, .{dir}) catch null; } -/// The database, opened (made, when its file is not there) at its first use -/// and again once the DumpDir names another: null when this session keeps -/// none, or it cannot be had now (the next use tries again). -fn opened(db: *Db, p: *Pardes) ?*Open { - switch (db.kind) { - .off => return null, - .disk => { - var buf: [4200]u8 = undefined; - const path = statePath(&buf, p.settings.dump_dir.get()) orelse return null; - if (db.open) |o| { - // The same file still: another session's compaction renames - // a new one over it, which this one then opens. - if (std.mem.eql(u8, o.where.disk.path, path) and !replaced(o)) return o; - // The DumpDir moved: its own file, read afresh. - db.deinit(); - db.seen = 0; - } - db.open = openDisk(p.recentGpa(), path) catch return null; - }, - .memory => if (db.open == null) { - const gpa = p.recentGpa(); - const o = gpa.create(Open) catch return null; - o.* = .{ .gpa = gpa, .buffer = .init(gpa), .where = undefined }; - o.where = .{ .memory = .{ .db = Memory.init(ioOf(), .{ .buffer = &o.buffer, .hash_id = hash_id }) catch { - o.buffer.deinit(); - gpa.destroy(o); - return null; - } } }; - db.open = o; - }, - } - return db.open; -} - /// The state file at `path`, its directory made: a new one is written under /// the file's lock (two sessions starting at once write one header), one a /// power loss tore is opened at its last whole commit (`mend`), and a file @@ -1140,6 +1106,40 @@ pub const Cache = struct { const testing = std.testing; +/// The database, opened (made, when its file is not there) at its first use +/// and again once the DumpDir names another: null when this session keeps +/// none, or it cannot be had now (the next use tries again). +fn opened(db: *Db, p: *Pardes) ?*Open { + switch (db.kind) { + .off => return null, + .disk => { + var buf: [4200]u8 = undefined; + const path = statePath(&buf, p.settings.dump_dir.get()) orelse return null; + if (db.open) |o| { + // The same file still: another session's compaction renames + // a new one over it, which this one then opens. + if (std.mem.eql(u8, o.where.disk.path, path) and !replaced(o)) return o; + // The DumpDir moved: its own file, read afresh. + db.deinit(); + db.seen = 0; + } + db.open = openDisk(p.recentGpa(), path) catch return null; + }, + .memory => if (db.open == null) { + const gpa = p.recentGpa(); + const o = gpa.create(Open) catch return null; + o.* = .{ .gpa = gpa, .buffer = .init(gpa), .where = undefined }; + o.where = .{ .memory = .{ .db = Memory.init(ioOf(), .{ .buffer = &o.buffer, .hash_id = hash_id }) catch { + o.buffer.deinit(); + gpa.destroy(o); + return null; + } } }; + db.open = o; + }, + } + return db.open; +} + /// A window keeping its state in `dir` (never the user's DumpDir). fn testWindow(dir: []const u8) !*Pardes { var config: [4200]u8 = undefined; -- cgit v1.3