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