╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
451 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 452 .core = &fork_repo.core, 453 .target_core = &target_repo.core, 454 .io = io, 455 .allocator = allocator, 456 .reader = reader, 457 .writer = writer, 458 .response = &response, 459 .patch_id = id.*, 460 .patch = fork_patch, 461 .published = published, 462 .target_oid = target_oid, 463 .title = title, 464 .author = author, 465 .timestamp = timestamp, 466 .newest = newest, 467 .revision_id_maybe = &revision_id_maybe, 468 .sideband = &sideband, 469 }); 470 }; 471 result catch |err| switch (err) { 472 // a refused push has already written the report saying why 473 error.CancelTransaction => return response.finish(writer, null), 474 else => { 475 response.finish(writer, @errorName(err)) catch {}; 476 return err; 477 }, 478 }; 479 480 if (!published) return response.finish(writer, null); 481 482 sideband.run(io, .{ .text = "Updating patches" }) catch {}; 483 sideband.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 484 485 // best-effort update the published patch so it has the new revision 486 var refreshed = false; 487 update: { 488 const revision_id = revision_id_maybe orelse break :update; 489 var update_arena = std.heap.ArenaAllocator.init(allocator); 490 defer update_arena.deinit(); 491 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 492 const published_patch = (evt.Patch.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, target_update_moment, &update_arena, &patch_id) catch break :update) orelse break :update; 493 if (published_patch.removed) break :update; 494 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 495 const revision = (evt.PatchRev.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, fork_update_moment, &update_arena, &revision_id) catch break :update) orelse break :update; 496 if (revision.removed) break :update; 497 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 498 if (published_patch.event.revision) |current| { 499 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 500 } 501 var patch = published_patch.event; 502 patch.revision = selected; 503 evt.consume(.{ .server = server }, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 504 .id = id.*, 505 .timestamp = timestamp, 506 .author = author, 507 .event = .{ .patch = patch }, 508 }}) catch |update_err| { 509 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 510 break :update; 511 }; 512 // consume also refreshed mergeability 513 refreshed = true; 514 } 515 516 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, server.users_dir, patch_id); 517 sideband.run(io, .{ .complete_one = .writing_patch }) catch {}; 518 sideband.run(io, .{ .end = .writing_patch }) catch {}; 519 520 // the client may read either repo as soon as it gets the final response. 521 try response.finish(writer, null); 522 } 523