╭ push.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const xit = @import("xit"); 3 const rp = xit.repo; 4 const hash = xit.hash; 5 const mrg = xit.merge; 6 const obj = xit.object; 7 const rf = xit.ref; 8 const evt = @import("event.zig"); 9 const pch = @import("patch.zig"); 10 const find = @import("find.zig"); 11 const srch_cmmt = @import("search_commit.zig"); 12 const fork = @import("fork.zig"); 13 const serve_common = @import("serve_common.zig"); 14 const ssh = @import("serve_ssh_protocol.zig"); 15 const progress = @import("./progress.zig"); 16 17 // prepare all reachable commits, including history received before patch 18 // generation was enabled. this shares the receive-pack transaction. 19 pub fn writeReceivedPatches( 20 comptime repo_opts: rp.RepoOpts(.xit), 21 state: rp.Repo(.xit, repo_opts).State(.read_write), 22 io: std.Io, 23 allocator: std.mem.Allocator, 24 response: *xit.net_server_receive_pack.Response, 25 writer: *std.Io.Writer, 26 ) !void { 27 var config = try xit.config.Config(.xit, repo_opts).init(state.readOnly(), io, allocator); 28 defer config.deinit(); 29 try config.add(state, io, .{ .name = "merge.algorithm", .value = "patch" }); 30 31 // every ref is a tip 32 var tips: std.ArrayList([hash.hexLen(repo_opts.hash)]u8) = .empty; 33 defer tips.deinit(allocator); 34 var refs = try rf.AllRefIterator(.xit, repo_opts).init(state.readOnly(), allocator); 35 defer refs.deinit(); 36 while (try refs.next()) |ref| { 37 if (try rf.readRecur(.xit, repo_opts, state.readOnly(), io, .{ .ref = ref })) |oid| try tips.append(allocator, oid); 38 } 39 var sideband = progress.Sideband{ .response = response, .writer = writer }; 40 try xit.patch.writePatches(repo_opts, state, io, allocator, tips.items, &sideband); 41 } 42 43 // the action a received push records 44 pub const undo_action = "haxy/push"; 45 46 // the fixture records a stand-in push with this too, so both write one shape 47 pub fn writeUndo( 48 comptime repo_opts: rp.RepoOpts(.xit), 49 state: rp.Repo(.xit, repo_opts).State(.read_write), 50 io: std.Io, 51 allocator: std.mem.Allocator, 52 author: ?evt.CommitAuthor, 53 updates: []const xit.net_server_receive_pack.AppliedRefUpdate, 54 ) !void { 55 // what the payload may take up: the record holds a timestamp and the 56 // action kind in the same fixed buffer 57 const payload_max_len = repo_opts.max_read_size - @sizeOf(i64) - undo_action.len - 1; 58 59 var arena = std.heap.ArenaAllocator.init(allocator); 60 defer arena.deinit(); 61 const aa = arena.allocator(); 62 63 const author_json: std.json.ObjectMap = if (author) |user| 64 try .init(aa, &.{ "username", "email" }, &.{ .{ .string = user.name }, .{ .string = user.email } }) 65 else 66 .empty; 67 var payload: std.json.ObjectMap = try .init(aa, &.{"author"}, &.{if (author != null) .{ .object = author_json } else .null}); 68 69 // where each ref landed, so the undo tab can say what the push did to it. 70 // an oid of all zeros means the ref has no side there, which is how a 71 // create and a remove are told apart 72 var refs: std.json.Array = .init(aa); 73 for (updates) |update| { 74 const entry: std.json.ObjectMap = try .init(aa, &.{ "name", "old", "new" }, &.{ 75 .{ .string = update.ref_name }, 76 .{ .string = if (zeroOid(update.old_oid)) "" else update.old_oid }, 77 .{ .string = if (zeroOid(update.new_oid)) "" else update.new_oid }, 78 }); 79 try refs.append(.{ .object = entry }); 80 try payload.put(aa, "refs", .{ .array = refs }); 81 82 // the record is written into one fixed buffer, so a ref that no 83 // longer fits is left out rather than failing the push 84 if (try payloadLen(payload) > payload_max_len) { 85 _ = refs.pop(); 86 break; 87 } 88 } 89 90 // the array is stored by value, so the one the payload holds still counts 91 // the entry that was popped until it is replaced here 92 try payload.put(aa, "refs", .{ .array = refs }); 93 94 try xit.undo.write(repo_opts, state, std.Io.Timestamp.now(io, .real).toSeconds(), .{ .custom = .{ .action_kind = undo_action, .payload = payload } }); 95 } 96 97 // the oid a ref update sends when it has no side: all zeros 98 fn zeroOid(oid: []const u8) bool { 99 for (oid) |char| if (char != '0') return false; 100 return true; 101 } 102 103 // how long the record's payload would be, to keep it within the buffer 104 fn payloadLen(payload: std.json.ObjectMap) !u64 { 105 var discarding = std.Io.Writer.Discarding.init(&.{}); 106 try std.json.Stringify.value(std.json.Value{ .object = payload }, .{}, &discarding.writer); 107 return discarding.fullCount(); 108 } 109 110 // serve a receive-pack and consume any events it pushed to the events branch, 111 // all in one transaction: the push and the views derived from it commit 112 // atomically, and a failed consume cancels the push 113 pub fn receivePackAndConsume( 114 comptime repo_opts: rp.RepoOpts(.xit), 115 io: std.Io, 116 allocator: std.mem.Allocator, 117 repo: *rp.Repo(.xit, repo_opts), 118 reader: *std.Io.Reader, 119 writer: *std.Io.Writer, 120 options: xit.net_server_receive_pack.Options, 121 author: ?evt.CommitAuthor, 122 repo_root_path: []const u8, 123 error_writer: *std.Io.Writer, 124 sess: ?*ssh.SessionCtx, 125 ) !void { 126 const DB = rp.Repo(.xit, repo_opts).DB; 127 const State = rp.Repo(.xit, repo_opts).State; 128 129 var response = xit.net_server_receive_pack.Response.init(allocator); 130 defer response.deinit(); 131 132 var updates = xit.net_server_receive_pack.AppliedRefUpdates.init(allocator); 133 defer updates.deinit(); 134 135 var sideband = progress.Sideband{ .response = &response, .writer = writer, .sess = sess }; 136 const Ctx = struct { 137 updates: *xit.net_server_receive_pack.AppliedRefUpdates, 138 core: *rp.Repo(.xit, repo_opts).Core, 139 io: std.Io, 140 allocator: std.mem.Allocator, 141 reader: *std.Io.Reader, 142 writer: *std.Io.Writer, 143 options: xit.net_server_receive_pack.Options, 144 author: ?evt.CommitAuthor, 145 response: *xit.net_server_receive_pack.Response, 146 repo_root_path: []const u8, 147 error_writer: *std.Io.Writer, 148 sideband: *progress.Sideband, 149 150 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 151 var moment = try DB.HashMap(.read_write).init(cursor.*); 152 const state = State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 153 154 var receive_options = ctx.options; 155 receive_options.applied_ref_updates = ctx.updates; 156 receive_options.deferred_response = ctx.response; 157 try xit.net_server_receive_pack.run(.xit, repo_opts, state, ctx.io, ctx.allocator, ctx.reader, ctx.writer, receive_options, ctx.sideband); 158 try writeReceivedPatches(repo_opts, state, ctx.io, ctx.allocator, ctx.response, ctx.writer); 159 if (ctx.sideband.gone) return error.ClientGone; 160 161 // a repo without an events branch has no events to consume. a 162 // no-op consume must not cancel here, since the push shares the 163 // transaction and must commit regardless. 164 if (null != try rf.readRecur(.xit, repo_opts, state.readOnly(), ctx.io, .{ .ref = evt.events_ref })) { 165 _ = try evt.consumeInTransaction(.repo, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref); 166 try pch.detectMerged(repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, ctx.repo_root_path, ctx.updates.items.items, ctx.error_writer); 167 168 // the revisions the pushed branches cause belong to the push 169 _ = try pch.refreshBranchesInTransaction(.server, repo_opts, state, &moment, ctx.io, ctx.allocator, ctx.updates.items.items, null, ctx.sideband); 170 } 171 172 if (ctx.sideband.gone) return error.ClientGone; 173 174 // the indexes the pushed refs invalidate belong to the push too 175 _ = try find.refreshInTransaction(repo_opts, state, &moment, ctx.io, ctx.allocator, ctx.sideband); 176 var moves: std.ArrayList(srch_cmmt.Move) = .empty; 177 defer moves.deinit(ctx.allocator); 178 for (ctx.updates.items.items) |update| try moves.append(ctx.allocator, .{ .old_oid = update.old_oid, .new_oid = update.new_oid }); 179 _ = try srch_cmmt.refreshInTransaction(repo_opts, state, &moment, ctx.io, ctx.allocator, moves.items, ctx.sideband); 180 181 try writeUndo(repo_opts, state, ctx.io, ctx.allocator, ctx.author, ctx.updates.items.items); 182 } 183 }; 184 185 const result = blk: { 186 try repo.core.db_file.lock(io, .exclusive); 187 defer repo.core.db_file.unlock(io); 188 189 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 190 break :blk history.appendContext( 191 .{ .slot = try history.getSlot(-1) }, 192 Ctx{ 193 .updates = &updates, 194 .core = &repo.core, 195 .io = io, 196 .allocator = allocator, 197 .reader = reader, 198 .writer = writer, 199 .options = options, 200 .author = author, 201 .response = &response, 202 .repo_root_path = repo_root_path, 203 .error_writer = error_writer, 204 .sideband = &sideband, 205 }, 206 ); 207 }; 208 result catch |err| { 209 response.finish(writer, @errorName(err)) catch {}; 210 if (err == error.CancelTransaction) return; 211 return err; 212 }; 213 214 pch.refreshBranches(.server, .xit, repo_opts, io, allocator, repo, updates.items.items, &sideband) catch |err| { 215 serve_common.logError(io, error_writer, "failed to refresh branch patches: {s}\n", .{@errorName(err)}); 216 pch.refreshOpenMergeability(repo_opts, io, allocator, repo, null, &sideband); 217 }; 218 try response.finish(writer, null); 219 } 220 221 pub fn receiveFork( 222 comptime repo_opts: rp.RepoOpts(.xit), 223 io: std.Io, 224 allocator: std.mem.Allocator, 225 fork_repo: *rp.Repo(.xit, repo_opts), 226 target_repo: *rp.Repo(.xit, repo_opts), 227 id: *const [evt.event_id_size * 2]u8, 228 author: evt.CommitAuthor, 229 timestamp: u64, 230 reader: *std.Io.Reader, 231 writer: *std.Io.Writer, 232 error_writer: *std.Io.Writer, 233 sess: ?*ssh.SessionCtx, 234 ) !void { 235 const patch_id = try evt.parseEventId(id); 236 var arena = std.heap.ArenaAllocator.init(allocator); 237 defer arena.deinit(); 238 239 // load the fork and target patch state 240 const fork_moment = evt.currentMoment(repo_opts, fork_repo) catch return error.PatchDataUnavailable; 241 const fork_patch = (try evt.Patch.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, fork_moment, &arena, &patch_id)) orelse return error.PatchDataUnavailable; 242 const target_moment = evt.currentMoment(repo_opts, target_repo) catch |err| switch (err) { 243 error.NotFound => null, 244 else => |other| return other, 245 }; 246 const target_patch = if (target_moment) |moment| 247 try evt.Patch.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, moment, &arena, &patch_id) 248 else 249 null; 250 if (fork_patch.removed and target_patch == null) return error.PatchDataUnavailable; 251 if (target_patch) |patch| { 252 if (!std.mem.eql(u8, patch.author_email orelse "", author.email)) return error.PatchDataUnavailable; 253 if (patch.event.status.kind() == .merged) return error.PatchAlreadyMerged; 254 } 255 const published = target_patch != null; 256 const active_patch = target_patch orelse fork_patch; 257 const title = active_patch.event.title; 258 259 // resolve the target and the newest fork revision 260 const target_branch = active_patch.event.target_branch; 261 const target_oid = (try target_repo.readRef(io, .{ .kind = .head, .name = target_branch })) orelse return error.TargetNotFound; 262 const newest = try evt.PatchRev.readNewest(evt.EventDB(repo_opts.hash), repo_opts.hash, fork_moment, &arena); 263 var revision_id_maybe: ?[evt.event_id_size]u8 = null; 264 var response = xit.net_server_receive_pack.Response.init(allocator); 265 defer response.deinit(); 266 var sideband = progress.Sideband{ .response = &response, .writer = writer, .sess = sess }; 267 268 // execute a transaction that receives the push and materializes its revision 269 const result = blk: { 270 const DB = rp.Repo(.xit, repo_opts).DB; 271 const State = rp.Repo(.xit, repo_opts).State; 272 const Ctx = struct { 273 core: *rp.Repo(.xit, repo_opts).Core, 274 target_core: *rp.Repo(.xit, repo_opts).Core, 275 io: std.Io, 276 allocator: std.mem.Allocator, 277 reader: *std.Io.Reader, 278 writer: *std.Io.Writer, 279 response: *xit.net_server_receive_pack.Response, 280 patch_id: [evt.event_id_size * 2]u8, 281 patch: evt.Patch.Record, 282 published: bool, 283 target_oid: [hash.hexLen(repo_opts.hash)]u8, 284 title: []const u8, 285 author: evt.CommitAuthor, 286 timestamp: u64, 287 newest: ?evt.PatchRev.WithId, 288 revision_id_maybe: *?[evt.event_id_size]u8, 289 sideband: *progress.Sideband, 290 291 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 292 // receive the branch update 293 var moment = try DB.HashMap(.read_write).init(cursor.*); 294 const state = State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 295 try xit.net_server_receive_pack.run(.xit, repo_opts, state, ctx.io, ctx.allocator, ctx.reader, ctx.writer, .{ .allowed_ref = "refs/heads/" ++ fork.ref.name, .deferred_response = ctx.response }, ctx.sideband); 296 try writeReceivedPatches(repo_opts, state, ctx.io, ctx.allocator, ctx.response, ctx.writer); 297 if (ctx.sideband.gone) return error.ClientGone; 298 299 // copy the target history needed to preserve the merge base 300 const source_oid = (try rf.readRecur(.xit, repo_opts, state.readOnly(), ctx.io, .{ .ref = fork.ref })) orelse return error.CancelTransaction; 301 var target_repo_moment = try ctx.target_core.latestMoment(); 302 const target_state = State(.read_only){ .core = ctx.target_core, .extra = .{ .moment = &target_repo_moment } }; 303 var objects = try obj.ObjectIterator(.xit, repo_opts).init(target_state, ctx.io, ctx.allocator, .{ .kind = .all }); 304 defer objects.deinit(); 305 try objects.include(&ctx.target_oid); 306 try obj.copyFromObjectIterator(.xit, repo_opts, state, .xit, repo_opts, &objects, ctx.io, ctx.sideband); 307 308 const base_oid = try mrg.commonAncestor(.xit, repo_opts, state.readOnly(), ctx.io, ctx.allocator, &ctx.target_oid, &source_oid); 309 const existing_revision = if (ctx.newest) |latest| 310 if (std.mem.eql(u8, latest.record.event.base_oid, &base_oid) and 311 std.mem.eql(u8, latest.record.event.source_oid, &source_oid)) latest else null 312 else 313 null; 314 315 // reuse an identical revision or record a new one 316 var revision_arena = std.heap.ArenaAllocator.init(ctx.allocator); 317 defer revision_arena.deinit(); 318 var events: [2]evt.EventWithId = undefined; 319 var event_count: usize = 0; 320 if (existing_revision) |latest| { 321 if (ctx.published) ctx.revision_id_maybe.* = latest.id; 322 } else { 323 const prepared = try evt.PatchRev.prepare(.xit, repo_opts, state, ctx.io, &revision_arena, &base_oid, &source_oid, ctx.title, ctx.author, ctx.timestamp); 324 events[event_count] = prepared.event; 325 event_count += 1; 326 ctx.revision_id_maybe.* = try evt.parseEventId(&prepared.event.id); 327 328 if (!ctx.published) { 329 var patch = ctx.patch.event; 330 patch.revision = prepared.revision; 331 events[event_count] = .{ 332 .id = ctx.patch_id, 333 .timestamp = ctx.timestamp, 334 .author = ctx.author, 335 .event = .{ .patch = patch }, 336 }; 337 event_count += 1; 338 } 339 } 340 341 // published patches keep only revisions in the fork 342 if (ctx.published and !ctx.patch.removed) { 343 events[event_count] = .{ 344 .id = ctx.patch_id, 345 .timestamp = ctx.timestamp, 346 .author = ctx.author, 347 .event = .{ .patch = null }, 348 }; 349 event_count += 1; 350 } 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