╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
375 .author = ctx.author, 376 .event = .{ .patch = patch }, 377 }; 378 event_count += 1; 379 } 380 } 381 382 // published patches keep only revisions in the fork 383 if (ctx.published and !ctx.patch.removed) { 384 events[event_count] = .{ 385 .id = ctx.patch_id, 386 .timestamp = ctx.timestamp, 387 .author = ctx.author, 388 .event = .{ .patch = null }, 389 }; 390 event_count += 1; 391 } 392 393 // commit and index any new events 394 if (event_count > 0) { 395 try evt.commitEvents(.xit, repo_opts, state, ctx.io, ctx.allocator, evt.events_ref, events[0..event_count], null); 396 _ = try evt.consumeInTransaction(.fork, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref); 397 } 398 // the patch branch's file index lands with the push 399 _ = try find.refreshInTransaction(repo_opts, state, &moment, ctx.io, ctx.allocator, ctx.sideband); 400 401 // a fork push tracks no ref updates, so it records no ranges 402 try writeUndo(repo_opts, state, ctx.io, ctx.allocator, ctx.author, &.{}); 403 } 404 }; 405 406 try fork_repo.core.db_file.lock(io, .exclusive); 407 defer fork_repo.core.db_file.unlock(io); 408 409 const history = try DB.ArrayList(.read_write).init(fork_repo.core.db.rootCursor()); 410 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 411 .core = &fork_repo.core, 412 .target_core = &target_repo.core, 413 .io = io, 414 .allocator = allocator, 415 .reader = reader, 416 .writer = writer, 417 .response = &response, 418 .patch_id = id.*, 419 .patch = fork_patch, 420 .published = published, 421 .target_oid = target_oid, 422 .title = title, 423 .author = author, 424 .timestamp = timestamp, 425 .newest = newest, 426 .revision_id_maybe = &revision_id_maybe, 427 .sideband = &sideband, 428 }); 429 }; 430 result catch |err| { 431 response.finish(writer, @errorName(err)) catch {}; 432 if (err == error.CancelTransaction) return; 433 return err; 434 }; 435 436 if (!published) return response.finish(writer, null); 437 438 sideband.run(io, .{ .text = "Updating patches" }) catch {}; 439 sideband.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 440 441 // best-effort update the published patch so it has the new revision 442 var refreshed = false; 443 update: { 444 const revision_id = revision_id_maybe orelse break :update; 445 var update_arena = std.heap.ArenaAllocator.init(allocator); 446 defer update_arena.deinit(); 447 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 448 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; 449 if (published_patch.removed) break :update; 450 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 451 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; 452 if (revision.removed) break :update; 453 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 454 if (published_patch.event.revision) |current| { 455 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 456 } 457 var patch = published_patch.event; 458 patch.revision = selected; 459 evt.consume(.{ .server = server }, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 460 .id = id.*, 461 .timestamp = timestamp, 462 .author = author, 463 .event = .{ .patch = patch }, 464 }}) catch |update_err| { 465 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 466 break :update; 467 }; 468 // consume also refreshed mergeability 469 refreshed = true; 470 } 471 472 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, server.users_dir, patch_id); 473 sideband.run(io, .{ .complete_one = .writing_patch }) catch {}; 474 sideband.run(io, .{ .end = .writing_patch }) catch {}; 475 476 // the client may read either repo as soon as it gets the final response. 477 try response.finish(writer, null); 478 } 479