╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
601 defer data_dir.close(io); 602 const store = try hx.web.SessionStore.init(io, data_dir); 603 defer store.deinit(); 604 const token = try store.create(&admin_user_id); 605 try store.offerAutoLogin(&token); 606 } 607 608 if (cli) { 609 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 610 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 611 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 612 613 const key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 614 defer allocator.free(key_path); 615 616 const Runnable = struct { 617 io: std.Io, 618 key_path: []const u8, 619 620 pub fn run(self: @This()) !void { 621 std.debug.print( 622 \\ 623 \\connect to the TUI with: 624 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 625 \\ 626 \\create a git repo and push over SSH: 627 \\ mkdir -p temp-try/client/test 628 \\ cd temp-try/client/test 629 \\ git init 630 \\ echo "hello" > hello.txt 631 \\ git add hello.txt 632 \\ git commit -m "let there be light" 633 \\ 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 634 \\ 635 \\to quit, press enter. 636 \\ 637 , .{self.key_path}); 638 // portable stdin read via std.Io — equivalent to the 639 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 640 // on windows. 641 var buf: [1]u8 = undefined; 642 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 643 _ = stdin_reader.interface.takeByte() catch {}; 644 } 645 }; 646 647 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 648 .data_dir = server_path, 649 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 650 } else { 651 var null_writer = std.Io.Writer.Discarding.init(&.{}); 652 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 653 654 const Runnable = struct { 655 io: std.Io, 656 allocator: std.mem.Allocator, 657 session: *ui.Session, 658 repo: *Repo, 659 660 pub fn run(self: @This()) !void { 661 // launch the TUI 662 try hx.ui.run(self.io, self.allocator, self.session, self.repo); 663 } 664 }; 665 666 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 667 .data_dir = server_path, 668 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 669 } 670 } 671 672 // words cycled through to pad generated lines into prose-like content 673 const scatter_words = [_][]const u8{ 674 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 675 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 676 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 677 "scatter", "gather", "encode", "decode", "render", "commit", 678 }; 679 680 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 681 // index `fi` shift which lines change and the words used, so each (c, fi) 682 // yields a distinct multi-hunk diff against the previous revision. untouched 683 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 684 // small hunks rather than a full rewrite. 685 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 686 const file = try repo_dir.createFile(io, path, .{}); 687 defer file.close(io); 688 var writer = std.Io.Writer.Allocating.init(allocator); 689 defer writer.deinit(); 690 for (0..40) |line| { 691 const start = writer.written().len; 692 if ((line + fi + c) % 8 == 0) { 693 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 694 try writer.writer.print("rev {d} {s}", .{ c, tag }); 695 } 696 const target = 40 + (line * 17 + fi * 23) % 70; 697 var w = line + fi; 698 while (true) : (w += 1) { 699 const word = scatter_words[w % scatter_words.len]; 700 const len = writer.written().len - start; 701 if (len >= target or len + 1 + word.len > 120) break; 702 if (len == 0) 703 try writer.writer.print("{s}", .{word}) 704 else 705 try writer.writer.print(" {s}", .{word}); 706 } 707 try writer.writer.writeByte('\n'); 708 } 709 try file.writeStreamingAll(io, writer.written()); 710 } 711 712 // tag the current HEAD as the next sequential version: v1, v2, and so on 713 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 714 var buf: [16]u8 = undefined; 715 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 716 _ = try repo.addTag(io, allocator, .{ .name = name }); 717 n.* += 1; 718 } 719 720 // recursively copy the contents of src_dir into dest_dir 721 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 722 var iter = src_dir.iterate(); 723 while (try iter.next(io)) |entry| { 724 switch (entry.kind) { 725 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 726 .directory => { 727 try dest_dir.createDirPath(io, entry.name); 728 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 729 defer dest_entry_dir.close(io); 730 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 731 defer src_entry_dir.close(io); 732 try copyDir(io, src_entry_dir, dest_entry_dir); 733 }, 734 else => {}, 735 } 736 } 737 } 738