╭ changed ────╮ │src/patch.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────╮ │← previous│ ╰──────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │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| {│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯