╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
436 const haxy_moment = try evt.currentMomentFromRepoMoment(repo_opts.hash, moment.readOnly()); 437 const revisions_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.revision_to_id_set_key)) orelse return; 438 const revisions = try DB.HashMap(.read_only).init(revisions_cursor); 439 var events_ref_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; 440 const events_ref_path = try evt.events_ref.toPath(&events_ref_buffer); 441 const heads_prefix = "refs/heads/"; 442 for (updates) |update| { 443 if (!std.mem.startsWith(u8, update.ref_name, heads_prefix) or 444 std.mem.eql(u8, update.ref_name, events_ref_path) or 445 std.mem.eql(u8, update.old_oid, update.new_oid)) continue; 446 if (update.old_oid.len != hash.hexLen(repo_opts.hash) or 447 update.new_oid.len != hash.hexLen(repo_opts.hash)) return error.InvalidOid; 448 var old_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 449 var new_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 450 @memcpy(&old_oid, update.old_oid); 451 @memcpy(&new_oid, update.new_oid); 452 if (std.mem.allEqual(u8, &new_oid, '0')) continue; 453 454 var commits = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit }); 455 defer commits.deinit(); 456 if (!std.mem.allEqual(u8, &old_oid, '0')) try commits.exclude(&old_oid); 457 try commits.include(&new_oid); 458 var revision_key_buffer: [rf.MAX_REF_CONTENT_SIZE + 1 + hash.hexLen(repo_opts.hash)]u8 = undefined; 459 while (try commits.next(arena.allocator())) |commit| { 460 defer commit.deinit(); 461 const key = try std.fmt.bufPrint(&revision_key_buffer, "{s}\x00{s}", .{ update.ref_name[heads_prefix.len..], &commit.oid }); 462 const ids_cursor = try revisions.getCursor(hash.hashInt(repo_opts.hash, key)) orelse continue; 463 const ids = try DB.CountedHashSet(.read_only).init(ids_cursor); 464 var ids_iter = try ids.iterator(); 465 while (try ids_iter.next()) |cursor| { 466 const pair = try cursor.readKeyValuePair(); 467 var patch_id: [evt.event_id_size]u8 = undefined; 468 if ((try pair.key_cursor.readBytes(&patch_id)).len != patch_id.len) return error.InvalidPatch; 469 const patch_hex = std.fmt.bytesToHex(patch_id, .lower); 470 importMerged(repo_opts, state, db, moment, io, allocator, repo_root_path, &patch_id, &commit.oid) catch |err| { 471 serve_common.logError(io, error_writer, "failed to mark patch {s} as merged: {s}\n", .{ &patch_hex, @errorName(err) }); 472 continue; 473 }; 474 } 475 } 476 } 477 } 478