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