╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
392 event_count += 1; 393 } 394 } 395 396 // published patches keep only revisions in the fork 397 if (ctx.published and !ctx.patch.removed) { 398 events[event_count] = .{ 399 .id = ctx.patch_id, 400 .timestamp = ctx.timestamp, 401 .author = ctx.author, 402 .event = .{ .patch = null }, 403 }; 404 event_count += 1; 405 } 406 407 // commit and index any new events 408 if (event_count > 0) { 409 try evt.commitEvents(.xit, repo_opts, state, ctx.io, ctx.allocator, evt.events_ref, events[0..event_count], null); 410 _ = try evt.consumeInTransaction(.fork, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref); 411 } 412 // the patch branch's file index lands with the push 413 _ = try find.refreshInTransaction(repo_opts, state, &moment, ctx.io, ctx.allocator, ctx.sideband); 414 415 // a fork push tracks no ref updates, so it records no ranges 416 try writeUndo(repo_opts, state, ctx.io, ctx.allocator, ctx.author, &.{}); 417 // the copied target history and the index count against the limit too 418 try ctx.sideband.checkSize(ctx.io); 419 } 420 }; 421 422 try fork_repo.core.db_file.lock(io, .exclusive); 423 defer fork_repo.core.db_file.unlock(io); 424 425 const history = try DB.ArrayList(.read_write).init(fork_repo.core.db.rootCursor()); 426 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 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