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