╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
562 if (cli) { 563 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 564 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 565 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 566 567 const key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 568 defer allocator.free(key_path); 569 570 const Runnable = struct { 571 io: std.Io, 572 key_path: []const u8, 573 574 pub fn run(self: @This()) !void { 575 std.debug.print( 576 \\ 577 \\connect to the TUI with: 578 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 579 \\ 580 \\create a git repo and push over SSH: 581 \\ mkdir -p temp-try/client/test 582 \\ cd temp-try/client/test 583 \\ git init 584 \\ echo "hello" > hello.txt 585 \\ git add hello.txt 586 \\ git commit -m "let there be light" 587 \\ GIT_SSH_COMMAND='ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i {s}' git push localhost:admin/test HEAD:master 588 \\ 589 \\to quit, press enter. 590 \\ 591 , .{self.key_path}); 592 // portable stdin read via std.Io — equivalent to the 593 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 594 // on windows. 595 var buf: [1]u8 = undefined; 596 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 597 _ = stdin_reader.interface.takeByte() catch {}; 598 } 599 }; 600 601 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 602 .data_dir = server_path, 603 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 604 } else { 605 var null_writer = std.Io.Writer.Discarding.init(&.{}); 606 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 607 608 const Runnable = struct { 609 io: std.Io, 610 allocator: std.mem.Allocator, 611 session: *ui.Session, 612 repo: *Repo, 613 614 pub fn run(self: @This()) !void { 615 // launch the TUI 616 try hx.ui.run(self.io, self.allocator, self.session, self.repo); 617 } 618 }; 619 620 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 621 .data_dir = server_path, 622 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 623 } 624 } 625 626 // words cycled through to pad generated lines into prose-like content 627 const scatter_words = [_][]const u8{ 628 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 629 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 630 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 631 "scatter", "gather", "encode", "decode", "render", "commit", 632 }; 633 634 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 635 // index `fi` shift which lines change and the words used, so each (c, fi) 636 // yields a distinct multi-hunk diff against the previous revision. untouched 637 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 638 // small hunks rather than a full rewrite. 639 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 640 const file = try repo_dir.createFile(io, path, .{}); 641 defer file.close(io); 642 var writer = std.Io.Writer.Allocating.init(allocator); 643 defer writer.deinit(); 644 for (0..40) |line| { 645 const start = writer.written().len; 646 if ((line + fi + c) % 8 == 0) { 647 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 648 try writer.writer.print("rev {d} {s}", .{ c, tag }); 649 } 650 const target = 40 + (line * 17 + fi * 23) % 70; 651 var w = line + fi; 652 while (true) : (w += 1) { 653 const word = scatter_words[w % scatter_words.len]; 654 const len = writer.written().len - start; 655 if (len >= target or len + 1 + word.len > 120) break; 656 if (len == 0) 657 try writer.writer.print("{s}", .{word}) 658 else 659 try writer.writer.print(" {s}", .{word}); 660 } 661 try writer.writer.writeByte('\n'); 662 } 663 try file.writeStreamingAll(io, writer.written()); 664 } 665 666 // tag the current HEAD as the next sequential version: v1, v2, and so on 667 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 668 var buf: [16]u8 = undefined; 669 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 670 _ = try repo.addTag(io, allocator, .{ .name = name }); 671 n.* += 1; 672 } 673 674 // recursively copy the contents of src_dir into dest_dir 675 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 676 var iter = src_dir.iterate(); 677 while (try iter.next(io)) |entry| { 678 switch (entry.kind) { 679 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 680 .directory => { 681 try dest_dir.createDirPath(io, entry.name); 682 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 683 defer dest_entry_dir.close(io); 684 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 685 defer src_entry_dir.close(io); 686 try copyDir(io, src_entry_dir, dest_entry_dir); 687 }, 688 else => {}, 689 } 690 } 691 } 692