╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │68 } │ │69 │ │70 // a repo's path, inside its owner's dir │ │71 -pub fn repoPath(allocator: std.mem.Allocator, users_dir: []const u8, owner_id: []const u8, repo_id: []const u8) ![]u8 { │ │72 - return try std.Io.Dir.path.join(allocator, &.{ users_dir, &std.fmt.bytesToHex(owner_id[0..event_id_size].*, .lower), "repos", &std.fmt.bytesToHex(repo_id[0..event_id_size].*, .lower) });│ │71 +pub fn repoPath(allocator: std.mem.Allocator, users_dir: []const u8, owner_id: *const [event_id_size]u8, repo_id: *const [event_id_size]u8) ![]u8 { │ │72 + return try std.Io.Dir.path.join(allocator, &.{ users_dir, &std.fmt.bytesToHex(owner_id.*, .lower), "repos", &std.fmt.bytesToHex(repo_id.*, .lower) }); │ │73 } │ │74 │ │75 // the ids a repo path names, or null for a path `repoPath` didn't build │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2145 .id = std.fmt.bytesToHex(Grant.idOf(repo_id, user_id), .lower), │ │2146 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), │ │2147 .author = author, │ │2148 - .event = .{ .grant = .{ .target_id = repo_id, .user_id = user_id, .role = role } }, │ │2148 + .event = .{ .grant = .{ .target_id = std.fmt.bytesToHex(repo_id.*, .lower), .user_id = std.fmt.bytesToHex(user_id.*, .lower), .role = role } },│ │2149 }}); │ │2150 } │ │2151 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────╮ │2278 .timestamp = timestamp, │ │2279 .author = owner, │ │2280 .event = .{ .repo = .{ │ │2281 - .user_id = owner_id, │ │2281 + .user_id = std.fmt.bytesToHex(owner_id.*, .lower),│ │2282 .name = name, │ │2283 .description = description, │ │2284 .read_access = read_access, │ ╰────────────────────────────────────────────────────────────────────╯ ╭ changed ─────────╮ │src/event/Fork.zig│ ╰──────────────────╯ ╭──────────────────────────────────────────────────────────────────────────╮ │ 3 const xit = @import("xit"); │ │ 4 const hash = xit.hash; │ │ 5 │ │ 6 -repo_id: []const u8, │ │ 6 +repo_id: [evt.event_id_size * 2]u8, │ │ 7 // the target repo's owner, whose user repo holds the target │ │ 8 -repo_user_id: []const u8, │ │ 8 +repo_user_id: [evt.event_id_size * 2]u8, │ │ 9 stage: Stage = .draft, │ │10 │ │11 // what the db stores: the event's data plus the commit-derived fields│ ╰──────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────╮ │30 pub const repo_to_draft_id_set_key = "repo->draft-id-set"; │ │31 │ │32 fn validate(record: Record) !void { │ │33 - if (record.event.repo_id.len != evt.event_id_size) return error.InvalidRepoId; │ │34 - if (record.event.repo_user_id.len != evt.event_id_size) return error.InvalidUserId;│ │33 + _ = try evt.parseEventId(&record.event.repo_id); │ │34 + _ = try evt.parseEventId(&record.event.repo_user_id); │ │35 } │ │36 │ │37 pub fn consume( │ ╰───────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │59 if (!record.removed) try validate(record); │ │60 │ │61 if (existing_maybe) |existing| { │ │62 - if (!std.mem.eql(u8, existing.event.repo_id, record.event.repo_id) or │ │63 - !std.mem.eql(u8, existing.event.repo_user_id, record.event.repo_user_id)) return error.ForkChanged; │ │62 + if (!std.mem.eql(u8, &existing.event.repo_id, &record.event.repo_id) or │ │63 + !std.mem.eql(u8, &existing.event.repo_user_id, &record.event.repo_user_id)) return error.ForkChanged; │ │64 if (existing.event.stage == .publish and record.event.stage != .publish) return error.ForkAlreadyPublished;│ │65 record.created_order = existing.created_order; │ │66 if (!existing.removed) { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │67 const order_key = evt.orderKeyDesc(existing.created_order, event_id); │ │68 _ = try active.remove(&order_key); │ │69 if (existing.event.stage == .draft) { │ │70 - try removeFromParentSet(DB, hash_kind, drafts, existing.event.repo_id, &order_key); │ │70 + try removeFromParentSet(DB, hash_kind, drafts, &try evt.parseEventId(&existing.event.repo_id), &order_key);│ │71 } │ │72 } │ │73 } │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │85 if (!record.removed) { │ │86 try active.put(&order_key); │ │87 if (record.event.stage == .draft) { │ │88 - const by_repo = try DB.SortedSet(.read_write).init(try drafts.putCursor(hash.hashInt(hash_kind, record.event.repo_id)));│ │88 + const repo_id = try evt.parseEventId(&record.event.repo_id); │ │89 + const by_repo = try DB.SortedSet(.read_write).init(try drafts.putCursor(hash.hashInt(hash_kind, &repo_id))); │ │90 try by_repo.put(&order_key); │ │91 } │ │92 } │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────╮ │ 96 comptime DB: type, │ │ 97 comptime hash_kind: hash.HashKind, │ │ 98 index: DB.HashMap(.read_write), │ │ 98 - parent_id: []const u8, │ │ 99 + parent_id: *const [evt.event_id_size]u8, │ │100 order_key: *const [@sizeOf(u64) + evt.event_id_size]u8, │ │101 ) !void { │ │102 const cursor = try index.putCursor(hash.hashInt(hash_kind, parent_id));│ ╰────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ──────────╮ │src/event/Grant.zig│ ╰───────────────────╯ ╭──────────────────────────────────────────────────────────────────────────╮ │ 4 const hash = xit.hash; │ │ 5 │ │ 6 // what the grant gives access to, held in the same user repo │ │ 7 -target_id: []const u8, │ │ 7 +target_id: [evt.event_id_size * 2]u8, │ │ 8 // who it gives access to │ │ 9 -user_id: []const u8, │ │ 9 +user_id: [evt.event_id_size * 2]u8, │ │10 role: evt.Repo.Role, │ │11 │ │12 // what the db stores: the event's data plus the commit-derived fields│ ╰──────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯