╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
333 for (chunks) |chunk| { 334 if (chunk != .conflict) continue; 335 try resolutions.append(arena.allocator(), if (hunk_index < resolve.hunks.len) resolve.hunks[hunk_index] else (chunk.conflict.ours orelse "")); 336 hunk_index += 1; 337 } 338 updated.description = try diff3.assemble(arena.allocator(), chunks, resolutions.items); 339 return updated; 340 } 341 342 fn fieldListed(fields: []const u8, delimiter: u8, name: []const u8) bool { 343 var iter = std.mem.splitScalar(u8, fields, delimiter); 344 while (iter.next()) |field| { 345 if (std.mem.eql(u8, field, name)) return true; 346 } 347 return false; 348 } 349 350 fn readFromRepo( 351 comptime repo_kind: rp.RepoKind, 352 comptime repo_opts: rp.RepoOpts(repo_kind), 353 io: std.Io, 354 allocator: std.mem.Allocator, 355 arena: *std.heap.ArenaAllocator, 356 repo: *rp.Repo(repo_kind, repo_opts), 357 id: *const [evt.event_id_size]u8, 358 ) !?Record { 359 var event_db_maybe: ?evt.LocalEventDB(repo_opts.hash) = if (repo_kind == .git) try evt.LocalEventDB(repo_opts.hash).openReadOnly(io, allocator, repo.core.repo_dir) else null; 360 defer if (event_db_maybe) |*event_db| event_db.deinit(io, allocator); 361 const moment = (if (event_db_maybe) |*event_db| 362 evt.currentMomentFromDb(repo_opts.hash, event_db.db) 363 else if (repo_kind == .git) 364 return null 365 else 366 evt.currentMoment(repo_opts, repo)) catch return null; 367 return readById(evt.EventDB(repo_opts.hash), repo_opts.hash, moment, arena, id); 368 } 369 370 fn revisionKey(allocator: std.mem.Allocator, target_ref: []const u8, oid: []const u8) ![]u8 { 371 return std.mem.concat(allocator, u8, &.{ target_ref, "\x00", oid }); 372 } 373 374 fn statusSet( 375 comptime DB: type, 376 statuses: DB.SortedMap(.read_write), 377 status: Status, 378 ) !DB.SortedSet(.read_write) { 379 return DB.SortedSet(.read_write).init(try statuses.putCursor(@tagName(status))); 380 } 381 382 fn removeFromTagSets( 383 comptime DB: type, 384 tag_statuses: DB.SortedMap(.read_write), 385 tags: []const u8, 386 status: Status, 387 order_key: []const u8, 388 ) !void { 389 var tag_iter = tagIterator(tags); 390 while (tag_iter.next()) |tag| { 391 if (tag.len == 0 or tag.len > tag_max_len) continue; 392 var key_buffer: TagStatusKey = undefined; 393 const key = try tagStatusKey(&key_buffer, tag, status); 394 const set = try DB.SortedSet(.read_write).init(try tag_statuses.putCursor(key)); 395 _ = try set.remove(order_key); 396 if (0 == try set.count()) _ = try tag_statuses.remove(key); 397 } 398 } 399 400 pub fn readById( 401 comptime DB: type, 402 comptime hash_kind: hash.HashKind, 403 haxy_moment: DB.HashMap(.read_only), 404 arena: *std.heap.ArenaAllocator, 405 id: *const [evt.event_id_size]u8, 406 ) !?Record { 407 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 408 const records = try DB.HashMap(.read_only).init(records_cursor); 409 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, id)) orelse return null; 410 return try evt.read(Record, DB, hash_kind, arena, try DB.HashMap(.read_only).init(record_cursor)); 411 } 412