╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
313 .title = title, 314 .author = author, 315 .timestamp = timestamp, 316 .newest = newest, 317 .revision_id_maybe = &revision_id_maybe, 318 }); 319 }; 320 result catch |err| { 321 response.finish(writer, @errorName(err)) catch {}; 322 if (err == error.CancelTransaction) return; 323 return err; 324 }; 325 326 var progress = PushProgress{ .response = &response, .writer = writer, .label = "Updating patches" }; 327 progress.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 328 329 // best-effort update the published patch so it has the new revision 330 var refreshed = false; 331 update: { 332 const revision_id = revision_id_maybe orelse break :update; 333 if (!published) break :update; 334 var update_arena = std.heap.ArenaAllocator.init(allocator); 335 defer update_arena.deinit(); 336 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 337 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; 338 if (published_patch.removed) break :update; 339 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 340 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; 341 if (revision.removed) break :update; 342 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 343 if (published_patch.event.revision) |current| { 344 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 345 } 346 var patch = published_patch.event; 347 patch.revision = selected; 348 evt.consume(.server, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 349 .id = id.*, 350 .timestamp = timestamp, 351 .author = author, 352 .event = .{ .patch = patch }, 353 }}) catch |update_err| { 354 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 355 break :update; 356 }; 357 // consume also refreshed mergeability 358 refreshed = true; 359 } 360 361 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, patch_id); 362 progress.run(io, .{ .complete_one = .writing_patch }) catch {}; 363 progress.run(io, .{ .end = .writing_patch }) catch {}; 364 365 // the client may read either repo as soon as it gets the final response. 366 try response.finish(writer, null); 367 } 368