╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
495 .title = "Deprecate the legacy plugin format", 496 .description = "Both plugin formats are currently loaded, doubling the maintenance surface. Warn on legacy plugins this release and drop support in the next.", 497 .tags = "maintenance plugins", 498 }, 499 }; 500 501 var issue_events: [issue_data.len]evt.EventWithId = undefined; 502 for (issue_data, 0..) |issue, i| { 503 issue_events[i] = .{ 504 .id = std.fmt.bytesToHex(evt.EventWithId.randomId(prng.random()), .lower), 505 // stepped timestamps so the issues list in a stable order 506 .timestamp = @intCast(i + 1), 507 .event = .{ 508 .issue = .{ 509 .title = issue.title, 510 .description = issue.description, 511 .tags = issue.tags, 512 .status = issue.status, 513 }, 514 }, 515 }; 516 } 517 try evt.commitAndConsume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &issue_events); 518 } 519 520 // copy the template to each repo's on-disk location, named by its 521 // hex-encoded event id. the template repo is deinitialized above, so its 522 // db file is fully written before we copy it. 523 { 524 var template_dir = try cwd.openDir(io, template_path, .{ .iterate = true }); 525 defer template_dir.close(io); 526 527 for (repo_event_ids) |id_bytes| { 528 const repo_id = std.fmt.bytesToHex(id_bytes, .lower); 529 const repo_path = try std.fs.path.join(arena.allocator(), &.{ cwd_path, temp_dir_name, "server", "repos", &repo_id }); 530 var dest_dir = try cwd.createDirPathOpen(io, repo_path, .{}); 531 defer dest_dir.close(io); 532 try copyDir(io, template_dir, dest_dir); 533 } 534 } 535 536 break :blk try ui.Session.init(&session_arena, &repo, .{}); 537 }; 538 session.is_terminal = true; 539 // try uses the default serve options below, so the footer's url points at 540 // the default web UI port. 541 session.web_port = try (srv.Options{}).wuiPort(); 542 543 // start the server 544 545 var cli = false; 546 547 var arg_it = try init.minimal.args.iterateAllocator(allocator); 548 defer arg_it.deinit(); 549 _ = arg_it.skip(); 550 while (arg_it.next()) |arg| { 551 if (std.mem.eql(u8, "--cli", arg)) { 552 cli = true; 553 } 554 } 555 556 const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server" }); 557 defer allocator.free(server_path); 558 559 // let the native TUI's page builders open the on-disk repos for the file tree 560 session.io = io; 561 session.repos_dir = try std.fs.path.join(session_arena.allocator(), &.{ server_path, "repos" }); 562 563 if (cli) { 564 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 565 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 566 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 567 568 const key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 569 defer allocator.free(key_path); 570 571 const Runnable = struct { 572 io: std.Io, 573 key_path: []const u8, 574 575 pub fn run(self: @This()) !void { 576 std.debug.print( 577 \\ 578 \\connect to the TUI with: 579 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 580 \\ 581 \\create a git repo and push over SSH: 582 \\ mkdir -p temp-try/client/test 583 \\ cd temp-try/client/test 584 \\ git init 585 \\ echo "hello" > hello.txt 586 \\ git add hello.txt 587 \\ git commit -m "let there be light" 588 \\ 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 589 \\ 590 \\to quit, press enter. 591 \\ 592 , .{self.key_path}); 593 // portable stdin read via std.Io — equivalent to the 594 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 595 // on windows. 596 var buf: [1]u8 = undefined; 597 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 598 _ = stdin_reader.interface.takeByte() catch {}; 599 } 600 }; 601 602 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 603 .data_dir = server_path, 604 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 605 } else { 606 var null_writer = std.Io.Writer.Discarding.init(&.{}); 607 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 608 609 const Runnable = struct { 610 io: std.Io, 611 allocator: std.mem.Allocator, 612 session: *ui.Session, 613 repo: *Repo, 614 615 pub fn run(self: @This()) !void { 616 // launch the TUI 617 try hx.ui.run(self.io, self.allocator, self.session, self.repo); 618 } 619 }; 620 621 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 622 .data_dir = server_path, 623 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 624 } 625 } 626 627 // words cycled through to pad generated lines into prose-like content 628 const scatter_words = [_][]const u8{ 629 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 630 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 631 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 632 "scatter", "gather", "encode", "decode", "render", "commit", 633 }; 634 635 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 636 // index `fi` shift which lines change and the words used, so each (c, fi) 637 // yields a distinct multi-hunk diff against the previous revision. untouched 638 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 639 // small hunks rather than a full rewrite. 640 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 641 const file = try repo_dir.createFile(io, path, .{}); 642 defer file.close(io); 643 var writer = std.Io.Writer.Allocating.init(allocator); 644 defer writer.deinit(); 645 for (0..40) |line| { 646 const start = writer.written().len; 647 if ((line + fi + c) % 8 == 0) { 648 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 649 try writer.writer.print("rev {d} {s}", .{ c, tag }); 650 } 651 const target = 40 + (line * 17 + fi * 23) % 70; 652 var w = line + fi; 653 while (true) : (w += 1) { 654 const word = scatter_words[w % scatter_words.len]; 655 const len = writer.written().len - start; 656 if (len >= target or len + 1 + word.len > 120) break; 657 if (len == 0) 658 try writer.writer.print("{s}", .{word}) 659 else 660 try writer.writer.print(" {s}", .{word}); 661 } 662 try writer.writer.writeByte('\n'); 663 } 664 try file.writeStreamingAll(io, writer.written()); 665 } 666 667 // tag the current HEAD as the next sequential version: v1, v2, and so on 668 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 669 var buf: [16]u8 = undefined; 670 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 671 _ = try repo.addTag(io, allocator, .{ .name = name }); 672 n.* += 1; 673 } 674 675 // recursively copy the contents of src_dir into dest_dir 676 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 677 var iter = src_dir.iterate(); 678 while (try iter.next(io)) |entry| { 679 switch (entry.kind) { 680 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 681 .directory => { 682 try dest_dir.createDirPath(io, entry.name); 683 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 684 defer dest_entry_dir.close(io); 685 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 686 defer src_entry_dir.close(io); 687 try copyDir(io, src_entry_dir, dest_entry_dir); 688 }, 689 else => {}, 690 } 691 } 692 } 693