╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1349 "I tested both paths:\n\n- the archive path\n- the direct-copy path\n\nBoth currently lose the mode.", 1350 "The `ArchiveWriter` is the right place to centralize it, since every exporter already goes through that layer.", 1351 "Please include a regression fixture with a *mix* of executable and ordinary files.", 1352 "I'll add that fixture and cover both supported archive formats:\n\n1. tar\n2. zip", 1353 }; 1354 var comments: [comment_ids.len]evt.EventWithId = undefined; 1355 for (&comments, 0..) |*comment, i| { 1356 comment.* = .{ 1357 .id = std.fmt.bytesToHex(comment_ids[i], .lower), 1358 .timestamp = seedTimestamp(now, i, comments.len, 2 * std.time.s_per_hour, 45), 1359 .author = .{ .name = if (i % 2 == 0) "alice" else "bobby", .email = if (i % 2 == 0) "alice@example.test" else "bobby@example.test" }, 1360 .event = .{ .comment = .{ 1361 .thread_id = std.fmt.bytesToHex(patch_ids[patch_ids.len - 1], .lower), 1362 .parent_id = switch (i) { 1363 0, 1 => std.fmt.bytesToHex(patch_ids[patch_ids.len - 1], .lower), 1364 2, 4 => std.fmt.bytesToHex(comment_ids[0], .lower), 1365 3 => std.fmt.bytesToHex(comment_ids[2], .lower), 1366 else => unreachable, 1367 }, 1368 .body = comment_bodies[i], 1369 } }, 1370 }; 1371 } 1372 try evt.consume(.{ .server = .{ .users_dir = users_dir } }, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &comments); 1373 1374 // create divergent metadata edits on the next three patches 1375 var patch_arena = std.heap.ArenaAllocator.init(allocator); 1376 defer patch_arena.deinit(); 1377 const moment = try evt.currentMoment(.{}, target_repo); 1378 var values: [3]evt.Patch = undefined; 1379 for (1..4) |i| { 1380 const record = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, &patch_arena, &patch_ids[i])) orelse return error.NotFound; 1381 values[i - 1] = record.event; 1382 } 1383 var ours_values = values; 1384 ours_values[0].title = "Drop the legacy configuration loader"; 1385 ours_values[0].labels = "cleanup config breaking"; 1386 const closed_description = try longDescription( 1387 patch_arena.allocator(), 1388 "## Summary\n\nCache parsed manifests for the lifetime of a command invocation and invalidate entries when their files change.", 1389 ); 1390 ours_values[1].description = closed_description; 1391 ours_values[2].description = "Add JSON output to `inspect` with versioned field names and deterministic object ordering."; 1392 var theirs_values = values; 1393 theirs_values[0].title = "Delete compatibility configuration support"; 1394 theirs_values[0].labels = "config maintenance"; 1395 theirs_values[1].description = "Keep a process-wide manifest cache shared by **every** command and refresh it after writes."; 1396 theirs_values[2].description = "Expose `inspect` results as newline-delimited JSON so callers can stream large repositories."; 1397 1398 const seed_tip = (try target_repo.readRef(io, evt.events_ref)) orelse return error.NotFound; 1399 const other_ref = xit.ref.Ref{ .kind = .head, .name = "haxy/patch-other" }; 1400 var ours = [_]evt.EventWithId{ 1401 .{ 1402 .id = std.fmt.bytesToHex(patch_ids[1], .lower), 1403 .timestamp = now - 30 * std.time.s_per_min, 1404 .author = .{ .name = "alice", .email = "alice@example.test" }, 1405 .event = .{ .patch = ours_values[0] }, 1406 }, 1407 .{ 1408 .id = std.fmt.bytesToHex(patch_ids[2], .lower), 1409 .timestamp = now - 29 * std.time.s_per_min, 1410 .author = .{ .name = "alice", .email = "alice@example.test" }, 1411 .event = .{ .patch = ours_values[1] }, 1412 }, 1413 .{ 1414 .id = std.fmt.bytesToHex(patch_ids[3], .lower), 1415 .timestamp = now - 28 * std.time.s_per_min, 1416 .author = .{ .name = "alice", .email = "alice@example.test" }, 1417 .event = .{ .patch = ours_values[2] }, 1418 }, 1419 }; 1420 1421 var theirs = ours; 1422 theirs[0].timestamp = now - 25 * std.time.s_per_min; 1423 theirs[0].author = .{ .name = "bobby", .email = "bobby@example.test" }; 1424 theirs[0].event.patch = theirs_values[0]; 1425 theirs[1].timestamp = now - 24 * std.time.s_per_min; 1426 theirs[1].author = .{ .name = "bobby", .email = "bobby@example.test" }; 1427 theirs[1].event.patch = theirs_values[1]; 1428 theirs[2].timestamp = now - 23 * std.time.s_per_min; 1429 theirs[2].author = .{ .name = "bobby", .email = "bobby@example.test" }; 1430 theirs[2].event.patch = theirs_values[2]; 1431 1432 try evt.consume(.{ .server = .{ .users_dir = users_dir } }, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &ours); 1433 try commitEventsAtRef(io, allocator, target_repo, other_ref, &theirs, seed_tip); 1434 { 1435 var merge = try target_repo.mergeAtRef(io, allocator, .{ .kind = .full, .action = .{ .new = .{ .source = &.{.{ .ref = other_ref }} } } }, evt.events_ref, null); 1436 defer merge.deinit(); 1437 if (merge.result != .success) return error.MergeFailed; 1438 } 1439 try target_repo.removeBranch(io, .{ .name = other_ref.name }); 1440 try evt.consume(.{ .server = .{ .users_dir = users_dir } }, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &.{}); 1441 try pch.writeBranchPatch(.{ .server = .{ .users_dir = users_dir } }, .xit, .{}, io, allocator, target_repo, std.fmt.bytesToHex(evt.EventWithId.randomId(random), .lower), .{ 1442 .title = "Merge the existing feature branch", 1443 .description = "This patch tracks the `feature` branch in this repo without creating a fork.", 1444 .labels = "feature", 1445 .source_branch = "feature", 1446 .target_branch = "master", 1447 }, null, patch_author); 1448 1449 // a push onto the branch that patch tracks, so the undo tab shows the 1450 // action and the patch refresh it sets off 1451 try seedPush(io, allocator, target_repo, users_dir, patch_author, now - 15); 1452 try pch.refreshBranches(.{ .server = .{ .users_dir = users_dir } }, .xit, .{}, io, allocator, target_repo, null, null); 1453 } 1454 1455 // stand in for a client push, which the fixture has no server to receive: one 1456 // transaction moves the branch, refreshes the patches tracking it and records 1457 // the action, the way receive-pack does 1458 fn seedPush(io: std.Io, allocator: std.mem.Allocator, repo: *rp.Repo(.xit, .{}), users_dir: []const u8, author: evt.CommitAuthor, timestamp: u64) !void { 1459 const Repo = rp.Repo(.xit, .{}); 1460 const DB = Repo.DB; 1461 const Ctx = struct { 1462 core: *Repo.Core, 1463 io: std.Io, 1464 allocator: std.mem.Allocator, 1465 users_dir: []const u8, 1466 author: evt.CommitAuthor, 1467 timestamp: u64, 1468 1469 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1470 const opts: rp.RepoOpts(.xit) = .{}; 1471 var moment = try DB.HashMap(.read_write).init(cursor.*); 1472 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1473 var arena = std.heap.ArenaAllocator.init(ctx.allocator); 1474 defer arena.deinit(); 1475 const aa = arena.allocator(); 1476 1477 // a null tree keeps the parent's content, so the branch advances 1478 // without the fixture having to build one 1479 const author_line = try aa.print("{s} <{s}>", .{ ctx.author.name, ctx.author.email }); 1480 const feature_old = (try rf.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = .{ .kind = .head, .name = "feature" } })) orelse return error.NotFound; 1481 const feature_new = try obj.writeCommit(.xit, opts, state, ctx.io, ctx.allocator, .{ 1482 .message = "Revise the feature branch", 1483 .author = author_line, 1484 .timestamp = ctx.timestamp, 1485 }, null, .{ .kind = .head, .name = "feature" }); 1486 1487 // a branch the push creates has no old tip, so its range is open 1488 try bch.add(.xit, opts, state, ctx.io, .{ .name = "docs" }); 1489 const docs_new = (try rf.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = .{ .kind = .head, .name = "docs" } })) orelse return error.NotFound; 1490 1491 const updates = [_]xit.net_server_receive_pack.AppliedRefUpdate{ 1492 .{ 1493 .ref_name = try aa.dupe(u8, "refs/heads/feature"), 1494 .old_oid = try aa.dupe(u8, &feature_old), 1495 .new_oid = try aa.dupe(u8, &feature_new), 1496 }, 1497 .{ 1498 .ref_name = try aa.dupe(u8, "refs/heads/docs"), 1499 .old_oid = try aa.dupe(u8, &@as([hash.hexLen(opts.hash)]u8, @splat('0'))), 1500 .new_oid = try aa.dupe(u8, &docs_new), 1501 }, 1502 }; 1503 1504 _ = try pch.refreshBranchesInTransaction(.{ .server = .{ .users_dir = ctx.users_dir } }, opts, state, &moment, ctx.io, ctx.allocator, &updates, null, null); 1505 try push.writeUndo(opts, state, ctx.io, ctx.allocator, ctx.author, &updates); 1506 } 1507 }; 1508 1509 try transaction(io, repo, Ctx{ .core = &repo.core, .io = io, .allocator = allocator, .users_dir = users_dir, .author = author, .timestamp = timestamp }); 1510 } 1511 1512 // commit `events` onto `ref`, rooted at `parent`, as one transaction. 1513 // consume always roots a new branch at nothing, so the divergent fixtures 1514 // write their side branch here instead. nothing is consumed, so it records 1515 // xit's own commit action rather than one of haxy's event actions 1516 fn commitEventsAtRef( 1517 io: std.Io, 1518 allocator: std.mem.Allocator, 1519 repo: *rp.Repo(.xit, .{}), 1520 ref: xit.ref.Ref, 1521 events: []const evt.EventWithId, 1522 parent: [hash.hexLen(.sha1)]u8, 1523 ) !void { 1524 const Repo = rp.Repo(.xit, .{}); 1525 const DB = Repo.DB; 1526 const Ctx = struct { 1527 core: *Repo.Core, 1528 io: std.Io, 1529 allocator: std.mem.Allocator, 1530 ref: xit.ref.Ref, 1531 events: []const evt.EventWithId, 1532 parent: [hash.hexLen(.sha1)]u8, 1533 1534 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1535 const opts: rp.RepoOpts(.xit) = .{}; 1536 var moment = try DB.HashMap(.read_write).init(cursor.*); 1537 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1538 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1539 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1540 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1541 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1542 }); 1543 } 1544 }; 1545 1546 try transaction(io, repo, Ctx{ 1547 .core = &repo.core, 1548 .io = io, 1549 .allocator = allocator, 1550 .ref = ref, 1551 .events = events, 1552 .parent = parent, 1553 }); 1554 } 1555 1556 // append `ctx` to the repo's history as one transaction. the fixtures write a 1557 // few states the normal paths have no way to produce 1558 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1559 // no commit index, as in production. 1560 const Reindex = struct { 1561 io: std.Io, 1562 allocator: std.mem.Allocator, 1563 core: *rp.Repo(.xit, .{}).Core, 1564 commits: bool, 1565 1566 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1567 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1568 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1569 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1570 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1571 } 1572 }; 1573 1574 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1575 const DB = rp.Repo(.xit, .{}).DB; 1576 try repo.core.db_file.lock(io, .exclusive); 1577 defer repo.core.db_file.unlock(io); 1578 1579 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1580 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1581 } 1582 1583 // recursively copy the contents of src_dir into dest_dir 1584 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1585 var iter = src_dir.iterate(); 1586 while (try iter.next(io)) |entry| { 1587 switch (entry.kind) { 1588 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1589 .directory => { 1590 try dest_dir.createDirPath(io, entry.name); 1591 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1592 defer dest_entry_dir.close(io); 1593 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1594 defer src_entry_dir.close(io); 1595 try copyDir(io, src_entry_dir, dest_entry_dir); 1596 }, 1597 else => {}, 1598 } 1599 } 1600 } 1601