╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
296 // commit and index any new events 297 if (event_count > 0) { 298 try evt.commitEvents(.xit, repo_opts, state, ctx.io, ctx.allocator, evt.events_ref, events[0..event_count], null); 299 if (!try evt.consumeInTransaction(.fork, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref)) return error.CancelTransaction; 300 } 301 try xit.undo.writeMessage(repo_opts, state, .push); 302 } 303 }; 304 305 try fork_repo.core.db_file.lock(io, .exclusive); 306 defer fork_repo.core.db_file.unlock(io); 307 308 const history = try DB.ArrayList(.read_write).init(fork_repo.core.db.rootCursor()); 309 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 310 .core = &fork_repo.core, 311 .target_core = &target_repo.core, 312 .io = io, 313 .allocator = allocator, 314 .reader = reader, 315 .writer = writer, 316 .response = &response, 317 .patch_id = id.*, 318 .patch = fork_patch, 319 .published = published, 320 .target_oid = target_oid, 321 .title = title, 322 .author = author, 323 .timestamp = timestamp, 324 .newest = newest, 325 .revision_id_maybe = &revision_id_maybe, 326 }); 327 }; 328 result catch |err| { 329 response.finish(writer, @errorName(err)) catch {}; 330 if (err == error.CancelTransaction) return; 331 return err; 332 }; 333 334 find.refresh(repo_opts, io, allocator, fork_repo) catch |err| { 335 serve_common.logError(io, error_writer, "failed to refresh file index: {s}\n", .{@errorName(err)}); 336 }; 337 if (!published) return response.finish(writer, null); 338 339 var progress = PushProgress{ .response = &response, .writer = writer, .label = "Updating patches" }; 340 progress.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 341 342 // best-effort update the published patch so it has the new revision 343 var refreshed = false; 344 update: { 345 const revision_id = revision_id_maybe orelse break :update; 346 var update_arena = std.heap.ArenaAllocator.init(allocator); 347 defer update_arena.deinit(); 348 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 349 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; 350 if (published_patch.removed) break :update; 351 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 352 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; 353 if (revision.removed) break :update; 354 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 355 if (published_patch.event.revision) |current| { 356 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 357 } 358 var patch = published_patch.event; 359 patch.revision = selected; 360 evt.consume(.server, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 361 .id = id.*, 362 .timestamp = timestamp, 363 .author = author, 364 .event = .{ .patch = patch }, 365 }}) catch |update_err| { 366 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 367 break :update; 368 }; 369 // consume also refreshed mergeability 370 refreshed = true; 371 } 372 373 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, patch_id); 374 progress.run(io, .{ .complete_one = .writing_patch }) catch {}; 375 progress.run(io, .{ .end = .writing_patch }) catch {}; 376 377 // the client may read either repo as soon as it gets the final response. 378 try response.finish(writer, null); 379 } 380