╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1037 switch (comptime T.merge_policy) { 1038 .field_conflicts => { 1039 if (try parent_moment.getCursor(hash.hashInt(hash_kind, T.conflicts_key))) |cursor| { 1040 parent_conflicts = try DB.SortedMap(.read_only).init(cursor); 1041 } 1042 if (try baseline_moment.getCursor(hash.hashInt(hash_kind, T.conflicts_key))) |cursor| { 1043 baseline_conflicts = try DB.SortedMap(.read_only).init(cursor); 1044 } 1045 if (try parent_moment.getCursor(hash.hashInt(hash_kind, T.id_to_field_to_oid_key))) |cursor| { 1046 parent_id_to_field_to_oid = try DB.HashMap(.read_only).init(cursor); 1047 } 1048 }, 1049 .target_wins => {}, 1050 } 1051 1052 var arena = std.heap.ArenaAllocator.init(allocator); 1053 defer arena.deinit(); 1054 1055 var iter = try parent_set.iteratorFromIndex(0); 1056 while (try iter.next()) |kv_pair_cursor| { 1057 const event_id = try readOrderKeyId(DB, kv_pair_cursor); 1058 const record_key = hash.hashInt(hash_kind, &event_id); 1059 1060 _ = arena.reset(.retain_capacity); 1061 1062 const parent_record_cursor = try parent_records.getCursor(record_key) orelse continue; 1063 const parent_slot = parent_record_cursor.slot(); 1064 const baseline_slot = if (baseline_records) |map| try map.getSlot(record_key) else null; 1065 1066 // the parent left this record alone 1067 if (baseline_slot) |slot| { 1068 if (slot.eql(parent_slot)) continue; 1069 } 1070 1071 const parent_record = try read(T.Record, DB, hash_kind, &arena, try DB.HashMap(.read_only).init(parent_record_cursor)); 1072 1073 // re-derived every iteration, since `consume` writes through its own 1074 // handles 1075 const target_records_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, T.record_map_key)); 1076 const target_records = try DB.HashMap(.read_write).init(target_records_cursor); 1077 1078 // a record the target doesn't have arrives wholesale from the parent 1079 var outcome: [std.meta.fields(T).len]FieldMerge = @splat(.parent); 1080 var merged = parent_record; 1081 1082 if (try target_records.getCursor(record_key)) |target_record_cursor| { 1083 // both sides share the change 1084 if (target_record_cursor.slot().eql(parent_slot)) continue; 1085 1086 const target_record = try read(T.Record, DB, hash_kind, &arena, try DB.HashMap(.read_only).init(target_record_cursor)); 1087 1088 var baseline_record: ?T.Record = null; 1089 if (baseline_records) |map| { 1090 if (try map.getCursor(record_key)) |baseline_record_cursor| { 1091 baseline_record = try read(T.Record, DB, hash_kind, &arena, try DB.HashMap(.read_only).init(baseline_record_cursor)); 1092 } 1093 } 1094 1095 switch (comptime T.merge_policy) { 1096 .field_conflicts => { 1097 outcome = @splat(.kept); 1098 merged = target_record; 1099 merged.event = mergeFields(T, if (baseline_record) |baseline| baseline.event else null, target_record.event, parent_record.event, &outcome); 1100 1101 // merge the removed state separately from serialized fields. removal 1102 // carries over an unchanged record, while an edit or restoration 1103 // keeps it active. 1104 merged.removed = if (target_record.removed == parent_record.removed) 1105 target_record.removed 1106 else if (baseline_record) |baseline| blk: { 1107 const active = if (!target_record.removed) target_record else parent_record; 1108 if (active.removed != baseline.removed) break :blk false; 1109 if (!fieldsEqual(T, active.event, baseline.event)) break :blk false; 1110 break :blk true; 1111 } else false; 1112 }, 1113 .target_wins => { 1114 // an uncontested parent change carries over. if both sides 1115 // changed the record, the target wins as a whole, except that 1116 // an edit or restoration wins over a removal. 1117 const target_changed = if (baseline_slot) |slot| 1118 !target_record_cursor.slot().eql(slot) 1119 else 1120 true; 1121 merged = if (!target_changed) 1122 parent_record 1123 else if (target_record.removed != parent_record.removed) 1124 if (target_record.removed) parent_record else target_record 1125 else 1126 target_record; 1127 }, 1128 } 1129 } 1130 1131 // the index is unique, so a key the target gave to a different record 1132 // leaves this one out rather than stranding that one behind a name it 1133 // no longer owns 1134 if (!merged.removed and @hasDecl(T, "name_index_key")) { 1135 const index_key = try merged.indexKey(arena.allocator()); 1136 const name_index_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, T.name_index_key)); 1137 const name_index = try DB.HashMap(.read_write).init(name_index_cursor); 1138 if (try name_index.getCursor(hash.hashInt(hash_kind, index_key))) |owner_cursor| { 1139 var owner_id: [event_id_size]u8 = undefined; 1140 _ = try owner_cursor.readBytes(&owner_id); 1141 if (!std.mem.eql(u8, &owner_id, &event_id)) continue; 1142 } 1143 } 1144 1145 // `consume` sets no oids, since each field's winner may come from 1146 // a different side 1147 try T.consume(DB, hash_kind, haxy_moment, &event_id, merged, &arena, null); 1148 1149 switch (comptime T.merge_policy) { 1150 .field_conflicts => {}, 1151 .target_wins => continue, 1152 } 1153 1154 // removed records do not carry field conflicts 1155 if (merged.removed) continue; 1156 1157 const conflicts_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, T.conflicts_key)); 1158 const conflicts = try DB.SortedMap(.read_write).init(conflicts_cursor); 1159 const id_to_field_to_oid_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, T.id_to_field_to_oid_key)); 1160 const id_to_field_to_oid = try DB.HashMap(.read_write).init(id_to_field_to_oid_cursor); 1161 const merged_key = orderKeyDesc(merged.created_ts, &event_id); 1162 1163 var parent_field_oids: ?DB.SortedMap(.read_only) = null; 1164 if (parent_id_to_field_to_oid) |map| { 1165 if (try map.getCursor(record_key)) |field_oids_cursor| { 1166 parent_field_oids = try DB.SortedMap(.read_only).init(field_oids_cursor); 1167 } 1168 } 1169 // created only once a field actually comes from the parent 1170 var field_oids: ?DB.SortedMap(.read_write) = null; 1171 1172 // the fields both sides changed differently, space separated 1173 var conflicted_fields: [conflictedFieldsMaxLen(T)]u8 = undefined; 1174 var conflicted_len: usize = 0; 1175 1176 inline for (std.meta.fields(T), 0..) |field, i| { 1177 switch (outcome[i]) { 1178 // the target's value stands, so its oid does too 1179 .kept => {}, 1180 // the parent set this value, so its commit takes the field. a 1181 // parent with no oid took its own value from a merge, leaving 1182 // the field unattributed rather than crediting the target's 1183 // commit for a value it no longer holds. 1184 .parent => { 1185 if (field_oids == null) { 1186 field_oids = try DB.SortedMap(.read_write).init(try id_to_field_to_oid.putCursor(record_key)); 1187 } 1188 const map = field_oids orelse unreachable; 1189 const parent_oid = if (parent_field_oids) |parent_map| try parent_map.getCursor(field.name) else null; 1190 if (parent_oid) |oid_cursor| { 1191 try map.put(field.name, .{ .slot = oid_cursor.slot() }); 1192 } else { 1193 _ = try map.remove(field.name); 1194 } 1195 }, 1196 .conflicted => { 1197 if (conflicted_len > 0) { 1198 conflicted_fields[conflicted_len] = ' '; 1199 conflicted_len += 1; 1200 } 1201 @memcpy(conflicted_fields[conflicted_len..][0..field.name.len], field.name); 1202 conflicted_len += field.name.len; 1203 }, 1204 } 1205 } 1206 1207 if (conflicted_len > 0) { 1208 // each side's whole record is stored by reference, so the view can 1209 // show any of them or take theirs wholesale 1210 _ = try conflicts.remove(&merged_key); 1211 const conflict = try DB.HashMap(.read_write).init(try conflicts.putCursor(&merged_key)); 1212 try conflict.put(hash.hashInt(hash_kind, conflicted_fields_key), .{ .bytes = conflicted_fields[0..conflicted_len] }); 1213 try conflict.put(hash.hashInt(hash_kind, base_record_key), .{ .slot = baseline_slot }); 1214 try conflict.put(hash.hashInt(hash_kind, their_record_key), .{ .slot = parent_slot }); 1215 if (parent_field_oids) |map| { 1216 try conflict.put(hash.hashInt(hash_kind, their_field_to_oid_key), .{ .slot = map.slot() }); 1217 } 1218 continue; 1219 } 1220 1221 // created_ts never changes, so the parent keys this record's conflict 1222 // identically, and it carries over when the target has none, unless the 1223 // parent's entry is unchanged from the baseline, meaning the target 1224 // inherited it too and resolving it removed it here. 1225 if (parent_conflicts) |map| { 1226 if (null == try conflicts.getCursor(&merged_key)) { 1227 if (try map.getSlot(&merged_key)) |conflict_slot| { 1228 const baseline_conflict_slot = if (baseline_conflicts) |baseline_map| try baseline_map.getSlot(&merged_key) else null; 1229 const resolved = if (baseline_conflict_slot) |slot| slot.eql(conflict_slot) else false; 1230 if (!resolved) try conflicts.put(&merged_key, .{ .slot = conflict_slot }); 1231 } 1232 } 1233 } 1234 } 1235 } 1236 1237 pub fn currentMoment( 1238 comptime repo_opts: rp.RepoOpts(.xit), 1239 repo: *rp.Repo(.xit, repo_opts), 1240 ) !rp.Repo(.xit, repo_opts).DB.HashMap(.read_only) { 1241 return currentMomentFromDb(repo_opts.hash, &repo.core.db); 1242 } 1243 1244 // the oid of the last event commit consumed into `db`, or null before any 1245 // consume completed 1246 fn lastConsumedOid( 1247 comptime hash_kind: hash.HashKind, 1248 db: *EventDB(hash_kind), 1249 ) !?[hash.byteLen(hash_kind)]u8 { 1250 const DB = EventDB(hash_kind); 1251 const history = try DB.ArrayList(.read_only).init(db.rootCursor().readOnly()); 1252 const moment_cursor = try history.getCursor(-1) orelse return null; 1253 const moment = try DB.HashMap(.read_only).init(moment_cursor); 1254 const last_object_id_cursor = try moment.getCursor(hash.hashInt(hash_kind, "haxy-last-object-id")) orelse return null; 1255 var last_object_id: [hash.byteLen(hash_kind)]u8 = undefined; 1256 _ = try last_object_id_cursor.readBytes(&last_object_id); 1257 return last_object_id; 1258 } 1259 1260 pub fn currentMomentFromDb( 1261 comptime hash_kind: hash.HashKind, 1262 db: *EventDB(hash_kind), 1263 ) !EventDB(hash_kind).HashMap(.read_only) { 1264 const DB = EventDB(hash_kind); 1265 const last_object_id = (try lastConsumedOid(hash_kind, db)) orelse return error.NotFound; 1266 const history = try DB.ArrayList(.read_only).init(db.rootCursor().readOnly()); 1267 const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; 1268 const moment = try DB.HashMap(.read_only).init(moment_cursor); 1269 const haxy_cursor = try moment.getCursor(hash.hashInt(hash_kind, "haxy")) orelse return error.NotFound; 1270 const haxy = try DB.ArrayList(.read_only).init(haxy_cursor); 1271 const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; 1272 const haxy_moments = try DB.HashMap(.read_only).init(haxy_moments_cursor); 1273 const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(hash_kind, &last_object_id)) orelse return error.NotFound; 1274 return try DB.HashMap(.read_only).init(haxy_moment_cursor); 1275 } 1276 1277 // build the key for SortedSets sorted by timestamp. the big-endian timestamp 1278 // makes byte order match creation order; the event id breaks ties and keeps 1279 // keys unique within the same timestamp. 1280 pub fn orderKey(timestamp: u64, event_id: *const [event_id_size]u8) [@sizeOf(u64) + event_id_size]u8 { 1281 var key: [@sizeOf(u64) + event_id_size]u8 = undefined; 1282 std.mem.writeInt(u64, key[0..@sizeOf(u64)], timestamp, .big); 1283 @memcpy(key[@sizeOf(u64)..], event_id); 1284 return key; 1285 } 1286 1287 pub fn orderKeyDesc(timestamp: u64, event_id: *const [event_id_size]u8) [@sizeOf(u64) + event_id_size]u8 { 1288 return orderKey(std.math.maxInt(u64) - timestamp, event_id); 1289 } 1290 1291 // add or refresh one entry in the global logical-event index. updates and 1292 // removed records preserve created_ts, so the key never moves. 1293 pub fn indexEvent( 1294 comptime DB: type, 1295 comptime hash_kind: hash.HashKind, 1296 haxy_moment: DB.HashMap(.read_write), 1297 event_id: *const [event_id_size]u8, 1298 kind: EventKind, 1299 created_ts: u64, 1300 removed: bool, 1301 ) !void { 1302 const kind_map_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, event_index_key)); 1303 const kind_map = try DB.HashMap(.read_write).init(kind_map_cursor); 1304 try kind_map.put(hash.hashInt(hash_kind, event_id), .{ .bytes = @tagName(kind) }); 1305 1306 const active_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, active_event_id_set_key)); 1307 const active = try DB.SortedSet(.read_write).init(active_cursor); 1308 const removed_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, removed_event_id_set_key)); 1309 const removed_set = try DB.SortedSet(.read_write).init(removed_cursor); 1310 const order_key = orderKeyDesc(created_ts, event_id); 1311 if (removed) { 1312 _ = try active.remove(&order_key); 1313 try removed_set.put(&order_key); 1314 } else { 1315 _ = try removed_set.remove(&order_key); 1316 try active.put(&order_key); 1317 } 1318 } 1319 1320 pub fn readEventKind( 1321 comptime hash_kind: hash.HashKind, 1322 kind_map: anytype, 1323 id: *const [event_id_size]u8, 1324 ) !?EventKind { 1325 const cursor = try kind_map.getCursor(hash.hashInt(hash_kind, id)) orelse return null; 1326 var buffer: [64]u8 = undefined; 1327 return std.meta.stringToEnum(EventKind, try cursor.readBytes(&buffer)) orelse error.InvalidEventKind; 1328 } 1329 1330 // the event id embedded in a set entry's order key 1331 pub fn readOrderKeyId(comptime DB: type, kv_pair_cursor: DB.Cursor(.read_only)) ![event_id_size]u8 { 1332 var cursor = kv_pair_cursor; 1333 const kv_pair = try cursor.readKeyValuePair(); 1334 var order_key: [@sizeOf(u64) + event_id_size]u8 = undefined; 1335 _ = try kv_pair.key_cursor.readBytes(&order_key); 1336 return order_key[@sizeOf(u64)..][0..event_id_size].*; 1337 } 1338 1339 // split a pushed "<owner>/<repo>" path into its two components, or null if it 1340 // isn't exactly two non-empty segments. 1341 pub fn parseOwnerRepoPath(path: []const u8) ?struct { owner: []const u8, name: []const u8 } { 1342 var it = std.mem.splitScalar(u8, path, '/'); 1343 const owner = it.next() orelse return null; 1344 const name = it.next() orelse return null; 1345 if (it.next() != null) return null; 1346 if (owner.len == 0 or name.len == 0) return null; 1347 1348 return .{ .owner = owner, .name = name }; 1349 } 1350 1351 // resolve a pushed `<owner>/<repo>` to the hex event id that names its on-disk 1352 // directory under the repos dir 1353 pub fn resolveOrCreateRepo( 1354 io: std.Io, 1355 allocator: std.mem.Allocator, 1356 admin_repo_path: []const u8, 1357 owner_name: []const u8, 1358 repo_name: []const u8, 1359 create_if_missing: bool, 1360 ) !?[event_id_size * 2]u8 { 1361 var repo = rp.Repo(.xit, admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { 1362 error.RepoNotFound => return null, 1363 else => |e| return e, 1364 }; 1365 defer repo.deinit(io, allocator); 1366 1367 var arena = std.heap.ArenaAllocator.init(allocator); 1368 defer arena.deinit(); 1369 1370 const moment = try currentMoment(admin_repo_opts, &repo); 1371 1372 // an already-registered repo reuses its event id, so a re-push (or a clone) 1373 // lands in the same repo 1374 if (try Repo.readByOwnerAndName(AdminDB, admin_repo_opts.hash, moment, &arena, owner_name, repo_name)) |found| { 1375 return std.fmt.bytesToHex(found.event_id, .lower); 1376 } 1377 1378 if (!create_if_missing) return null; 1379 1380 // the new repo is owned by the named user, read from the name index; an 1381 // unknown owner can't own a repo, so the push is rejected 1382 const name_to_user_id_cursor = try moment.getCursor(hash.hashInt(admin_repo_opts.hash, "name->user-id")) orelse return null; 1383 const name_to_user_id = try AdminDB.HashMap(.read_only).init(name_to_user_id_cursor); 1384 const owner_id_cursor = try name_to_user_id.getCursor(hash.hashInt(admin_repo_opts.hash, owner_name)) orelse return null; 1385 var owner_user_id: [event_id_size]u8 = undefined; 1386 _ = try owner_id_cursor.readBytes(&owner_user_id); 1387 1388 const owner = (try User.readById(AdminDB, admin_repo_opts.hash, moment, &arena, &owner_user_id)) orelse unreachable; 1389 1390 var id_bytes: [event_id_size]u8 = undefined; 1391 io.random(&id_bytes); 1392 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 1393 1394 try consume(.xit, admin_repo_opts, io, allocator, &repo, events_ref, &[_]EventWithId{.{ 1395 .id = event_id_hex, 1396 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 1397 .author = .{ .name = owner.event.name, .email = owner.event.email }, 1398 .event = .{ .repo = .{ 1399 .user_id = &owner_user_id, 1400 .name = repo_name, 1401 .description = "", 1402 } }, 1403 }}); 1404 1405 return event_id_hex; 1406 } 1407 1408 // 1409 // reading from xitdb 1410 // 1411 1412 // a struct field's fields share its container's map, so their names must not 1413 // collide with the container's or two fields would silently share a key 1414 fn validateFlattenedFields(comptime T: type) void { 1415 comptime { 1416 for (std.meta.fields(T)) |field| { 1417 if (@typeInfo(field.type) != .@"struct") continue; 1418 for (std.meta.fields(field.type)) |nested| { 1419 if (@hasField(T, nested.name)) 1420 @compileError("flattened field name collision in " ++ @typeName(T) ++ ": " ++ nested.name); 1421 } 1422 } 1423 } 1424 } 1425 1426 pub fn read( 1427 comptime T: type, 1428 comptime DB: type, 1429 comptime hash_kind: hash.HashKind, 1430 arena: *std.heap.ArenaAllocator, 1431 map: DB.HashMap(.read_only), 1432 ) !T { 1433 var event: T = undefined; 1434 1435 switch (@typeInfo(T)) { 1436 .@"struct" => |struct_info| { 1437 comptime validateFlattenedFields(T); 1438 inline for (struct_info.fields) |field| { 1439 switch (@typeInfo(field.type)) { 1440 .pointer => |pointer_info| { 1441 if (pointer_info.size == .slice and pointer_info.child == u8 and pointer_info.is_const) { 1442 @field(event, field.name) = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 1443 } else { 1444 @compileError("unsupported read field type: " ++ @typeName(field.type)); 1445 } 1446 }, 1447 .array => |array_info| { 1448 if (array_info.child == u8) { 1449 const bytes = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 1450 if (bytes.len != array_info.len) return error.InvalidByteArrayLength; 1451 @memcpy(@field(event, field.name)[0..], bytes); 1452 } else { 1453 @compileError("unsupported read field type: " ++ @typeName(field.type)); 1454 } 1455 }, 1456 .bool => @field(event, field.name) = try readBool(DB, hash_kind, map, field.name), 1457 .int => |int_info| switch (int_info.signedness) { 1458 .unsigned => @field(event, field.name) = @intCast(try readUint(DB, hash_kind, map, field.name)), 1459 .signed => @field(event, field.name) = @intCast(try readInt(DB, hash_kind, map, field.name)), 1460 }, 1461 .@"enum" => { 1462 const bytes = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 1463 @field(event, field.name) = std.meta.stringToEnum(field.type, bytes) orelse return error.InvalidEnumTag; 1464 }, 1465 .optional => |optional_info| { 1466 if (optional_info.child != []const u8) @compileError("unsupported read field type: " ++ @typeName(field.type)); 1467 // a missing key is null 1468 @field(event, field.name) = if (try map.getCursor(hash.hashInt(hash_kind, field.name))) |cursor| 1469 try cursor.readBytesAlloc(arena.allocator(), null) 1470 else 1471 null; 1472 }, 1473 // a struct field's own fields are read from the same map 1474 .@"struct" => @field(event, field.name) = try read(field.type, DB, hash_kind, arena, map), 1475 else => @compileError("unsupported read field type: " ++ @typeName(field.type)), 1476 } 1477 } 1478 }, 1479 else => @compileError("read expects a struct"), 1480 } 1481 1482 return event; 1483 } 1484 1485 // whether two events carry the same data 1486 fn fieldsEqual(comptime T: type, a: T, b: T) bool { 1487 switch (@typeInfo(T)) { 1488 .@"struct" => |struct_info| { 1489 inline for (struct_info.fields) |field| { 1490 if (!fieldEqual(field.type, @field(a, field.name), @field(b, field.name))) return false; 1491 } 1492 }, 1493 else => @compileError("fieldsEqual expects a struct"), 1494 } 1495 1496 return true; 1497 } 1498 1499 pub fn fieldEqual(comptime Field: type, a: Field, b: Field) bool { 1500 switch (@typeInfo(Field)) { 1501 .pointer => |pointer_info| { 1502 if (pointer_info.size == .slice and pointer_info.child == u8) { 1503 return std.mem.eql(u8, a, b); 1504 } else { 1505 @compileError("unsupported field type: " ++ @typeName(Field)); 1506 } 1507 }, 1508 .array => |array_info| { 1509 if (array_info.child == u8) { 1510 return std.mem.eql(u8, &a, &b); 1511 } else { 1512 @compileError("unsupported field type: " ++ @typeName(Field)); 1513 } 1514 }, 1515 .bool, .int, .@"enum" => return a == b, 1516 else => @compileError("unsupported field type: " ++ @typeName(Field)), 1517 } 1518 } 1519 1520 fn readBytes( 1521 comptime DB: type, 1522 comptime hash_kind: hash.HashKind, 1523 allocator: std.mem.Allocator, 1524 map: DB.HashMap(.read_only), 1525 field_name: []const u8, 1526 ) ![]const u8 { 1527 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1528 return try cursor.readBytesAlloc(allocator, null); 1529 } 1530 1531 fn readUint( 1532 comptime DB: type, 1533 comptime hash_kind: hash.HashKind, 1534 map: DB.HashMap(.read_only), 1535 field_name: []const u8, 1536 ) !u64 { 1537 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1538 return try cursor.readUint(); 1539 } 1540 1541 fn readInt( 1542 comptime DB: type, 1543 comptime hash_kind: hash.HashKind, 1544 map: DB.HashMap(.read_only), 1545 field_name: []const u8, 1546 ) !i64 { 1547 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1548 return try cursor.readInt(); 1549 } 1550 1551 fn readBool( 1552 comptime DB: type, 1553 comptime hash_kind: hash.HashKind, 1554 map: DB.HashMap(.read_only), 1555 field_name: []const u8, 1556 ) !bool { 1557 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1558 var buffer: [5]u8 = undefined; 1559 const bytes = try cursor.readBytesObject(&buffer); 1560 const format_tag = bytes.format_tag orelse return error.InvalidFormatTag; 1561 if (!std.mem.eql(u8, &format_tag, "bl")) return error.InvalidFormatTag; 1562 if (std.mem.eql(u8, bytes.value, "true")) return true; 1563 if (std.mem.eql(u8, bytes.value, "false")) return false; 1564 return error.InvalidBool; 1565 } 1566 1567 // 1568 // writing to xitdb 1569 // 1570 1571 pub fn upsert( 1572 comptime T: type, 1573 comptime DB: type, 1574 comptime hash_kind: hash.HashKind, 1575 map: DB.HashMap(.read_write), 1576 event: T, 1577 ) !void { 1578 switch (@typeInfo(T)) { 1579 .@"struct" => |struct_info| { 1580 comptime validateFlattenedFields(T); 1581 inline for (struct_info.fields) |field| { 1582 try upsertField(DB, hash_kind, map, field.name, field.type, @field(event, field.name)); 1583 } 1584 }, 1585 else => @compileError("upsert expects a struct"), 1586 } 1587 } 1588 1589 fn upsertField( 1590 comptime DB: type, 1591 comptime hash_kind: hash.HashKind, 1592 map: DB.HashMap(.read_write), 1593 comptime field_name: []const u8, 1594 comptime Field: type, 1595 value: Field, 1596 ) !void { 1597 const key = hash.hashInt(hash_kind, field_name); 1598 1599 switch (@typeInfo(Field)) { 1600 .pointer => |pointer_info| { 1601 if (pointer_info.size == .slice and pointer_info.child == u8) { 1602 try upsertBytes(DB, hash_kind, map, key, value); 1603 } else { 1604 @compileError("unsupported upsert field type: " ++ @typeName(Field)); 1605 } 1606 }, 1607 .array => |array_info| { 1608 if (array_info.child == u8) { 1609 try upsertBytes(DB, hash_kind, map, key, &value); 1610 } else { 1611 @compileError("unsupported upsert field type: " ++ @typeName(Field)); 1612 } 1613 }, 1614 .int => |int_info| switch (int_info.signedness) { 1615 .unsigned => { 1616 if (try map.getCursor(key)) |value_cursor| { 1617 if (try value_cursor.readUint() == value) { 1618 return; 1619 } 1620 } 1621 1622 try map.put(key, .{ .uint = value }); 1623 }, 1624 .signed => { 1625 if (try map.getCursor(key)) |value_cursor| { 1626 if (try value_cursor.readInt() == value) { 1627 return; 1628 } 1629 } 1630 1631 try map.put(key, .{ .int = value }); 1632 }, 1633 }, 1634 .bool => { 1635 const bytes = if (value) "true" else "false"; 1636 if (try map.getCursor(key)) |value_cursor| { 1637 var buffer: [5]u8 = undefined; 1638 const existing = try value_cursor.readBytesObject(&buffer); 1639 if (existing.format_tag) |format_tag| { 1640 if (std.mem.eql(u8, &format_tag, "bl") and std.mem.eql(u8, existing.value, bytes)) { 1641 return; 1642 } 1643 } 1644 } 1645 1646 try map.put(key, .{ .bytes_object = .{ .value = bytes, .format_tag = "bl".* } }); 1647 }, 1648 .@"enum" => try upsertBytes(DB, hash_kind, map, key, @tagName(value)), 1649 .optional => |optional_info| { 1650 if (optional_info.child != []const u8) @compileError("unsupported upsert field type: " ++ @typeName(Field)); 1651 // a missing key is null 1652 if (value) |bytes| { 1653 try upsertBytes(DB, hash_kind, map, key, bytes); 1654 } else { 1655 _ = try map.remove(key); 1656 } 1657 }, 1658 // a struct field's own fields are stored in the same map 1659 .@"struct" => try upsert(Field, DB, hash_kind, map, value), 1660 else => @compileError("unsupported upsert field type: " ++ @typeName(Field)), 1661 } 1662 } 1663 1664 fn upsertBytes( 1665 comptime DB: type, 1666 comptime hash_kind: hash.HashKind, 1667 map: DB.HashMap(.read_write), 1668 key: hash.HashInt(hash_kind), 1669 value: []const u8, 1670 ) !void { 1671 var existing_cursor_maybe = try map.getCursor(key); 1672 if (existing_cursor_maybe) |*existing_cursor| { 1673 if (try bytesEqual(DB, existing_cursor, value)) { 1674 return; 1675 } 1676 } 1677 1678 var value_cursor = try map.putCursor(key); 1679 var write_buffer: [1024]u8 = undefined; 1680 var writer = try value_cursor.writer(&write_buffer); 1681 try writer.interface.writeAll(value); 1682 try writer.finish(); 1683 } 1684 1685 fn bytesEqual( 1686 comptime DB: type, 1687 cursor: *DB.Cursor(.read_only), 1688 value: []const u8, 1689 ) !bool { 1690 var read_buffer: [1024]u8 = undefined; 1691 var reader = try cursor.reader(&read_buffer); 1692 if (reader.size != value.len) { 1693 return false; 1694 } 1695 1696 var chunk_buffer: [1024]u8 = undefined; 1697 var offset: usize = 0; 1698 while (offset < value.len) { 1699 const chunk_len = @min(chunk_buffer.len, value.len - offset); 1700 try reader.interface.readSliceAll(chunk_buffer[0..chunk_len]); 1701 if (!std.mem.eql(u8, chunk_buffer[0..chunk_len], value[offset .. offset + chunk_len])) { 1702 return false; 1703 } 1704 offset += chunk_len; 1705 } 1706 1707 return true; 1708 } 1709 1710 // 1711 // CommitIterator 1712 // 1713 // differs from xit's ObjectIterator in a few ways: 1714 // 1715 // 1. iterates parents first, rather than children first 1716 // 2. `next` only returns the object id, not the full Object 1717 // 3. stores its temporary state in a file on disk to avoid OOMs 1718 // 1719 1720 pub fn CommitIterator(comptime repo_kind: rp.RepoKind, comptime repo_opts: rp.RepoOpts(repo_kind)) type { 1721 return struct { 1722 const DB = EventDB(repo_opts.hash); 1723 const db_name = "haxy-repo-events.db"; 1724 1725 repo_dir: std.Io.Dir, 1726 db_file: std.Io.File, 1727 db: *DB, 1728 // map of each object id to its children 1729 parent_to_children: DB.HashMap(.read_write), 1730 // tracking pending parents is necessary because a child can only 1731 // be returned after all of its unconsumed parents have been returned 1732 child_to_pending_parents: DB.HashMap(.read_write), 1733 // queue of object ids that are ready to be returned from `next` 1734 ready_queue: DB.ArrayList(.read_write), 1735 ready_queue_index: u64, 1736 // the object id at the tip of this branch 1737 newest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, 1738 // the object id furthest back in the history that hasn't been consumed 1739 oldest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, 1740 1741 pub fn init( 1742 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 1743 io: std.Io, 1744 allocator: std.mem.Allocator, 1745 consumed_object_ids: DB.HashMap(.read_only), 1746 ref: rf.Ref, 1747 ) !CommitIterator(repo_kind, repo_opts) { 1748 const db_file = try state.core.repo_dir.createFile(io, db_name, .{ .truncate = true, .lock = .exclusive, .read = true }); 1749 errdefer { 1750 db_file.close(io); 1751 state.core.repo_dir.deleteFile(io, db_name) catch {}; 1752 } 1753 1754 const buffer_ptr = try allocator.create(std.Io.Writer.Allocating); 1755 errdefer allocator.destroy(buffer_ptr); 1756 1757 buffer_ptr.* = std.Io.Writer.Allocating.init(allocator); 1758 errdefer buffer_ptr.deinit(); 1759 1760 const db_ptr = try allocator.create(DB); 1761 errdefer allocator.destroy(db_ptr); 1762 // the db is scratch state that gets deleted after iteration, so 1763 // there is nothing worth fsyncing 1764 db_ptr.* = try DB.init(.{ .io = io, .file = db_file, .buffer = buffer_ptr, .fsync = false }); 1765 1766 const map = try DB.HashMap(.read_write).init(db_ptr.rootCursor()); 1767 1768 const parent_to_children_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "parent->children")); 1769 const parent_to_children = try DB.HashMap(.read_write).init(parent_to_children_cursor); 1770 1771 const child_to_pending_parents_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "child->pending-parents")); 1772 const child_to_pending_parents = try DB.HashMap(.read_write).init(child_to_pending_parents_cursor); 1773 1774 const ready_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "ready-queue")); 1775 const ready_queue = try DB.ArrayList(.read_write).init(ready_queue_cursor); 1776 1777 var self = CommitIterator(repo_kind, repo_opts){ 1778 .repo_dir = state.core.repo_dir, 1779 .db_file = db_file, 1780 .db = db_ptr, 1781 .parent_to_children = parent_to_children, 1782 .child_to_pending_parents = child_to_pending_parents, 1783 .ready_queue = ready_queue, 1784 .ready_queue_index = 0, 1785 .newest_object_id = null, 1786 .oldest_object_id = null, 1787 }; 1788 errdefer self.deinit(io, allocator); 1789 1790 try self.collect(state, io, allocator, consumed_object_ids, ref); 1791 1792 return self; 1793 } 1794 1795 pub fn deinit(self: *CommitIterator(repo_kind, repo_opts), io: std.Io, allocator: std.mem.Allocator) void { 1796 self.db_file.close(io); 1797 self.db.core.memory.buffer.deinit(); 1798 allocator.destroy(self.db.core.memory.buffer); 1799 self.repo_dir.deleteFile(io, db_name) catch {}; 1800 allocator.destroy(self.db); 1801 } 1802 1803 pub fn next(self: *CommitIterator(repo_kind, repo_opts)) !?[hash.byteLen(repo_opts.hash)]u8 { 1804 if (self.ready_queue_index >= try self.ready_queue.count()) return null; 1805 1806 const oid = try readOidFromList(self.ready_queue.readOnly(), self.ready_queue_index); 1807 self.ready_queue_index += 1; 1808 1809 try self.enqueueChildren(&oid); 1810 return oid; 1811 } 1812 1813 fn collect( 1814 self: *CommitIterator(repo_kind, repo_opts), 1815 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 1816 io: std.Io, 1817 allocator: std.mem.Allocator, 1818 consumed_object_ids: DB.HashMap(.read_only), 1819 ref: rf.Ref, 1820 ) !void { 1821 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 1822 1823 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 1824 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 1825 var walk_queue_index: u64 = 0; 1826 1827 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 1828 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 1829 1830 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 1831 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1832 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 1833 try walk_queue.append(.{ .bytes = &head_oid }); 1834 1835 while (walk_queue_index < try walk_queue.count()) { 1836 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 1837 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 1838 1839 walk_queue_index += 1; 1840 1841 // if we've seen this object id, skip it 1842 if (null != try seen_object_ids.getCursor(oid_int)) { 1843 continue; 1844 } 1845 1846 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 1847 1848 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 1849 defer commit_object.deinit(); 1850 1851 // if this object id has already been consumed, skip it 1852 if (null != try consumed_object_ids.getCursor(oid_int)) { 1853 continue; 1854 } 1855 1856 if (self.newest_object_id == null) self.newest_object_id = oid; 1857 self.oldest_object_id = oid; 1858 1859 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 1860 var pending_parent_count: u64 = 0; 1861 for (parent_oids) |*parent_oid| { 1862 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1863 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 1864 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 1865 1866 // if this object id has already been consumed, skip it 1867 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 1868 continue; 1869 } 1870 1871 // if this object id hasn't already been seen, add it to the walk queue 1872 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 1873 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 1874 } 1875 1876 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 1877 const children = try DB.HashSet(.read_write).init(children_cursor); 1878 try children.put(oid_int, .{ .bytes = &oid }); 1879 pending_parent_count += 1; 1880 } 1881 1882 if (pending_parent_count == 0) { 1883 try self.ready_queue.append(.{ .bytes = &oid }); 1884 } else { 1885 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 1886 } 1887 } 1888 } 1889 1890 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 1891 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 1892 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 1893 const children = try DB.HashSet(.read_only).init(children_cursor); 1894 var children_iter = try children.iterator(); 1895 1896 while (try children_iter.next()) |*child_cursor| { 1897 const kv_pair = try child_cursor.readKeyValuePair(); 1898 const child_oid_int = kv_pair.hash; 1899 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 1900 const pending_parent_count = try pending_parent_cursor.readUint(); 1901 1902 if (pending_parent_count <= 1) { 1903 _ = try self.child_to_pending_parents.remove(child_oid_int); 1904 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 1905 try self.ready_queue.append(.{ .bytes = &child_oid }); 1906 } else { 1907 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 1908 } 1909 } 1910 } 1911 1912 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 1913 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 1914 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1915 _ = try oid_cursor.readBytes(&oid); 1916 return oid; 1917 } 1918 }; 1919 } 1920