╭ 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 _ = try srch_cmmt.refreshInTransaction(repo_opts, state, &moment, ctx.io, ctx.allocator, ctx.updates.items.items, ctx.sideband); 177 178 try writeUndo(repo_opts, state, ctx.io, ctx.allocator, ctx.author, ctx.updates.items.items); 179 } 180 }; 181 182 const result = blk: { 183 try repo.core.db_file.lock(io, .exclusive); 184 defer repo.core.db_file.unlock(io); 185 186 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 187 break :blk history.appendContext( 188 .{ .slot = try history.getSlot(-1) }, 189 Ctx{ 190 .updates = &updates, 191 .core = &repo.core, 192 .io = io, 193 .allocator = allocator, 194 .reader = reader, 195 .writer = writer, 196 .options = options, 197 .author = author, 198 .response = &response, 199 .repo_root_path = repo_root_path, 200 .error_writer = error_writer, 201 .sideband = &sideband, 202 }, 203 ); 204 }; 205 result catch |err| { 206 response.finish(writer, @errorName(err)) catch {}; 207 if (err == error.CancelTransaction) return; 208 return err; 209 }; 210 211 pch.refreshBranches(.server, .xit, repo_opts, io, allocator, repo, updates.items.items, &sideband) catch |err| { 212 serve_common.logError(io, error_writer, "failed to refresh branch patches: {s}\n", .{@errorName(err)}); 213 pch.refreshOpenMergeability(repo_opts, io, allocator, repo, null, &sideband); 214 }; 215 try response.finish(writer, null); 216 } 217 218 pub fn receiveFork( 219 comptime repo_opts: rp.RepoOpts(.xit), 220 io: std.Io, 221 allocator: std.mem.Allocator, 222 fork_repo: *rp.Repo(.xit, repo_opts), 223 target_repo: *rp.Repo(.xit, repo_opts), 224 id: *const [evt.event_id_size * 2]u8, 225 author: evt.CommitAuthor, 226 timestamp: u64, 227 reader: *std.Io.Reader, 228 writer: *std.Io.Writer, 229 error_writer: *std.Io.Writer, 230 sess: ?*ssh.SessionCtx, 231 ) !void { 232 const patch_id = try evt.parseEventId(id); 233 var arena = std.heap.ArenaAllocator.init(allocator); 234 defer arena.deinit(); 235 236 // load the fork and target patch state 237 const fork_moment = evt.currentMoment(repo_opts, fork_repo) catch return error.PatchDataUnavailable; 238 const fork_patch = (try evt.Patch.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, fork_moment, &arena, &patch_id)) orelse return error.PatchDataUnavailable; 239 const target_moment = evt.currentMoment(repo_opts, target_repo) catch |err| switch (err) { 240 error.NotFound => null, 241 else => |other| return other, 242 }; 243 const target_patch = if (target_moment) |moment| 244 try evt.Patch.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, moment, &arena, &patch_id) 245 else 246 null; 247 if (fork_patch.removed and target_patch == null) return error.PatchDataUnavailable; 248 if (target_patch) |patch| { 249 if (!std.mem.eql(u8, patch.author_email orelse "", author.email)) return error.PatchDataUnavailable; 250 if (patch.event.status.kind() == .merged) return error.PatchAlreadyMerged; 251 } 252 const published = target_patch != null; 253 const active_patch = target_patch orelse fork_patch; 254 const title = active_patch.event.title; 255 256 // resolve the target and the newest fork revision 257 const target_branch = active_patch.event.target_branch; 258 const target_oid = (try target_repo.readRef(io, .{ .kind = .head, .name = target_branch })) orelse return error.TargetNotFound; 259 const newest = try evt.PatchRev.readNewest(evt.EventDB(repo_opts.hash), repo_opts.hash, fork_moment, &arena); 260 var revision_id_maybe: ?[evt.event_id_size]u8 = null; 261 var response = xit.net_server_receive_pack.Response.init(allocator); 262 defer response.deinit(); 263 var sideband = progress.Sideband{ .response = &response, .writer = writer, .sess = sess }; 264 265 // execute a transaction that receives the push and materializes its revision 266 const result = blk: { 267 const DB = rp.Repo(.xit, repo_opts).DB; 268 const State = rp.Repo(.xit, repo_opts).State; 269 const Ctx = struct { 270 core: *rp.Repo(.xit, repo_opts).Core, 271 target_core: *rp.Repo(.xit, repo_opts).Core, 272 io: std.Io, 273 allocator: std.mem.Allocator, 274 reader: *std.Io.Reader, 275 writer: *std.Io.Writer, 276 response: *xit.net_server_receive_pack.Response, 277 patch_id: [evt.event_id_size * 2]u8, 278 patch: evt.Patch.Record, 279 published: bool, 280 target_oid: [hash.hexLen(repo_opts.hash)]u8, 281 title: []const u8, 282 author: evt.CommitAuthor, 283 timestamp: u64, 284 newest: ?evt.PatchRev.WithId, 285 revision_id_maybe: *?[evt.event_id_size]u8, 286 sideband: *progress.Sideband, 287 288 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 289 // receive the branch update 290 var moment = try DB.HashMap(.read_write).init(cursor.*); 291 const state = State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 292 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); 293 try writeReceivedPatches(repo_opts, state, ctx.io, ctx.allocator, ctx.response, ctx.writer); 294 if (ctx.sideband.gone) return error.ClientGone; 295 296 // copy the target history needed to preserve the merge base 297 const source_oid = (try rf.readRecur(.xit, repo_opts, state.readOnly(), ctx.io, .{ .ref = fork.ref })) orelse return error.CancelTransaction; 298 var target_repo_moment = try ctx.target_core.latestMoment(); 299 const target_state = State(.read_only){ .core = ctx.target_core, .extra = .{ .moment = &target_repo_moment } }; 300 var objects = try obj.ObjectIterator(.xit, repo_opts).init(target_state, ctx.io, ctx.allocator, .{ .kind = .all }); 301 defer objects.deinit(); 302 try objects.include(&ctx.target_oid); 303 try obj.copyFromObjectIterator(.xit, repo_opts, state, .xit, repo_opts, &objects, ctx.io, ctx.sideband); 304 305 const base_oid = try mrg.commonAncestor(.xit, repo_opts, state.readOnly(), ctx.io, ctx.allocator, &ctx.target_oid, &source_oid); 306 const existing_revision = if (ctx.newest) |latest| 307 if (std.mem.eql(u8, latest.record.event.base_oid, &base_oid) and 308 std.mem.eql(u8, latest.record.event.source_oid, &source_oid)) latest else null 309 else 310 null; 311 312 // reuse an identical revision or record a new one 313 var revision_arena = std.heap.ArenaAllocator.init(ctx.allocator); 314 defer revision_arena.deinit(); 315 var events: [2]evt.EventWithId = undefined; 316 var event_count: usize = 0; 317 if (existing_revision) |latest| { 318 if (ctx.published) ctx.revision_id_maybe.* = latest.id; 319 } else { 320 const prepared = try evt.PatchRev.prepare(.xit, repo_opts, state, ctx.io, &revision_arena, &base_oid, &source_oid, ctx.title, ctx.author, ctx.timestamp); 321 events[event_count] = prepared.event; 322 event_count += 1; 323 ctx.revision_id_maybe.* = try evt.parseEventId(&prepared.event.id); 324 325 if (!ctx.published) { 326 var patch = ctx.patch.event; 327 patch.revision = prepared.revision; 328 events[event_count] = .{ 329 .id = ctx.patch_id, 330 .timestamp = ctx.timestamp, 331 .author = ctx.author, 332 .event = .{ .patch = patch }, 333 }; 334 event_count += 1; 335 } 336 } 337 338 // published patches keep only revisions in the fork 339 if (ctx.published and !ctx.patch.removed) { 340 events[event_count] = .{ 341 .id = ctx.patch_id, 342 .timestamp = ctx.timestamp, 343 .author = ctx.author, 344 .event = .{ .patch = null }, 345 }; 346 event_count += 1; 347 } 348 349 // commit and index any new events 350 if (event_count > 0) { 351 try evt.commitEvents(.xit, repo_opts, state, ctx.io, ctx.allocator, evt.events_ref, events[0..event_count], null); 352 if (!try evt.consumeInTransaction(.fork, .xit, repo_opts, state, &ctx.core.db, &moment, ctx.io, ctx.allocator, evt.events_ref)) return error.CancelTransaction; 353 } 354 // a fork push tracks no ref updates, so it records no ranges 355 try writeUndo(repo_opts, state, ctx.io, ctx.allocator, ctx.author, &.{}); 356 } 357 }; 358 359 try fork_repo.core.db_file.lock(io, .exclusive); 360 defer fork_repo.core.db_file.unlock(io); 361 362 const history = try DB.ArrayList(.read_write).init(fork_repo.core.db.rootCursor()); 363 break :blk history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 364 .core = &fork_repo.core, 365 .target_core = &target_repo.core, 366 .io = io, 367 .allocator = allocator, 368 .reader = reader, 369 .writer = writer, 370 .response = &response, 371 .patch_id = id.*, 372 .patch = fork_patch, 373 .published = published, 374 .target_oid = target_oid, 375 .title = title, 376 .author = author, 377 .timestamp = timestamp, 378 .newest = newest, 379 .revision_id_maybe = &revision_id_maybe, 380 .sideband = &sideband, 381 }); 382 }; 383 result catch |err| { 384 response.finish(writer, @errorName(err)) catch {}; 385 if (err == error.CancelTransaction) return; 386 return err; 387 }; 388 389 find.refresh(repo_opts, io, allocator, fork_repo) catch |err| { 390 serve_common.logError(io, error_writer, "failed to refresh file index: {s}\n", .{@errorName(err)}); 391 }; 392 if (!published) return response.finish(writer, null); 393 394 sideband.run(io, .{ .text = "Updating patches" }) catch {}; 395 sideband.run(io, .{ .start = .{ .kind = .writing_patch, .estimated_total_items = 1 } }) catch {}; 396 397 // best-effort update the published patch so it has the new revision 398 var refreshed = false; 399 update: { 400 const revision_id = revision_id_maybe orelse break :update; 401 var update_arena = std.heap.ArenaAllocator.init(allocator); 402 defer update_arena.deinit(); 403 const target_update_moment = evt.currentMoment(repo_opts, target_repo) catch break :update; 404 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; 405 if (published_patch.removed) break :update; 406 const fork_update_moment = evt.currentMoment(repo_opts, fork_repo) catch break :update; 407 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; 408 if (revision.removed) break :update; 409 const selected = evt.Patch.Revision.fromRecord(revision_id, revision); 410 if (published_patch.event.revision) |current| { 411 if (evt.fieldEqual(evt.Patch.Revision, current, selected)) break :update; 412 } 413 var patch = published_patch.event; 414 patch.revision = selected; 415 evt.consume(.server, .repo, .xit, repo_opts, io, allocator, target_repo, evt.events_ref, &.{.{ 416 .id = id.*, 417 .timestamp = timestamp, 418 .author = author, 419 .event = .{ .patch = patch }, 420 }}) catch |update_err| { 421 serve_common.logError(io, error_writer, "failed to update published patch {s}: {s}\n", .{ id, @errorName(update_err) }); 422 break :update; 423 }; 424 // consume also refreshed mergeability 425 refreshed = true; 426 } 427 428 if (!refreshed) pch.refreshMergeability(repo_opts, io, allocator, target_repo, patch_id); 429 sideband.run(io, .{ .complete_one = .writing_patch }) catch {}; 430 sideband.run(io, .{ .end = .writing_patch }) catch {}; 431 432 // the client may read either repo as soon as it gets the final response. 433 try response.finish(writer, null); 434 } 435