╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
278 if (ctx.published and !ctx.patch.removed) { 279 events[event_count] = .{ 280 .id = ctx.patch_id, 281 .timestamp = ctx.timestamp, 282 .author = ctx.author, 283 .event = .{ .patch = null }, 284 }; 285 event_count += 1; 286 } 287 288 // commit and index any new events 289 if (event_count > 0) { 290 try evt.commitEvents(.xit, repo_opts, state, ctx.io, ctx.allocator, evt.events_ref, events[0..event_count], null); 291 if (!try evt.consumeInTransaction(.fork, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref)) return error.CancelTransaction; 292 } 293 try xit.undo.writeMessage(repo_opts, state, .push); 294 } 295 }; 296 297 try fork_repo.core.db_file.lock(io, .exclusive); 298 defer fork_repo.core.db_file.unlock(io); 299 300 const history = try DB.ArrayList(.read_write).init(fork_repo.core.db.rootCursor()); 301 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 302 .core = &fork_repo.core, 303 .target_core = &target_repo.core, 304 .io = io, 305 .allocator = allocator, 306 .reader = reader, 307 .writer = writer, 308 .response = &response, 309 .patch_id = id.*, 310 .patch = fork_patch, 311 .published = published, 312 .target_oid = target_oid, 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