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