╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
427 .core = &fork_repo.core, 428 .target_core = &target_repo.core, 429 .io = io, 430 .allocator = allocator, 431 .reader = reader, 432 .writer = writer, 433 .response = &response, 434 .patch_id = id.*, 435 .patch = fork_patch, 436 .published = published, 437 .target_oid = target_oid, 438 .title = title, 439 .author = author, 440 .timestamp = timestamp, 441 .newest = newest, 442 .revision_id_maybe = &revision_id_maybe, 443 .sideband = &sideband, 444 }); 445 }; 446 result catch |err| switch (err) { 447 // a refused push has already written the report saying why 448 error.CancelTransaction => return response.finish(writer, null), 449 else => { 450 response.finish(writer, @errorName(err)) catch {}; 451 return err; 452 }, 453 }; 454 455 if (!published) return response.finish(writer, null); 456 457 sideband.run(io, .{ .text = "Updating patches" }) catch {}; 458 sideband.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 459 460 // best-effort update the published patch so it has the new revision 461 var refreshed = false; 462 update: { 463 const revision_id = revision_id_maybe orelse break :update; 464 var update_arena = std.heap.ArenaAllocator.init(allocator); 465 defer update_arena.deinit(); 466 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 467 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; 468 if (published_patch.removed) break :update; 469 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 470 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; 471 if (revision.removed) break :update; 472 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 473 if (published_patch.event.revision) |current| { 474 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 475 } 476 var patch = published_patch.event; 477 patch.revision = selected; 478 evt.consume(.{ .server = server }, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 479 .id = id.*, 480 .timestamp = timestamp, 481 .author = author, 482 .event = .{ .patch = patch }, 483 }}) catch |update_err| { 484 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 485 break :update; 486 }; 487 // consume also refreshed mergeability 488 refreshed = true; 489 } 490 491 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, server.users_dir, patch_id); 492 sideband.run(io, .{ .complete_one = .writing_patch }) catch {}; 493 sideband.run(io, .{ .end = .writing_patch }) catch {}; 494 495 // the client may read either repo as soon as it gets the final response. 496 try response.finish(writer, null); 497 } 498