╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1470 defer commit.deinit(); 1471 try targets.append(arena.allocator(), .{ 1472 .before_oid = (commit.content.commit.metadata.firstParent() orelse &old_oid).*, 1473 .after_oid = commit.oid, 1474 }); 1475 } 1476 } 1477 1478 // visit target commits oldest first, attributing each revision to the 1479 // commit that introduced it; the shared iterator visits each ancestor once 1480 var revision_key_buffer: [rf.MAX_REF_CONTENT_SIZE + 1 + hash.hexLen(repo_opts.hash)]u8 = undefined; 1481 while (targets.pop()) |target| { 1482 try commits.include(&target.after_oid); 1483 while (try commits.next(arena.allocator())) |commit| { 1484 defer commit.deinit(); 1485 1486 // find patches whose selected revision matches this commit. 1487 const key = try std.fmt.bufPrint(&revision_key_buffer, "{s}\x00{s}", .{ update.ref_name[heads_prefix.len..], &commit.oid }); 1488 const ids_cursor = try revisions.getCursor(hash.hashInt(repo_opts.hash, key)) orelse continue; 1489 const ids = try DB.CountedHashSet(.read_only).init(ids_cursor); 1490 var ids_iter = try ids.iterator(); 1491 while (try ids_iter.next()) |cursor| { 1492 const pair = try cursor.readKeyValuePair(); 1493 var patch_id: [evt.event_id_size]u8 = undefined; 1494 if ((try pair.key_cursor.readBytes(&patch_id)).len != patch_id.len) return error.InvalidPatch; 1495 const patch_hex = std.fmt.bytesToHex(patch_id, .lower); 1496 1497 // a fast-forward has no recorded merge boundary; use the old ref tip 1498 const before_oid = if (std.mem.eql(u8, &commit.oid, &target.after_oid)) &old_oid else &target.before_oid; 1499 importMerged(repo_opts, state, db, moment, io, allocator, users_dir, &patch_id, &commit.oid, before_oid, &target.after_oid) catch |err| { 1500 serve_common.logError(io, error_writer, "failed to mark patch {s} as merged: {s}\n", .{ &patch_hex, @errorName(err) }); 1501 continue; 1502 }; 1503 } 1504 } 1505 } 1506 } 1507 } 1508