╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1433 }, null, .{ .kind = .head, .name = "feature" }); 1434 1435 // a branch the push creates has no old tip, so its range is open 1436 try bch.add(.xit, opts, state, ctx.io, .{ .name = "docs" }); 1437 const docs_new = (try rf.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = .{ .kind = .head, .name = "docs" } })) orelse return error.NotFound; 1438 1439 const updates = [_]xit.net_server_receive_pack.AppliedRefUpdate{ 1440 .{ 1441 .ref_name = try aa.dupe(u8, "refs/heads/feature"), 1442 .old_oid = try aa.dupe(u8, &feature_old), 1443 .new_oid = try aa.dupe(u8, &feature_new), 1444 }, 1445 .{ 1446 .ref_name = try aa.dupe(u8, "refs/heads/docs"), 1447 .old_oid = try aa.dupe(u8, "0" ** hash.hexLen(opts.hash)), 1448 .new_oid = try aa.dupe(u8, &docs_new), 1449 }, 1450 }; 1451 1452 _ = try pch.refreshBranchesInTransaction(.{ .server = .{ .users_dir = ctx.users_dir } }, opts, state, &moment, ctx.io, ctx.allocator, &updates, null, null); 1453 try push.writeUndo(opts, state, ctx.io, ctx.allocator, ctx.author, &updates); 1454 } 1455 }; 1456 1457 try transaction(io, repo, Ctx{ .core = &repo.core, .io = io, .allocator = allocator, .users_dir = users_dir, .author = author }); 1458 } 1459 1460 // commit `events` onto `ref`, rooted at `parent`, as one transaction. 1461 // consume always roots a new branch at nothing, so the divergent fixtures 1462 // write their side branch here instead. nothing is consumed, so it records 1463 // xit's own commit action rather than one of haxy's event actions 1464 fn commitEventsAtRef( 1465 io: std.Io, 1466 allocator: std.mem.Allocator, 1467 repo: *rp.Repo(.xit, .{}), 1468 ref: xit.ref.Ref, 1469 events: []const evt.EventWithId, 1470 parent: [hash.hexLen(.sha1)]u8, 1471 ) !void { 1472 const Repo = rp.Repo(.xit, .{}); 1473 const DB = Repo.DB; 1474 const Ctx = struct { 1475 core: *Repo.Core, 1476 io: std.Io, 1477 allocator: std.mem.Allocator, 1478 ref: xit.ref.Ref, 1479 events: []const evt.EventWithId, 1480 parent: [hash.hexLen(.sha1)]u8, 1481 1482 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1483 const opts: rp.RepoOpts(.xit) = .{}; 1484 var moment = try DB.HashMap(.read_write).init(cursor.*); 1485 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1486 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1487 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1488 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1489 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1490 }); 1491 } 1492 }; 1493 1494 try transaction(io, repo, Ctx{ 1495 .core = &repo.core, 1496 .io = io, 1497 .allocator = allocator, 1498 .ref = ref, 1499 .events = events, 1500 .parent = parent, 1501 }); 1502 } 1503 1504 // append `ctx` to the repo's history as one transaction. the fixtures write a 1505 // few states the normal paths have no way to produce 1506 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1507 // no commit index, as in production. 1508 const Reindex = struct { 1509 io: std.Io, 1510 allocator: std.mem.Allocator, 1511 core: *rp.Repo(.xit, .{}).Core, 1512 commits: bool, 1513 1514 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1515 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1516 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1517 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1518 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1519 } 1520 }; 1521 1522 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1523 const DB = rp.Repo(.xit, .{}).DB; 1524 try repo.core.db_file.lock(io, .exclusive); 1525 defer repo.core.db_file.unlock(io); 1526 1527 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1528 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1529 } 1530 1531 // recursively copy the contents of src_dir into dest_dir 1532 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1533 var iter = src_dir.iterate(); 1534 while (try iter.next(io)) |entry| { 1535 switch (entry.kind) { 1536 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1537 .directory => { 1538 try dest_dir.createDirPath(io, entry.name); 1539 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1540 defer dest_entry_dir.close(io); 1541 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1542 defer src_entry_dir.close(io); 1543 try copyDir(io, src_entry_dir, dest_entry_dir); 1544 }, 1545 else => {}, 1546 } 1547 } 1548 } 1549