╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1375 1376 _ = try pch.refreshBranchesInTransaction(.server, opts, state, &moment, ctx.io, ctx.allocator, null, null, null); 1377 try push.writeUndo(opts, state, ctx.io, ctx.allocator, ctx.author); 1378 } 1379 }; 1380 1381 try transaction(io, repo, Ctx{ .core = &repo.core, .io = io, .allocator = allocator, .author = author }); 1382 } 1383 1384 // commit `events` onto `ref`, rooted at `parent`, as one transaction. 1385 // consume always roots a new branch at nothing, so the divergent fixtures 1386 // write their side branch here instead. nothing is consumed, so it records 1387 // xit's own commit action rather than one of haxy's event actions 1388 fn commitEventsAtRef( 1389 io: std.Io, 1390 allocator: std.mem.Allocator, 1391 repo: *rp.Repo(.xit, .{}), 1392 ref: xit.ref.Ref, 1393 events: []const evt.EventWithId, 1394 parent: [hash.hexLen(.sha1)]u8, 1395 ) !void { 1396 const Repo = rp.Repo(.xit, .{}); 1397 const DB = Repo.DB; 1398 const Ctx = struct { 1399 core: *Repo.Core, 1400 io: std.Io, 1401 allocator: std.mem.Allocator, 1402 ref: xit.ref.Ref, 1403 events: []const evt.EventWithId, 1404 parent: [hash.hexLen(.sha1)]u8, 1405 1406 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1407 const opts: rp.RepoOpts(.xit) = .{}; 1408 var moment = try DB.HashMap(.read_write).init(cursor.*); 1409 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1410 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1411 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1412 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1413 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1414 }); 1415 } 1416 }; 1417 1418 try transaction(io, repo, Ctx{ 1419 .core = &repo.core, 1420 .io = io, 1421 .allocator = allocator, 1422 .ref = ref, 1423 .events = events, 1424 .parent = parent, 1425 }); 1426 } 1427 1428 // append `ctx` to the repo's history as one transaction. the fixtures write a 1429 // few states the normal paths have no way to produce 1430 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1431 const DB = rp.Repo(.xit, .{}).DB; 1432 try repo.core.db_file.lock(io, .exclusive); 1433 defer repo.core.db_file.unlock(io); 1434 1435 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1436 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1437 } 1438 1439 // recursively copy the contents of src_dir into dest_dir 1440 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1441 var iter = src_dir.iterate(); 1442 while (try iter.next(io)) |entry| { 1443 switch (entry.kind) { 1444 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1445 .directory => { 1446 try dest_dir.createDirPath(io, entry.name); 1447 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1448 defer dest_entry_dir.close(io); 1449 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1450 defer src_entry_dir.close(io); 1451 try copyDir(io, src_entry_dir, dest_entry_dir); 1452 }, 1453 else => {}, 1454 } 1455 } 1456 } 1457