╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ───╮ │src/push.zig│ ╰────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────╮ │387 }; │ │388 } │ │389 │ │390 + response.progress(writer, "Checking merges...\n") catch {}; │ │391 + pch.refreshMergeability(repo_opts, io, allocator, target_repo, patch_id);│ │392 + │ │393 // the client may read either repo as soon as it gets the final response.│ │394 try response.finish(writer, null); │ │395 } │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ───────────────╮ │src/test/event/patch.zig│ ╰────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │757 })); │ │758 try evt.Patch.update(.xit, repo_opts, io, allocator, &target, &patch_id, .{ .status = .open }, author);│ │759 │ │760 + // run the cache scenario once; both lifecycle runs still perform a merge │ │761 + if (merge_revision == .source) { │ │762 + try testMergeability(&target, io, allocator, repos_dir, &patch_id, &base_oid, &source_oid); │ │763 + } │ │764 + │ │765 const selected_oid = switch (merge_revision) { │ │766 .squash => squash_oid, │ │767 .source => source_oid, │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │818 const ids_cursor = try tags.getCursor(try evt.Patch.tagStatusKey(&key_buffer, tag, status)) orelse return 0; │ │819 const ids = try Repo.DB.SortedSet(.read_only).init(ids_cursor); │ │820 return try ids.count(); │ │821 +} │ │822 + │ │823 +fn readMergeability(repo: *Repo, io: std.Io, allocator: std.mem.Allocator, id: *const [evt.event_id_size]u8, patch: evt.Patch) !pch.Mergeability { │ │824 + var arena = std.heap.ArenaAllocator.init(allocator); │ │825 + defer arena.deinit(); │ │826 + var moment = try repo.core.latestMoment(); │ │827 + return pch.readMergeability(repo_opts, .{ .core = &repo.core, .extra = .{ .moment = &moment } }, io, &arena, id, patch); │ │828 +} │ │829 + │ │830 +fn expectMergeabilityShortBytes(moment: Repo.DB.HashMap(.read_only), id: *const [evt.event_id_size]u8) !void { │ │831 + const checks = try Repo.DB.HashMap(.read_only).init((try moment.getCursor(hash.hashInt(repo_opts.hash, "patch-id->mergeability"))) orelse return error.NotFound);│ │832 + const entry = try Repo.DB.HashMap(.read_only).init((try checks.getCursor(hash.hashInt(repo_opts.hash, id))) orelse return error.NotFound); │ │833 + const result = try Repo.DB.HashMap(.read_only).init((try entry.getCursor(hash.hashInt(repo_opts.hash, "result"))) orelse return error.NotFound); │ │834 + for ([_][]const u8{ "source", "squash" }) |field| { │ │835 + const cursor = (try result.getCursor(hash.hashInt(repo_opts.hash, field))) orelse return error.NotFound; │ │836 + try std.testing.expectEqual(.short_bytes, cursor.slot().tag); │ │837 + } │ │838 +} │ │839 + │ │840 +fn testMergeability( │ │841 + target: *Repo, │ │842 + io: std.Io, │ │843 + allocator: std.mem.Allocator, │ │844 + repos_dir: []const u8, │ │845 + id: *const [evt.event_id_size]u8, │ │846 + base: *const [hash.hexLen(repo_opts.hash)]u8, │ │847 + source: *const [hash.hexLen(repo_opts.hash)]u8, │ │848 +) !void { │ │849 + var arena = std.heap.ArenaAllocator.init(allocator); │ │850 + defer arena.deinit(); │ │851 + const events = try evt.currentMoment(repo_opts, target); │ │852 + const record = (try evt.Patch.readById(Repo.DB, repo_opts.hash, events, &arena, id)) orelse return error.NotFound; │ │853 + const patch = record.event; │ │854 + │ │855 + // publication checks both methods, and reads and cache hits do no work │ │856 + const clean = pch.Mergeability{ .source = .clean, .squash = .clean }; │ │857 + try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); │ │858 + try expectMergeabilityShortBytes(try target.core.latestMoment(), id); │ │859 + const before = (try target.core.latestMoment()).cursor.slot(); │ │860 + pch.refreshMergeability(repo_opts, io, allocator, target, id.*); │ │861 + try std.testing.expectEqualDeep(before, (try target.core.latestMoment()).cursor.slot()); │ │862 + { │ │863 + var moment = try target.core.latestMoment(); │ │864 + const state = Repo.State(.read_only){ .core = &target.core, .extra = .{ .moment = &moment } }; │ │865 + try std.testing.expectError(error.ObjectNotFound, obj.Object(.xit, repo_opts).initCommit(state, io, allocator, source)); │ │866 + } │ │867 + const events_before = try target.readRef(io, evt.events_ref); │ │868 + │ │869 + // a target update invalidates the old result before refresh │ │870 + { │ │871 + const file = try target.core.work_dir.createFile(io, "feature.zig", .{ .truncate = true }); │ │872 + defer file.close(io); │ │873 + try file.writeStreamingAll(io, "pub const answer = 99;\n"); │ │874 + } │ │875 + try target.add(io, allocator, &.{"feature.zig"}); │ │876 + const conflicting_target = try target.commit(io, allocator, .{ .message = "different answer", .timestamp = 20 }); │ │877 + const input = pch.MergeInput{ .id = std.fmt.bytesToHex(id.*, .lower), .revision = .source, .author = author, .timestamp = 21 }; │ │878 + var squash_input = input; │ │879 + squash_input.revision = .squash; │ │880 + try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); │ │881 + try std.testing.expectError(error.MergeCheckUnavailable, pch.merge(repo_opts, io, allocator, repos_dir, target, input)); │ │882 + try std.testing.expectError(error.MergeCheckUnavailable, pch.merge(repo_opts, io, allocator, repos_dir, target, squash_input)); │ │883 + pch.refreshMergeability(repo_opts, io, allocator, target, null); │ │884 + try std.testing.expectEqualDeep(pch.Mergeability{ .source = .conflict, .squash = .conflict }, try readMergeability(target, io, allocator, id, patch)); │ │885 + try expectMergeabilityShortBytes(try target.core.latestMoment(), id); │ │886 + try std.testing.expectError(error.MergeConflict, pch.merge(repo_opts, io, allocator, repos_dir, target, input)); │ │887 + try std.testing.expectError(error.MergeConflict, pch.merge(repo_opts, io, allocator, repos_dir, target, squash_input)); │ │888 + try std.testing.expectEqual(events_before, try target.readRef(io, evt.events_ref)); │ │889 + try std.testing.expectEqual(conflicting_target, (try target.readRef(io, .{ .kind = .head, .name = "master" })).?); │ │890 + try std.testing.expectEqual(null, try target.readRef(io, .{ .kind = .none, .name = "MERGE_HEAD" })); │ │891 + │ │892 + // deleting and restoring the target cannot reuse the conflict result │ │893 + { │ │894 + var detached = try target.switchDir(io, allocator, .{ .target = .{ .oid = base } }); │ │895 + defer detached.deinit(); │ │896 + } │ │897 + try target.removeBranch(io, .{ .name = "master" }); │ │898 + pch.refreshMergeability(repo_opts, io, allocator, target, null); │ │899 + try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); │ │900 + try expectMergeabilityShortBytes(try target.core.latestMoment(), id); │ │901 + try target.addBranch(io, .{ .name = "master" }); │ │902 + { │ │903 + var restored = try target.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = "master" } } }); │ │904 + defer restored.deinit(); │ │905 + } │ │906 + pch.refreshMergeability(repo_opts, io, allocator, target, null); │ │907 + try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); │ │908 + │ │909 + // a missing fork disables merging without changing the accepted events │ │910 + const draft_path = try fork.forkPath(allocator, repos_dir, &std.fmt.bytesToHex(id.*, .lower)); │ │911 + defer allocator.free(draft_path); │ │912 + const away_path = try std.fmt.allocPrint(allocator, "{s}.away", .{draft_path}); │ │913 + defer allocator.free(away_path); │ │914 + { │ │915 + try std.Io.Dir.renameAbsolute(draft_path, away_path, io); │ │916 + defer std.Io.Dir.renameAbsolute(away_path, draft_path, io) catch {}; │ │917 + pch.refreshMergeability(repo_opts, io, allocator, target, id.*); │ │918 + try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); │ │919 + try std.testing.expectEqual(events_before, try target.readRef(io, evt.events_ref)); │ │920 + } │ │921 + pch.refreshMergeability(repo_opts, io, allocator, target, id.*); │ │922 + try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); │ │923 + │ │924 + // a changed revision is unknown even if its target has not moved │ │925 + var changed = patch; │ │926 + changed.revision.?.id[0] = if (changed.revision.?.id[0] == 'a') 'b' else 'a'; │ │927 + try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, changed)); │ │928 } │ │929 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ──╮ │src/try.zig│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │960 defer file.close(io); │ │961 try file.writeStreamingAll(io, content); │ │962 } │ │963 + │ │964 +const ScatterEdit = struct { line: usize, text: []const u8 }; │ │965 │ │964 -fn scatterContent(allocator: std.mem.Allocator, fi: usize, c: usize, replacement: ?struct { line: usize, text: []const u8 }) ![]u8 {│ │966 +fn scatterContent(allocator: std.mem.Allocator, fi: usize, c: usize, replacement: ?ScatterEdit) ![]u8 { │ │967 var writer = std.Io.Writer.Allocating.init(allocator); │ │968 defer writer.deinit(); │ │969 for (0..40) |line| { │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────╮ │1111 description: []const u8, │ │1112 tags: []const u8, │ │1113 status: ?evt.Patch.StatusKind, │ │1112 - adjacent_edit: bool = false, │ │1114 + alpha_edit: ?ScatterEdit = null, │ │1115 }{ │ │1116 .{ │ │1117 .title = "Draft a faster dependency scanner",│ ╰───────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1142 .description = "This patch can be cleanly merged by haxy, while git throws a merge conflict!", │ │1143 .tags = "merge", │ │1144 .status = .open, │ │1143 - .adjacent_edit = true, │ │1145 + .alpha_edit = .{ .line = 2, .text = "adjust alpha beside the latest scatter edit" }, │ │1146 }, │ │1147 .{ │ │1146 - .title = "Preserve file permissions during export", │ │1147 - .description = "Carry executable bits through archive exports so unpacked command-line tools remain runnable without a manual chmod step.",│ │1148 - .tags = "bug export permissions", │ │1148 + .title = "Edit a conflicting line in alpha.txt", │ │1149 + .description = "Both source and squash merges conflict with a different edit to the same line on master.", │ │1150 + .tags = "merge", │ │1151 .status = .open, │ │1152 + .alpha_edit = .{ .line = 3, .text = "replace alpha with a conflicting edit" }, │ │1153 }, │ │1154 }; │ │1155 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1181 const aa = arena.allocator(); │ │1182 var base_oid = (try target_repo.readRef(io, .{ .kind = .head, .name = "master" })) orelse return error.NotFound; │ │1183 var contents: [3][]const u8 = undefined; │ │1181 - const file_path: []const u8, const count: usize = if (patch.adjacent_edit) blk: { │ │1184 + const file_path: []const u8, const count: usize = if (patch.alpha_edit) |edit| blk: { │ │1185 // v30 precedes the last scatter commit, even after the sample merge │ │1186 const tag_oid = (try target_repo.readRef(io, .{ .kind = .tag, .name = "v30" })) orelse return error.NotFound;│ │1187 var moment = try target_repo.core.latestMoment(); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1192 .tag => |value| value.target, │ │1193 else => return error.InvalidObject, │ │1194 }; │ │1192 - // rev 29 first changes line 4; edit the line above it in rev 28 │ │1193 - contents[0] = try scatterContent(aa, 0, 28, .{ .line = 2, .text = "adjust alpha beside the latest scatter edit" });│ │1195 + // rev 29 first changes line 4; edit that line or the one above it │ │1196 + contents[0] = try scatterContent(aa, 0, 28, edit); │ │1197 break :blk .{ "src/alpha.txt", 1 }; │ │1198 } else blk: { │ │1199 var writer = std.Io.Writer.Allocating.init(allocator); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1339 } │ │1340 try target_repo.removeBranch(io, .{ .name = other_ref.name }); │ │1341 try evt.consume(.repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &.{});│ │1342 + pch.refreshMergeability(.{}, io, allocator, target_repo, null); │ │1343 } │ │1344 │ │1345 // recursively copy the contents of src_dir into dest_dir │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ──────────────╮ │src/ui/Repo/Patches.zig│ ╰───────────────────────╯ ╭─────────────────────────────────────────────╮ │37 fork_oid: []const u8 = "", │ │38 no_changes: bool = false, │ │39 fork_exists: bool = false, │ │40 + mergeability: pch.Mergeability = .{},│ │41 }; │ │42 │ │43 pub const Entry = PatchWithId; │ ╰─────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯