╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
1197 const events = try evt.currentMoment(repo_opts, target); 1198 const record = (try evt.Patch.readById(Repo.DB, repo_opts.hash, events, &arena, id)) orelse return error.NotFound; 1199 const patch = record.event; 1200 1201 // publication checks both methods, and reads and cache hits do no work 1202 const clean = pch.Mergeability{ .source = .clean, .squash = .clean }; 1203 try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); 1204 try expectMergeabilityShortBytes(try target.core.latestMoment(), id); 1205 const before = (try target.core.latestMoment()).cursor.slot(); 1206 pch.refreshMergeability(repo_opts, io, allocator, target, users_dir, id.*); 1207 try std.testing.expectEqualDeep(before, (try target.core.latestMoment()).cursor.slot()); 1208 { 1209 var moment = try target.core.latestMoment(); 1210 const state = Repo.State(.read_only){ .core = &target.core, .extra = .{ .moment = &moment } }; 1211 try std.testing.expectError(error.ObjectNotFound, obj.Object(.xit, repo_opts).initCommit(state, io, allocator, source)); 1212 } 1213 1214 // a target update invalidates the old result before refresh 1215 { 1216 const file = try target.core.work_dir.createFile(io, "feature.zig", .{ .truncate = true }); 1217 defer file.close(io); 1218 try file.writeStreamingAll(io, "pub const answer = 99;\n"); 1219 } 1220 try target.add(io, allocator, &.{"feature.zig"}); 1221 const conflicting_target = try target.commit(io, allocator, .{ .message = "different answer", .timestamp = 20 }); 1222 const input = pch.MergeInput{ .id = std.fmt.bytesToHex(id.*, .lower), .revision = .source, .author = author, .timestamp = 21 }; 1223 var squash_input = input; 1224 squash_input.revision = .squash; 1225 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1226 try std.testing.expectError(error.MergeCheckUnavailable, pch.merge(repo_opts, io, allocator, .{ .users_dir = users_dir }, target, input)); 1227 try std.testing.expectError(error.MergeCheckUnavailable, pch.merge(repo_opts, io, allocator, .{ .users_dir = users_dir }, target, squash_input)); 1228 1229 // local edits and server comments leave checks alone 1230 var edit = evt.Patch.Update{ .fields = .{ 1231 .title = "edit the answer", 1232 .labels = patch.labels, 1233 .description = patch.description, 1234 .target_branch = patch.target_branch, 1235 } }; 1236 try evt.Patch.update(.local, .xit, repo_opts, io, allocator, target, id, edit, author); 1237 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1238 _ = try evt.Comment.create(.{ .server = .{ .users_dir = users_dir } }, .xit, repo_opts, io, allocator, target, .patch, &input.id, &input.id, "reviewing the answer", author); 1239 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1240 1241 // a server patch edit refreshes its mergeability 1242 edit.fields.title = patch.title; 1243 const before_edit = try target.core.db.rootCursor().count(); 1244 try evt.Patch.update(.{ .server = .{ .users_dir = users_dir } }, .xit, repo_opts, io, allocator, target, id, edit, author); 1245 try std.testing.expectEqual(before_edit + 1, try target.core.db.rootCursor().count()); 1246 const events_before = try target.readRef(io, evt.events_ref); 1247 try std.testing.expectEqualDeep(pch.Mergeability{ .source = .conflict, .squash = .conflict }, try readMergeability(target, io, allocator, id, patch)); 1248 try expectMergeabilityShortBytes(try target.core.latestMoment(), id); 1249 try std.testing.expectError(error.MergeConflict, pch.merge(repo_opts, io, allocator, .{ .users_dir = users_dir }, target, input)); 1250 try std.testing.expectError(error.MergeConflict, pch.merge(repo_opts, io, allocator, .{ .users_dir = users_dir }, target, squash_input)); 1251 try std.testing.expectEqual(events_before, try target.readRef(io, evt.events_ref)); 1252 try std.testing.expectEqual(conflicting_target, (try target.readRef(io, .{ .kind = .head, .name = "master" })).?); 1253 try std.testing.expectEqual(null, try target.readRef(io, .{ .kind = .none, .name = "MERGE_HEAD" })); 1254 1255 // deleting and restoring the target cannot reuse the conflict result 1256 { 1257 var detached = try target.switchDir(io, allocator, .{ .target = .{ .oid = base } }); 1258 defer detached.deinit(); 1259 } 1260 try target.removeBranch(io, .{ .name = "master" }); 1261 pch.refreshOpenMergeability(repo_opts, io, allocator, target, users_dir, null, null); 1262 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1263 try expectMergeabilityShortBytes(try target.core.latestMoment(), id); 1264 try target.addBranch(io, .{ .name = "master" }); 1265 { 1266 var restored = try target.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = "master" } } }); 1267 defer restored.deinit(); 1268 } 1269 pch.refreshOpenMergeability(repo_opts, io, allocator, target, users_dir, null, null); 1270 try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); 1271 1272 // a missing fork disables merging without changing the accepted events 1273 const draft_path = try fork.forkPath(allocator, users_dir, forker_id, id); 1274 defer allocator.free(draft_path); 1275 const away_path = try allocator.print("{s}.away", .{draft_path}); 1276 defer allocator.free(away_path); 1277 { 1278 try std.Io.Dir.renameAbsolute(draft_path, away_path, io); 1279 defer std.Io.Dir.renameAbsolute(away_path, draft_path, io) catch {}; 1280 { 1281 const log_level = std.testing.log_level; 1282 std.testing.log_level = .err; 1283 defer std.testing.log_level = log_level; 1284 try std.testing.expectError(error.PatchDataUnavailable, pch.merge(repo_opts, io, allocator, .{ .users_dir = users_dir }, target, input)); 1285 } 1286 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1287 try std.testing.expectEqual(events_before, try target.readRef(io, evt.events_ref)); 1288 } 1289 pch.refreshMergeability(repo_opts, io, allocator, target, users_dir, id.*); 1290 try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); 1291 1292 // a changed revision is unknown even if its target has not moved 1293 var changed = patch; 1294 changed.revision.?.id[0] = if (changed.revision.?.id[0] == 'a') 'b' else 'a'; 1295 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, changed)); 1296 } 1297