╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
351 352 // commit and index any new events 353 if (event_count > 0) { 354 try evt.commitEvents(.xit, repo_opts, state, ctx.io, ctx.allocator, evt.events_ref, events[0..event_count], null); 355 if (!try evt.consumeInTransaction(.fork, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref)) return error.CancelTransaction; 356 } 357 // the patch branch's file index lands with the push 358 _ = try find.refreshInTransaction(repo_opts, state, &moment, ctx.io, ctx.allocator, ctx.sideband); 359 360 // a fork push tracks no ref updates, so it records no ranges 361 try writeUndo(repo_opts, state, ctx.io, ctx.allocator, ctx.author, &.{}); 362 } 363 }; 364 365 try fork_repo.core.db_file.lock(io, .exclusive); 366 defer fork_repo.core.db_file.unlock(io); 367 368 const history = try DB.ArrayList(.read_write).init(fork_repo.core.db.rootCursor()); 369 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 370 .core = &fork_repo.core, 371 .target_core = &target_repo.core, 372 .io = io, 373 .allocator = allocator, 374 .reader = reader, 375 .writer = writer, 376 .response = &response, 377 .patch_id = id.*, 378 .patch = fork_patch, 379 .published = published, 380 .target_oid = target_oid, 381 .title = title, 382 .author = author, 383 .timestamp = timestamp, 384 .newest = newest, 385 .revision_id_maybe = &revision_id_maybe, 386 .sideband = &sideband, 387 }); 388 }; 389 result catch |err| { 390 response.finish(writer, @errorName(err)) catch {}; 391 if (err == error.CancelTransaction) return; 392 return err; 393 }; 394 395 if (!published) return response.finish(writer, null); 396 397 sideband.run(io, .{ .text = "Updating patches" }) catch {}; 398 sideband.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 399 400 // best-effort update the published patch so it has the new revision 401 var refreshed = false; 402 update: { 403 const revision_id = revision_id_maybe orelse break :update; 404 var update_arena = std.heap.ArenaAllocator.init(allocator); 405 defer update_arena.deinit(); 406 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 407 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; 408 if (published_patch.removed) break :update; 409 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 410 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; 411 if (revision.removed) break :update; 412 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 413 if (published_patch.event.revision) |current| { 414 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 415 } 416 var patch = published_patch.event; 417 patch.revision = selected; 418 evt.consume(.server, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 419 .id = id.*, 420 .timestamp = timestamp, 421 .author = author, 422 .event = .{ .patch = patch }, 423 }}) catch |update_err| { 424 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 425 break :update; 426 }; 427 // consume also refreshed mergeability 428 refreshed = true; 429 } 430 431 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, patch_id); 432 sideband.run(io, .{ .complete_one = .writing_patch }) catch {}; 433 sideband.run(io, .{ .end = .writing_patch }) catch {}; 434 435 // the client may read either repo as soon as it gets the final response. 436 try response.finish(writer, null); 437 } 438