style: adopt TigerStyle across src/; add docs/TIGER_STYLE.md

Wrap signatures and long expressions to the 100-column limit and make every
file zig fmt clean. Semantics-preserving throughout: ignoring whitespace and
the trailing commas that wrapping introduces, every file here is byte-identical
to its predecessor, and the one apparent exception is a warning string split
with `++`, which concatenates at comptime to the same bytes.

src/index.zig and src/commands.zig are reformatted in the commits that follow,
because their reformat is interleaved with in-flight changes to them and
separating the two would need the reformat re-derived rather than moved.
This commit is contained in:
2026-08-03 17:08:21 +03:00
parent d4c9b04f21
commit 86ae8fa8af
14 changed files with 1130 additions and 126 deletions

View File

@@ -227,7 +227,10 @@ pub const Log = struct {
while (true) {
var hdr: [block_header_len]u8 = undefined;
const n = self.file.readPositionalAll(self.io, &hdr, pos) catch |err| {
std.debug.print("multiforadb: log read error at {d}: {s}\n", .{ pos, @errorName(err) });
std.debug.print("multiforadb: log read error at {d}: {s}\n", .{
pos,
@errorName(err),
});
return error.InvalidLog;
};
if (n == 0) return; // clean end
@@ -262,7 +265,10 @@ pub const Log = struct {
codec_raw => try decomp.appendSlice(self.gpa, payload),
codec_lz4 => try lz4_decompress(self.gpa, payload, &decomp),
else => {
std.debug.print("multiforadb: unknown block codec {d} at {d}\n", .{ codec, pos });
std.debug.print("multiforadb: unknown block codec {d} at {d}\n", .{
codec,
pos,
});
return error.InvalidLog;
},
}
@@ -280,7 +286,13 @@ pub const Log = struct {
/// and deliver it. Returns the record's byte length. Any framing failure
/// here is interior corruption: a block was sealed only with complete
/// records, and its hash proved the stored bytes intact.
fn parse_record(self: *Log, bytes: []const u8, pos: u64, ctx: *anyopaque, callback: ReplayFn) !usize {
fn parse_record(
self: *Log,
bytes: []const u8,
pos: u64,
ctx: *anyopaque,
callback: ReplayFn,
) !usize {
if (bytes.len < 4) return error.InvalidLog;
const total: u32 = std.mem.readInt(u32, bytes[0..4], .little);
if (total < header_len) {
@@ -321,26 +333,57 @@ pub const Log = struct {
return total;
}
pub fn append_upsert(self: *Log, db: []const u8, coll: []const u8, doc: []const u8, seq: u64) !void {
pub fn append_upsert(
self: *Log,
db: []const u8,
coll: []const u8,
doc: []const u8,
seq: u64,
) !void {
try self.append(record_type_upsert, db, coll, doc, seq);
}
pub fn append_delete(self: *Log, db: []const u8, coll: []const u8, doc: []const u8, seq: u64) !void {
pub fn append_delete(
self: *Log,
db: []const u8,
coll: []const u8,
doc: []const u8,
seq: u64,
) !void {
try self.append(record_type_delete, db, coll, doc, seq);
}
/// The payload is the canonical index spec document ({v, key, name,
/// unique?, sparse?}); only apply_record interprets it.
pub fn append_index_create(self: *Log, db: []const u8, coll: []const u8, doc: []const u8, seq: u64) !void {
pub fn append_index_create(
self: *Log,
db: []const u8,
coll: []const u8,
doc: []const u8,
seq: u64,
) !void {
try self.append(record_type_index_create, db, coll, doc, seq);
}
/// The payload is {name: "..."}; only apply_record interprets it.
pub fn append_index_drop(self: *Log, db: []const u8, coll: []const u8, doc: []const u8, seq: u64) !void {
pub fn append_index_drop(
self: *Log,
db: []const u8,
coll: []const u8,
doc: []const u8,
seq: u64,
) !void {
try self.append(record_type_index_drop, db, coll, doc, seq);
}
fn append(self: *Log, rtype: u8, db: []const u8, coll: []const u8, doc: []const u8, seq: u64) !void {
fn append(
self: *Log,
rtype: u8,
db: []const u8,
coll: []const u8,
doc: []const u8,
seq: u64,
) !void {
if (std.mem.indexOfScalar(u8, db, 0) != null or std.mem.indexOfScalar(u8, coll, 0) != null) {
return error.NulInName;
}
@@ -547,7 +590,11 @@ fn emit_literals(dst: []u8, literals: []const u8) usize {
/// Decompress an LZ4 block into `out` (appended). The block hash has
/// already proven the input intact when this runs during replay, so
/// structural failures here mean a bug or a raw-codec mismatch.
fn lz4_decompress(gpa: std.mem.Allocator, src: []const u8, out: *std.ArrayListUnmanaged(u8)) error{ CorruptLz4, OutOfMemory }!void {
fn lz4_decompress(
gpa: std.mem.Allocator,
src: []const u8,
out: *std.ArrayListUnmanaged(u8),
) error{ CorruptLz4, OutOfMemory }!void {
var ip: usize = 0;
while (ip < src.len) {
const token = src[ip];