╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ────╮ │src/patch.zig│ ╰─────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1105 defer event_object.deinit(); │ │1106 const original_author = try commitAuthor(event_object.content.commit.metadata.author orelse return false);│ │1107 │ │1108 + // retain the submitted revision if the target has not imported it yet. │ │1109 var events_buffer: [3]evt.EventWithId = undefined; │ │1110 var events: std.ArrayList(evt.EventWithId) = .initBuffer(&events_buffer); │ │1111 var tree_entries: [2]evt.EventTreeEntry = undefined; │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1127 if (!selected.matches(existing)) return error.InvalidPatch; │ │1128 } │ │1129 │ │ 892 - const author = merged_author orelse original_author; │ │ 893 - const timestamp = if (merged_author != null) merged_timestamp else @as(u64, @intCast(std.Io.Timestamp.now(io, .real).toSeconds())); │ │ 894 - var patch = patch_record.event; │ │ 895 - const result = try evt.PatchRev.prepare(.xit, repo_opts, state, io, &arena, merged.before_oid, merged.after_oid, patch.title, author, timestamp); │ │ 896 - events.appendAssumeCapacity(result.event); │ │ 897 - patch.status = .{ .merged = .{ .revision = merged.revision, .patchrev_id = result.event.id } }; │ │ 898 - events.appendAssumeCapacity(.{ │ │ 899 - .id = std.fmt.bytesToHex(patch_id.*, .lower), │ │ 900 - .timestamp = timestamp, │ │ 901 - .author = author, │ │ 902 - .event = .{ .patch = patch }, │ │ 903 - }); │ │1130 + // snapshot the merge result and mark the patch as merged. │ │1131 + { │ │1132 + const author = merged_author orelse original_author; │ │1133 + const timestamp = if (merged_author != null) merged_timestamp else @as(u64, @intCast(std.Io.Timestamp.now(io, .real).toSeconds())); │ │1134 + var patch = patch_record.event; │ │1135 + const result = try evt.PatchRev.prepare(.xit, repo_opts, state, io, &arena, merged.before_oid, merged.after_oid, patch.title, author, timestamp);│ │1136 + events.appendAssumeCapacity(result.event); │ │1137 + patch.status = .{ .merged = .{ .revision = merged.revision, .patchrev_id = result.event.id } }; │ │1138 + events.appendAssumeCapacity(.{ │ │1139 + .id = std.fmt.bytesToHex(patch_id.*, .lower), │ │1140 + .timestamp = timestamp, │ │1141 + .author = author, │ │1142 + .event = .{ .patch = patch }, │ │1143 + }); │ │1144 + } │ │1145 │ │1146 + // commit and consume the revision and patch events together. │ │1147 try evt.commitEvents(.xit, repo_opts, state, io, allocator, evt.events_ref, events.items, null); │ │1148 if (!try evt.consumeInTransaction(.repo, .xit, repo_opts, state, db, moment, io, allocator, evt.events_ref)) return error.CancelTransaction; │ │1149 return true; │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1165 var arena = std.heap.ArenaAllocator.init(allocator); │ │1166 defer arena.deinit(); │ │1167 │ │1168 + // read the revision index used to identify merged patches. │ │1169 const haxy_moment = try evt.currentMomentFromRepoMoment(repo_opts.hash, moment.readOnly()); │ │1170 const revisions_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.revision_to_id_set_key)) orelse return;│ │1171 const revisions = try DB.HashMap(.read_only).init(revisions_cursor); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────╮ │1172 + │ │1173 + // ignore event refs and inspect only changed branch tips. │ │1174 var events_ref_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; │ │1175 const events_ref_path = try evt.events_ref.toPath(&events_ref_buffer);│ │1176 const heads_prefix = "refs/heads/"; │ ╰────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────╮ │1178 if (!std.mem.startsWith(u8, update.ref_name, heads_prefix) or │ │1179 std.mem.eql(u8, update.ref_name, events_ref_path) or │ │1180 std.mem.eql(u8, update.old_oid, update.new_oid)) continue; │ │1181 + │ │1182 + // validate the ref tips and skip branch deletions. │ │1183 if (update.old_oid.len != hash.hexLen(repo_opts.hash) or │ │1184 update.new_oid.len != hash.hexLen(repo_opts.hash)) return error.InvalidOid;│ │1185 var old_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1188 @memcpy(&new_oid, update.new_oid); │ │1189 if (std.mem.allEqual(u8, &new_oid, '0')) continue; │ │1190 │ │1191 + // traverse commits introduced by this branch update. │ │1192 var commits = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit });│ │1193 defer commits.deinit(); │ │1194 if (!std.mem.allEqual(u8, &old_oid, '0')) try commits.exclude(&old_oid); │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1196 before_oid: [hash.hexLen(repo_opts.hash)]u8, │ │1197 after_oid: [hash.hexLen(repo_opts.hash)]u8, │ │1198 }) = .empty; │ │1199 + │ │1200 + // collect merge boundaries along the target's first-parent history. │ │1201 { │ │1202 var first_parents = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit, .first_parent = true });│ │1203 defer first_parents.deinit(); │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1219 try commits.include(&target.after_oid); │ │1220 while (try commits.next(arena.allocator())) |commit| { │ │1221 defer commit.deinit(); │ │1222 + │ │1223 + // find patches whose selected revision matches this commit. │ │1224 const key = try std.fmt.bufPrint(&revision_key_buffer, "{s}\x00{s}", .{ update.ref_name[heads_prefix.len..], &commit.oid });│ │1225 const ids_cursor = try revisions.getCursor(hash.hashInt(repo_opts.hash, key)) orelse continue; │ │1226 const ids = try DB.CountedHashSet(.read_only).init(ids_cursor); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1230 var patch_id: [evt.event_id_size]u8 = undefined; │ │1231 if ((try pair.key_cursor.readBytes(&patch_id)).len != patch_id.len) return error.InvalidPatch; │ │1232 const patch_hex = std.fmt.bytesToHex(patch_id, .lower); │ │1233 + │ │1234 // a fast-forward has no recorded merge boundary; use the old ref tip │ │1235 const before_oid = if (std.mem.eql(u8, &commit.oid, &target.after_oid)) &old_oid else &target.before_oid; │ │1236 importMerged(repo_opts, state, db, moment, io, allocator, repo_root_path, &patch_id, &commit.oid, before_oid, &target.after_oid) catch |err| {│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ────────╮ │src/serve_ssh.zig│ ╰─────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │291 continue; │ │292 }, │ │293 .sync_events => {}, │ │294 - .undo => |target| try ui.Repo.Undo.perform(allocator, &ui_session, target), │ │294 + .undo => |target| ui.Repo.Undo.handleRequest(allocator, &ui_session, target),│ │295 } │ │296 } │ │297 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯