╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
776 777 pub fn run(self: @This(), web_port: u16, ssh_port: u16) !void { 778 _ = web_port; 779 std.debug.print( 780 \\ 781 \\connect to the TUI with: 782 \\ ssh -p {d} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 783 \\ 784 \\create a git repo and push over SSH: 785 \\ mkdir -p temp-try/client/test 786 \\ cd temp-try/client/test 787 \\ git init 788 \\ echo "hello" > hello.txt 789 \\ git add hello.txt 790 \\ git commit -m "let there be light" 791 \\ GIT_SSH_COMMAND='ssh -p {d} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i {s}' git push localhost:admin/test HEAD:master 792 \\ 793 \\to quit, press enter. 794 \\ 795 , .{ ssh_port, ssh_port, self.key_path }); 796 // portable stdin read via std.Io — equivalent to the 797 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 798 // on windows. 799 var buf: [1]u8 = undefined; 800 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 801 _ = stdin_reader.interface.takeByte() catch {}; 802 } 803 }; 804 805 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 806 .data_dir = server_path, 807 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 808 } else { 809 var null_writer = std.Io.Writer.Discarding.init(&.{}); 810 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 811 812 const Runnable = struct { 813 io: std.Io, 814 allocator: std.mem.Allocator, 815 session: *ui.Session, 816 repo: *Repo, 817 818 pub fn run(self: @This(), web_port: u16, ssh_port: u16) !void { 819 _ = ssh_port; 820 // launch the TUI; the footer points at whatever port was bound 821 self.session.web_port = web_port; 822 try hx.ui.run(self.io, self.allocator, self.session, self.repo); 823 } 824 }; 825 826 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 827 .data_dir = server_path, 828 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 829 } 830 } 831 832 // words cycled through to pad generated lines into prose-like content 833 const scatter_words = [_][]const u8{ 834 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 835 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 836 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 837 "scatter", "gather", "encode", "decode", "render", "commit", 838 }; 839 840 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 841 // index `fi` shift which lines change and the words used, so each (c, fi) 842 // yields a distinct multi-hunk diff against the previous revision. untouched 843 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 844 // small hunks rather than a full rewrite. 845 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 846 const file = try repo_dir.createFile(io, path, .{}); 847 defer file.close(io); 848 var writer = std.Io.Writer.Allocating.init(allocator); 849 defer writer.deinit(); 850 for (0..40) |line| { 851 const start = writer.written().len; 852 if ((line + fi + c) % 8 == 0) { 853 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 854 try writer.writer.print("rev {d} {s}", .{ c, tag }); 855 } 856 const target = 40 + (line * 17 + fi * 23) % 70; 857 var w = line + fi; 858 while (true) : (w += 1) { 859 const word = scatter_words[w % scatter_words.len]; 860 const len = writer.written().len - start; 861 if (len >= target or len + 1 + word.len > 120) break; 862 if (len == 0) 863 try writer.writer.print("{s}", .{word}) 864 else 865 try writer.writer.print(" {s}", .{word}); 866 } 867 try writer.writer.writeByte('\n'); 868 } 869 try file.writeStreamingAll(io, writer.written()); 870 } 871 872 // tag the current HEAD as the next sequential version: v1, v2, and so on 873 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 874 var buf: [16]u8 = undefined; 875 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 876 _ = try repo.addTag(io, allocator, .{ .name = name }); 877 n.* += 1; 878 } 879 880 // recursively copy the contents of src_dir into dest_dir 881 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 882 var iter = src_dir.iterate(); 883 while (try iter.next(io)) |entry| { 884 switch (entry.kind) { 885 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 886 .directory => { 887 try dest_dir.createDirPath(io, entry.name); 888 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 889 defer dest_entry_dir.close(io); 890 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 891 defer src_entry_dir.close(io); 892 try copyDir(io, src_entry_dir, dest_entry_dir); 893 }, 894 else => {}, 895 } 896 } 897 } 898