╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Attachment.zig ───────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
147 io.random(&id_bytes); 148 const event_id = std.fmt.bytesToHex(id_bytes, .lower); 149 try evt.consume(host, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{.{ 150 .id = event_id, 151 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 152 .author = author, 153 .tree_entries = &.{.{ .blob = blob }}, 154 .event = .{ .attach = .{ .parent_id = parent_id.* } }, 155 }}); 156 return event_id; 157 } 158 159 // read an attachment by event id, or null if the id isn't a known attachment. 160 // field byte slices are allocated in `arena`. 161 pub fn readById( 162 comptime DB: type, 163 comptime hash_kind: hash.HashKind, 164 haxy_moment: DB.HashMap(.read_only), 165 arena: *std.heap.ArenaAllocator, 166 attachment_id: []const u8, 167 ) !?Record { 168 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 169 const records = try DB.HashMap(.read_only).init(records_cursor); 170 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, attachment_id)) orelse return null; 171 const record_map = try DB.HashMap(.read_only).init(record_cursor); 172 return try evt.read(Record, DB, hash_kind, arena, record_map); 173 } 174