╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
425 426 pub fn run(self: @This()) !void { 427 std.debug.print( 428 \\ 429 \\connect to the TUI with: 430 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 431 \\ 432 \\create a git repo and push over SSH: 433 \\ mkdir -p temp-try/client/test 434 \\ cd temp-try/client/test 435 \\ git init 436 \\ echo "hello" > hello.txt 437 \\ git add hello.txt 438 \\ git commit -m "let there be light" 439 \\ 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 440 \\ 441 \\to quit, press enter. 442 \\ 443 , .{self.key_path}); 444 // portable stdin read via std.Io — equivalent to the 445 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 446 // on windows. 447 var buf: [1]u8 = undefined; 448 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 449 _ = stdin_reader.interface.takeByte() catch {}; 450 } 451 }; 452 453 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 454 .data_dir = server_path, 455 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 456 } else { 457 var null_writer = std.Io.Writer.Discarding.init(&.{}); 458 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 459 460 const Runnable = struct { 461 io: std.Io, 462 allocator: std.mem.Allocator, 463 session: *ui.Session, 464 465 pub fn run(self: @This()) !void { 466 // launch the TUI 467 try hx.ui.run(self.io, self.allocator, self.session); 468 } 469 }; 470 471 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 472 .data_dir = server_path, 473 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session }); 474 } 475 } 476 477 // words cycled through to pad generated lines into prose-like content 478 const scatter_words = [_][]const u8{ 479 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 480 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 481 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 482 "scatter", "gather", "encode", "decode", "render", "commit", 483 }; 484 485 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 486 // index `fi` shift which lines change and the words used, so each (c, fi) 487 // yields a distinct multi-hunk diff against the previous revision. untouched 488 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 489 // small hunks rather than a full rewrite. 490 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 491 const file = try repo_dir.createFile(io, path, .{}); 492 defer file.close(io); 493 var writer = std.Io.Writer.Allocating.init(allocator); 494 defer writer.deinit(); 495 for (0..40) |line| { 496 const start = writer.written().len; 497 if ((line + fi + c) % 8 == 0) { 498 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 499 try writer.writer.print("rev {d} {s}", .{ c, tag }); 500 } 501 const target = 40 + (line * 17 + fi * 23) % 70; 502 var w = line + fi; 503 while (true) : (w += 1) { 504 const word = scatter_words[w % scatter_words.len]; 505 const len = writer.written().len - start; 506 if (len >= target or len + 1 + word.len > 120) break; 507 if (len == 0) 508 try writer.writer.print("{s}", .{word}) 509 else 510 try writer.writer.print(" {s}", .{word}); 511 } 512 try writer.writer.writeByte('\n'); 513 } 514 try file.writeStreamingAll(io, writer.written()); 515 } 516 517 // tag the current HEAD as the next sequential version: v1, v2, and so on 518 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 519 var buf: [16]u8 = undefined; 520 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 521 _ = try repo.addTag(io, allocator, .{ .name = name }); 522 n.* += 1; 523 } 524 525 // recursively copy the contents of src_dir into dest_dir 526 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 527 var iter = src_dir.iterate(); 528 while (try iter.next(io)) |entry| { 529 switch (entry.kind) { 530 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 531 .directory => { 532 try dest_dir.createDirPath(io, entry.name); 533 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 534 defer dest_entry_dir.close(io); 535 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 536 defer src_entry_dir.close(io); 537 try copyDir(io, src_entry_dir, dest_entry_dir); 538 }, 539 else => {}, 540 } 541 } 542 } 543