╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 //! start a server with some fake data and then launch 2 //! the TUI. this provides a nice way to test things 3 //! out safely. 4 5 const std = @import("std"); 6 const builtin = @import("builtin"); 7 const hx = @import("haxy"); 8 const srv = hx.serve; 9 const evt = hx.event; 10 const xit = hx.xit; 11 const rp = xit.repo; 12 const ui = hx.ui; 13 14 // cook the terminal before a panic/segfault trace is printed, so the trace 15 // isn't mangled by raw mode and the alternate buffer 16 pub const std_options_debug_io = xit.xitui.terminal.crash_debug_io; 17 18 pub fn main(init: std.process.Init) !void { 19 const allocator = std.heap.smp_allocator; 20 21 var threaded = std.Io.Threaded.init(allocator, .{ 22 .environ = init.minimal.environ, 23 }); 24 defer threaded.deinit(); 25 const io = threaded.io(); 26 27 const temp_dir_name = "temp-try"; 28 29 // create the temp dir 30 const cwd = std.Io.Dir.cwd(); 31 var temp_dir_or_err = cwd.openDir(io, temp_dir_name, .{}); 32 if (temp_dir_or_err) |*temp_dir| { 33 temp_dir.close(io); 34 try cwd.deleteTree(io, temp_dir_name); 35 } else |_| {} 36 var temp_dir = try cwd.createDirPathOpen(io, temp_dir_name, .{}); 37 defer cwd.deleteTree(io, temp_dir_name) catch {}; 38 defer temp_dir.close(io); 39 40 // write the dev SSH private key so pushes can authenticate against the 41 // matching public key seeded on the admin account below 42 { 43 const priv_key_file = try temp_dir.createFile(io, "key", .{}); 44 defer priv_key_file.close(io); 45 try priv_key_file.writeStreamingAll(io, 46 \\-----BEGIN OPENSSH PRIVATE KEY----- 47 \\b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW 48 \\QyNTUxOQAAACCniLPJiaooAWecvOCeAjoJwCSeWxzysvpTNkpYjF22JgAAAJA+7hikPu4Y 49 \\pAAAAAtzc2gtZWQyNTUxOQAAACCniLPJiaooAWecvOCeAjoJwCSeWxzysvpTNkpYjF22Jg 50 \\AAAEDVlopOMnKt/7by/IA8VZvQXUS/O6VLkixOqnnahUdPCKeIs8mJqigBZ5y84J4COgnA 51 \\JJ5bHPKy+lM2SliMXbYmAAAAC3JhZGFyQHJvYXJrAQI= 52 \\-----END OPENSSH PRIVATE KEY----- 53 \\ 54 ); 55 if (.windows != builtin.os.tag) { 56 try priv_key_file.setPermissions(io, @enumFromInt(0o600)); 57 } 58 } 59 60 const cwd_path = try std.process.currentPathAlloc(io, allocator); 61 defer allocator.free(cwd_path); 62 63 const work_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server", "admin" }); 64 defer allocator.free(work_path); 65 66 const Repo = rp.Repo(.xit, evt.admin_repo_opts); 67 var repo = try Repo.init(io, allocator, .{ .path = work_path }); 68 defer repo.deinit(io, allocator); 69 70 var session_arena = std.heap.ArenaAllocator.init(allocator); 71 defer session_arena.deinit(); 72 73 // the seeded admin's event id, so both uis start logged in as them 74 var admin_user_id: [evt.event_id_size]u8 = undefined; 75 76 var session: ui.Session = blk: { 77 var arena = std.heap.ArenaAllocator.init(allocator); 78 defer arena.deinit(); 79 80 // define test events 81 82 var prng = std.Random.DefaultPrng.init(std.testing.random_seed); 83 84 const user_data = [_]struct { 85 name: []const u8, 86 display_name: []const u8, 87 email: []const u8, 88 }{ 89 .{ .name = "admin", .display_name = "Admin", .email = "admin@example.test" }, 90 .{ .name = "alice", .display_name = "Alice Tulley", .email = "alice@example.test" }, 91 .{ .name = "bob", .display_name = "Bob Smith", .email = "bob@example.test" }, 92 .{ .name = "carol", .display_name = "Carol Johnson", .email = "carol@example.test" }, 93 .{ .name = "dave", .display_name = "Dave Wilson", .email = "dave@example.test" }, 94 .{ .name = "eve", .display_name = "Eve Anderson", .email = "eve@example.test" }, 95 .{ .name = "frank", .display_name = "Frank Miller", .email = "frank@example.test" }, 96 .{ .name = "grace", .display_name = "Grace Lee", .email = "grace@example.test" }, 97 .{ .name = "henry", .display_name = "Henry Davis", .email = "henry@example.test" }, 98 .{ .name = "ivy", .display_name = "Ivy Martinez", .email = "ivy@example.test" }, 99 .{ .name = "jack", .display_name = "Jack Thompson", .email = "jack@example.test" }, 100 .{ .name = "kate", .display_name = "Kate Robinson", .email = "kate@example.test" }, 101 .{ .name = "liam", .display_name = "Liam Walker", .email = "liam@example.test" }, 102 .{ .name = "mona", .display_name = "Mona Patel", .email = "mona@example.test" }, 103 .{ .name = "noah", .display_name = "Noah Garcia", .email = "noah@example.test" }, 104 .{ .name = "olivia", .display_name = "Olivia Hernandez", .email = "olivia@example.test" }, 105 .{ .name = "peter", .display_name = "Peter Wright", .email = "peter@example.test" }, 106 .{ .name = "quinn", .display_name = "Quinn Foster", .email = "quinn@example.test" }, 107 .{ .name = "rachel", .display_name = "Rachel Bennett", .email = "rachel@example.test" }, 108 .{ .name = "sam", .display_name = "Sam Brooks", .email = "sam@example.test" }, 109 .{ .name = "tina", .display_name = "Tina Cooper", .email = "tina@example.test" }, 110 }; 111 112 const repo_data = [_]struct { 113 user_index: usize, 114 name: []const u8, 115 description: []const u8, 116 }{ 117 .{ .user_index = 1, .name = "ziglings", .description = "Learn the Zig programming language by fixing tiny broken programs" }, 118 .{ .user_index = 2, .name = "linux", .description = "Linux kernel source tree" }, 119 .{ .user_index = 3, .name = "kubernetes", .description = "Production-grade container orchestration" }, 120 .{ .user_index = 4, .name = "react", .description = "A declarative, efficient, and flexible JavaScript library for building user interfaces" }, 121 .{ .user_index = 5, .name = "typescript", .description = "TypeScript is a superset of JavaScript that compiles to clean JavaScript output" }, 122 .{ .user_index = 6, .name = "rust", .description = "Empowering everyone to build reliable and efficient software" }, 123 .{ .user_index = 7, .name = "go", .description = "The Go programming language" }, 124 .{ .user_index = 8, .name = "nodejs", .description = "Node.js JavaScript runtime" }, 125 .{ .user_index = 9, .name = "cpython", .description = "The Python programming language" }, 126 .{ .user_index = 10, .name = "docker", .description = "Container platform for developing, shipping, and running applications" }, 127 .{ .user_index = 1, .name = "vim", .description = "The ubiquitous text editor" }, 128 .{ .user_index = 2, .name = "neovim", .description = "Hyperextensible Vim-based text editor" }, 129 .{ .user_index = 3, .name = "emacs", .description = "GNU Emacs source code mirror" }, 130 .{ .user_index = 4, .name = "tmux", .description = "Terminal multiplexer" }, 131 .{ .user_index = 5, .name = "zsh", .description = "Mirror of the Z shell source code repository" }, 132 .{ .user_index = 6, .name = "git", .description = "Distributed version control system" }, 133 .{ .user_index = 7, .name = "mercurial", .description = "Source-control management tool" }, 134 .{ .user_index = 8, .name = "tensorflow", .description = "An end-to-end open source machine learning platform" }, 135 .{ .user_index = 9, .name = "pytorch", .description = "Tensors and dynamic neural networks in Python with strong GPU acceleration" }, 136 .{ .user_index = 10, .name = "numpy", .description = "The fundamental package for scientific computing with Python" }, 137 .{ .user_index = 1, .name = "pandas", .description = "Flexible and powerful data analysis and manipulation library for Python" }, 138 .{ .user_index = 2, .name = "scikit-learn", .description = "Machine learning in Python" }, 139 .{ .user_index = 3, .name = "nginx", .description = "High performance HTTP server and reverse proxy" }, 140 .{ .user_index = 4, .name = "redis", .description = "In-memory data structure store, used as a database, cache, and message broker" }, 141 .{ .user_index = 5, .name = "postgres", .description = "The world's most advanced open source relational database" }, 142 .{ .user_index = 6, .name = "sqlite", .description = "Self-contained, serverless, zero-configuration SQL database engine" }, 143 .{ .user_index = 7, .name = "mongodb", .description = "The MongoDB Database" }, 144 .{ .user_index = 8, .name = "elasticsearch", .description = "Free and open, distributed, RESTful search engine" }, 145 .{ .user_index = 9, .name = "kafka", .description = "Distributed event streaming platform" }, 146 .{ .user_index = 10, .name = "terraform", .description = "Infrastructure as code tool" }, 147 .{ .user_index = 11, .name = "svelte", .description = "Cybernetically enhanced web apps" }, 148 .{ .user_index = 12, .name = "vue", .description = "The progressive JavaScript framework" }, 149 .{ .user_index = 13, .name = "flask", .description = "The Python micro framework for building web applications" }, 150 .{ .user_index = 14, .name = "django", .description = "The web framework for perfectionists with deadlines" }, 151 .{ .user_index = 15, .name = "rails", .description = "Ruby on Rails web framework" }, 152 .{ .user_index = 16, .name = "phoenix", .description = "Peace of mind from prototype to production for Elixir web apps" }, 153 .{ .user_index = 17, .name = "laravel", .description = "The PHP framework for web artisans" }, 154 .{ .user_index = 18, .name = "prometheus", .description = "The Prometheus monitoring system and time series database" }, 155 .{ .user_index = 19, .name = "grafana", .description = "The open and composable observability and data visualization platform" }, 156 .{ .user_index = 20, .name = "ansible", .description = "Simple, agentless IT automation" }, 157 }; 158 159 var user_ids: [user_data.len][evt.event_id_size]u8 = undefined; 160 for (&user_ids) |*id| id.* = evt.EventWithId.randomId(prng.random()); 161 // admin is the first entry of user_data above 162 admin_user_id = user_ids[0]; 163 164 var repo_event_ids: [repo_data.len][evt.event_id_size]u8 = undefined; 165 for (&repo_event_ids) |*id| id.* = evt.EventWithId.randomId(prng.random()); 166 167 var password_hash_buf: [evt.User.password_hash_max_len]u8 = undefined; 168 const password_hash = try evt.User.hashPassword("password", &password_hash_buf, io); 169 170 // public key matching temp-try/key, given to admin so we can push as admin 171 const admin_ssh_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKeIs8mJqigBZ5y84J4COgnAJJ5bHPKy+lM2SliMXbYm radar@roark"; 172 173 var events_to_consume: [user_data.len + repo_data.len]evt.EventWithId = undefined; 174 // inserted back to front, so the newest-first listing shows them in the 175 // order they're written above 176 for (0..user_data.len) |slot| { 177 const i = user_data.len - 1 - slot; 178 const u = user_data[i]; 179 events_to_consume[slot] = .{ 180 .id = std.fmt.bytesToHex(user_ids[i], .lower), 181 // stepped timestamps so the seeded users/repos list in a stable order 182 .timestamp = @intCast(slot + 1), 183 .author_email = "admin@example.test", 184 .event = .{ 185 .user = .{ 186 .name = u.name, 187 .display_name = u.display_name, 188 .email = u.email, 189 .password_hash = password_hash, 190 .ssh_keys = if (std.mem.eql(u8, "admin", u.name)) admin_ssh_key else "", 191 }, 192 }, 193 }; 194 } 195 for (repo_data, 0..) |r, i| { 196 events_to_consume[user_data.len + i] = .{ 197 .id = std.fmt.bytesToHex(repo_event_ids[i], .lower), 198 .timestamp = @intCast(user_data.len + i + 1), 199 .author_email = user_data[r.user_index].email, 200 .event = .{ 201 .repo = .{ 202 .user_id = &user_ids[r.user_index], 203 .name = r.name, 204 .description = r.description, 205 }, 206 }, 207 }; 208 } 209 210 // commit the seed events and consume them into the database 211 try evt.consume(.xit, evt.admin_repo_opts, io, allocator, &repo, evt.events_ref, &events_to_consume); 212 213 // every repo gets the same generated history, so build it once into a 214 // template repo and copy that to each repo's location below rather than 215 // redoing the expensive commit work for every repo. 216 const template_path = try std.fs.path.join(arena.allocator(), &.{ cwd_path, temp_dir_name, "template" }); 217 { 218 var template_repo = try rp.Repo(.xit, .{}).init(io, allocator, .{ .path = template_path }); 219 defer template_repo.deinit(io, allocator); 220 221 try template_repo.addConfig(io, allocator, .{ .name = "user.name", .value = "haxy" }); 222 try template_repo.addConfig(io, allocator, .{ .name = "user.email", .value = "admin@example.test" }); 223 224 // a README plus a nested doc so the file tree has a directory to 225 // descend into 226 { 227 var repo_dir = try cwd.openDir(io, template_path, .{}); 228 defer repo_dir.close(io); 229 230 const readme = try repo_dir.createFile(io, "README.md", .{}); 231 defer readme.close(io); 232 try readme.writeStreamingAll(io, 233 \\# Sample Repo 234 \\ 235 \\A repository seeded with test data for exercising the UI. 236 \\ 237 \\## Features 238 \\ 239 \\- Fast and lightweight 240 \\- Zero configuration required 241 \\- Works out of the box 242 \\ 243 \\## Installation 244 \\ 245 \\Clone the repository and build it from source: 246 \\ 247 \\```sh 248 \\git clone https://example.test/sample-repo.git 249 \\cd sample-repo 250 \\make install 251 \\``` 252 \\ 253 \\## Usage 254 \\ 255 \\Run the program with the `--help` flag to see all available 256 \\options: 257 \\ 258 \\```sh 259 \\sample-repo --help 260 \\``` 261 \\ 262 \\| Option | Description | 263 \\| ----------- | ------------------------------ | 264 \\| `--verbose` | Print extra diagnostic output | 265 \\| `--quiet` | Suppress all non-error output | 266 \\| `--version` | Print the version and exit | 267 \\ 268 \\## Contributing 269 \\ 270 \\Contributions are welcome! Please open an issue to discuss 271 \\any significant changes before submitting a pull request. 272 \\See the docs under `docs/dev` for more details. 273 \\ 274 \\## License 275 \\ 276 \\Released under the MIT License. See `LICENSE` for the full 277 \\text. 278 \\ 279 ); 280 281 try repo_dir.createDirPath(io, "docs/dev"); 282 const doc = try repo_dir.createFile(io, "docs/dev/contribute.md", .{}); 283 defer doc.close(io); 284 try doc.writeStreamingAll(io, "To contribute, please make a pull request"); 285 } 286 287 try template_repo.add(io, allocator, &.{ "README.md", "docs/dev/contribute.md" }); 288 _ = try template_repo.commit(io, allocator, .{ .message = "let there be light" }); 289 290 // tag every commit in creation order as v1, v2, and so on 291 var tag_num: usize = 1; 292 try addNextTag(&template_repo, io, allocator, &tag_num); 293 294 // a batch of commits so the commits tab has more than one page to 295 // paginate through. each rewrites a few files with scattered line 296 // edits, so every commit is a multi-file diff with several separate 297 // hunks to look at. stepped timestamps vary the date column. 298 const base_ts: u64 = 1_700_000_000; // 2023-11-14 299 const edit_files = [_][]const u8{ "src/alpha.txt", "src/beta.txt", "src/gamma.txt" }; 300 // commit subjects, cycled then padded to a varying length. 301 const subjects = [_][]const u8{ 302 "fix off-by-one in scatter loop", 303 "encode and decode buffers", 304 "tune kernel socket timeouts", 305 "render matrix vector product", 306 "gather falcon and otter stats", 307 "refactor badger walrus module", 308 "drop dead ferret marmot branch", 309 }; 310 const commit_count = 30; 311 var c: usize = 0; 312 while (c < commit_count) : (c += 1) { 313 { 314 var repo_dir = try cwd.openDir(io, template_path, .{}); 315 defer repo_dir.close(io); 316 try repo_dir.createDirPath(io, "src"); 317 for (edit_files, 0..) |path, fi| { 318 try writeScatterFile(io, allocator, repo_dir, path, fi, c); 319 } 320 } 321 try template_repo.add(io, allocator, &edit_files); 322 // a cycling subject padded to a c-varying length so the commit 323 // list shows messages of different widths, capped at 120. 324 var msg_writer = std.Io.Writer.Allocating.init(allocator); 325 defer msg_writer.deinit(); 326 try msg_writer.writer.print("{s}", .{subjects[c % subjects.len]}); 327 const msg_target = 16 + (c * 41) % 96; 328 var mw = c; 329 while (true) : (mw += 1) { 330 const word = scatter_words[mw % scatter_words.len]; 331 const len = msg_writer.written().len; 332 if (len >= msg_target or len + 1 + word.len > 120) break; 333 try msg_writer.writer.print(" {s}", .{word}); 334 } 335 // the newest commit's message runs past what the detail pane 336 // reads, so it shows the truncated message and its link. 337 if (c == commit_count - 1) { 338 var line: usize = 0; 339 while (msg_writer.written().len <= ui.Repo.Commits.max_message_size) : (line += 1) { 340 try msg_writer.writer.print("\n{d} {s}", .{ line, scatter_words[line % scatter_words.len] }); 341 } 342 } 343 const message = try arena.allocator().dupe(u8, msg_writer.written()); 344 _ = try template_repo.commit(io, allocator, .{ .message = message, .timestamp = base_ts + c * std.time.s_per_day }); 345 try addNextTag(&template_repo, io, allocator, &tag_num); 346 } 347 348 // two more branches forked off master, each adding a single commit 349 // that makes a scattered edit to one file. tag each new commit too, 350 // and switch back to master after each so the next branch also 351 // forks from master and the template ends up back on master. 352 const branch_data = [_]struct { 353 name: []const u8, 354 file: []const u8, 355 fi: usize, 356 message: []const u8, 357 rev: usize, 358 }{ 359 .{ .name = "extra", .file = "src/alpha.txt", .fi = 0, .message = "scatter alpha on the extra branch", .rev = 30 }, 360 .{ .name = "feature", .file = "src/beta.txt", .fi = 1, .message = "scatter beta on the feature branch", .rev = 31 }, 361 }; 362 for (branch_data) |b| { 363 try template_repo.addBranch(io, .{ .name = b.name }); 364 { 365 var to_branch = try template_repo.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = b.name } } }); 366 defer to_branch.deinit(); 367 } 368 369 { 370 var repo_dir = try cwd.openDir(io, template_path, .{}); 371 defer repo_dir.close(io); 372 try writeScatterFile(io, allocator, repo_dir, b.file, b.fi, b.rev); 373 } 374 try template_repo.add(io, allocator, &.{b.file}); 375 _ = try template_repo.commit(io, allocator, .{ .message = b.message, .timestamp = base_ts + b.rev * std.time.s_per_day }); 376 try addNextTag(&template_repo, io, allocator, &tag_num); 377 378 { 379 var to_master = try template_repo.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = "master" } } }); 380 defer to_master.deinit(); 381 } 382 } 383 384 // the timestamps issue's description, in paragraphs, so the 385 // seeded conflict below can insert and delete among them 386 const tz_p1 = "All timestamps in the activity feed render in UTC regardless of the system timezone."; 387 const tz_p2 = "The tooltip on each entry repeats the same UTC value, so there is no way to see the local time without converting by hand."; 388 const tz_p3 = "A quick survey of other clients shows every one of them rendering local time by default."; 389 const tz_p4 = "Convert to local time and include the offset in tooltips."; 390 391 // the sync issue's description, in paragraphs, so each side of its 392 // seeded conflict can rework a different one 393 const sync_p1 = "The sync engine only has unit tests with mocked transports."; 394 const sync_p2 = "Failures seen in production involve reconnects and partial writes, which the mocks can't reproduce."; 395 const sync_p3 = "Add end-to-end tests that run two instances against a real local server."; 396 397 // seed issues so every repo's issue tracker has content 398 const issue_data = [_]struct { 399 title: []const u8, 400 description: []const u8, 401 tags: []const u8, 402 status: evt.Issue.Status = .open, 403 }{ 404 .{ 405 .title = "Crash on startup when config file is missing", 406 .description = "Running the program without a config file present dereferences a null pointer and segfaults. Fall back to the built-in defaults and log a warning instead.", 407 .tags = "bug priority-high crash", 408 }, 409 .{ 410 .title = "Support dark mode in the settings panel", 411 .description = "The settings panel is always rendered with the light palette even when the rest of the app is in dark mode. Read the active theme and pick colors accordingly.", 412 .tags = "enhancement ui theme", 413 }, 414 .{ 415 .title = "Memory leak when reconnecting after network failure", 416 .description = "Each reconnect allocates a new connection state without freeing the previous one. After a flaky network session, memory usage grows by several megabytes per hour.", 417 .tags = "bug memory networking", 418 .status = .closed, 419 }, 420 .{ 421 .title = "Document the plugin API", 422 .description = "The plugin interface has no documentation beyond the header comments. Add a guide covering the lifecycle hooks, the event callbacks, and a minimal working plugin.", 423 .tags = "documentation plugins", 424 }, 425 .{ 426 .title = "Slow file indexing on large directories", 427 .description = "Indexing a directory with more than 100k files takes several minutes because every entry is stat'd twice. Cache the first stat result and batch the reads.", 428 .tags = "performance indexing", 429 }, 430 .{ 431 .title = "Add keyboard shortcut for quick search", 432 .description = "Opening the search box currently requires clicking the toolbar icon. Bind a shortcut and show it in the tooltip so keyboard users can search without the mouse.", 433 .tags = "enhancement ux keyboard", 434 }, 435 .{ 436 .title = "Unicode filenames are garbled in the export dialog", 437 .description = "Filenames containing non-ASCII characters display as replacement characters in the export dialog. The dialog decodes the path as Latin-1 instead of UTF-8.", 438 .tags = "bug unicode i18n", 439 }, 440 .{ 441 .title = "Flaky test: integration suite times out on CI", 442 .description = "The integration suite intermittently exceeds the CI time limit because the server fixture waits for a fixed 30 seconds. Poll for readiness instead of sleeping.", 443 .tags = "bug testing ci", 444 }, 445 .{ 446 .title = "Upgrade bundled zlib to the latest release", 447 .description = "The vendored zlib is two major releases behind and misses several upstream fixes. Update the bundled copy and re-run the compression benchmarks.", 448 .tags = "dependencies maintenance", 449 }, 450 .{ 451 .title = "Progress bar overshoots 100% during resumed downloads", 452 .description = "Resuming a partial download counts the already-downloaded bytes twice, so the progress bar reads up to 150%. Subtract the resume offset from the total.", 453 .tags = "bug ui downloads", 454 .status = .closed, 455 }, 456 .{ 457 .title = "Config parser rejects trailing commas", 458 .description = "A trailing comma after the last entry in a config block is reported as a syntax error. Most editors add one automatically, so accept it.", 459 .tags = "bug config parser", 460 }, 461 .{ 462 .title = "Add a --json flag to the status command", 463 .description = "Scripts currently scrape the human-readable status output, which breaks whenever the format changes. Emit a stable machine-readable JSON form behind a flag.", 464 .tags = "enhancement cli", 465 }, 466 .{ 467 .title = "Race condition between autosave and manual save", 468 .description = "Saving manually while an autosave is in flight can interleave the two writes and corrupt the file. Serialize saves through a single queue.", 469 .tags = "bug priority-high data-loss", 470 }, 471 .{ 472 .title = "Reduce binary size of release builds", 473 .description = "The release binary has grown past 40 MB, mostly from debug info and an unused bundled font. Strip symbols and drop the font from the default build.", 474 .tags = "performance build", 475 }, 476 .{ 477 .title = "Tooltips flicker when the cursor moves between adjacent buttons", 478 .description = "Moving the cursor across a toolbar hides and re-shows the tooltip for every button. Keep the tooltip open with a short grace period between neighbors.", 479 .tags = "bug ui polish", 480 }, 481 .{ 482 .title = "Support environment variable expansion in config paths", 483 .description = "Paths in the config file are taken literally, so shared configs can't refer to the home directory portably. Expand environment variables when loading.", 484 .tags = "enhancement config", 485 }, 486 .{ 487 .title = "Log rotation deletes the newest file instead of the oldest", 488 .description = "When the log directory hits its size cap, the rotation logic sorts by name rather than mtime and removes the most recent log. Sort by modification time.", 489 .tags = "bug logging", 490 .status = .closed, 491 }, 492 .{ 493 .title = "Add man pages for all subcommands", 494 .description = "Only the top-level command has a man page. Generate one per subcommand from the existing help text as part of the release build.", 495 .tags = "documentation cli", 496 }, 497 .{ 498 .title = "High CPU usage while idle in the background", 499 .description = "The main loop polls for file changes every 10 ms even when no window is visible. Switch to native file watching and idle at zero CPU.", 500 .tags = "performance priority-high", 501 }, 502 .{ 503 .title = "Paste from clipboard drops the final newline", 504 .description = "Pasting text that ends with a newline silently trims it, which breaks pasted shell snippets. Preserve the clipboard content exactly.", 505 .tags = "bug editor clipboard", 506 }, 507 .{ 508 .title = "Improve error message for expired credentials", 509 .description = "An expired token currently surfaces as a bare 401 with no guidance. Detect the expiry case and tell the user how to re-authenticate.", 510 .tags = "enhancement ux auth", 511 }, 512 .{ 513 .title = "Crash when window is resized during startup animation", 514 .description = "Resizing the window while the splash animation is running dereferences a freed layout node. Cancel the animation before rebuilding the layout.", 515 .tags = "bug crash ui", 516 }, 517 .{ 518 .title = "Add integration tests for the sync engine", 519 .description = sync_p1 ++ "\n\n" ++ sync_p2 ++ "\n\n" ++ sync_p3, 520 .tags = "testing sync", 521 }, 522 .{ 523 .title = "Timestamps display in UTC instead of local time", 524 .description = tz_p1 ++ "\n\n" ++ tz_p2 ++ "\n\n" ++ tz_p3 ++ "\n\n" ++ tz_p4, 525 .tags = "bug i18n time", 526 }, 527 .{ 528 .title = "Deprecate the legacy plugin format", 529 .description = "Both plugin formats are currently loaded, doubling the maintenance surface. Warn on legacy plugins this release and drop support in the next.", 530 .tags = "maintenance plugins", 531 }, 532 }; 533 534 var issue_events: [issue_data.len]evt.EventWithId = undefined; 535 for (issue_data, 0..) |issue, i| { 536 // the newest issue's description runs past what the detail 537 // pane shows, so it shows the truncated description and its 538 // link. 539 const description = if (i == issue_data.len - 1) desc: { 540 var desc_writer = std.Io.Writer.Allocating.init(allocator); 541 defer desc_writer.deinit(); 542 try desc_writer.writer.print("{s}", .{issue.description}); 543 var line: usize = 0; 544 while (desc_writer.written().len <= ui.Repo.Issues.max_description_size) : (line += 1) { 545 try desc_writer.writer.print("\n{d} {s}", .{ line, scatter_words[line % scatter_words.len] }); 546 } 547 break :desc try arena.allocator().dupe(u8, desc_writer.written()); 548 } else issue.description; 549 issue_events[i] = .{ 550 .id = std.fmt.bytesToHex(evt.EventWithId.randomId(prng.random()), .lower), 551 // stepped timestamps so the issues list in a stable order 552 .timestamp = @intCast(i + 1), 553 .author_email = user_data[i % user_data.len].email, 554 .event = .{ 555 .issue = .{ 556 .title = issue.title, 557 .description = description, 558 .tags = issue.tags, 559 .status = issue.status, 560 }, 561 }, 562 }; 563 } 564 try evt.consume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &issue_events); 565 // the tip is the branch point for the conflicting edits below 566 const seed_tip = (try template_repo.readRef(io, evt.events_ref)) orelse unreachable; 567 568 // two divergent edits per conflicted issue: ours on the events 569 // branch, theirs on a temp branch rooted at the seed tip, then a 570 // merge. the 4th-newest issue conflicts on title and tags; the 571 // 3rd-newest on its description with every hunk auto-resolving 572 // (each side reworks a different paragraph); the 2nd-newest on 573 // its description with a deletion conflict (ours removes a 574 // paragraph theirs rewords) and an insertion conflict (each side 575 // appends a different closing paragraph). 576 { 577 const other_ref: xit.ref.Ref = .{ .kind = .head, .name = "haxy/other" }; 578 const title_issue = issue_data[issue_data.len - 4]; 579 const sync_issue = issue_data[issue_data.len - 3]; 580 const desc_issue = issue_data[issue_data.len - 2]; 581 582 const ours = [_]evt.EventWithId{ .{ 583 .id = issue_events[issue_data.len - 4].id, 584 .timestamp = 100, 585 .author_email = user_data[1].email, 586 .event = .{ .issue = .{ 587 .title = "Crash when resizing the window during the splash animation", 588 .description = title_issue.description, 589 .tags = "bug crash ui priority-high", 590 } }, 591 }, .{ 592 .id = issue_events[issue_data.len - 3].id, 593 .timestamp = 101, 594 .author_email = user_data[1].email, 595 .event = .{ .issue = .{ 596 .title = sync_issue.title, 597 .description = "The sync engine's coverage is unit tests only, with every transport mocked out." ++ "\n\n" ++ 598 sync_p2 ++ "\n\n" ++ sync_p3, 599 .tags = sync_issue.tags, 600 } }, 601 }, .{ 602 .id = issue_events[issue_data.len - 2].id, 603 .timestamp = 102, 604 .author_email = user_data[1].email, 605 .event = .{ .issue = .{ 606 .title = desc_issue.title, 607 .description = tz_p1 ++ "\n\n" ++ tz_p2 ++ "\n\n" ++ tz_p4 ++ "\n\n" ++ 608 "The confusion is worst for teams spread across timezones, who each read a different wall-clock time from the same feed.", 609 .tags = desc_issue.tags, 610 } }, 611 } }; 612 const theirs = [_]evt.EventWithId{ .{ 613 .id = issue_events[issue_data.len - 4].id, 614 .timestamp = 103, 615 .author_email = user_data[2].email, 616 .event = .{ .issue = .{ 617 .title = "Segfault on early window resize", 618 .description = title_issue.description, 619 .tags = "bug crash rendering", 620 } }, 621 }, .{ 622 .id = issue_events[issue_data.len - 3].id, 623 .timestamp = 104, 624 .author_email = user_data[2].email, 625 .event = .{ .issue = .{ 626 .title = sync_issue.title, 627 .description = sync_p1 ++ "\n\n" ++ sync_p2 ++ "\n\n" ++ 628 "Add end-to-end tests that drive two live instances against a local server on every CI run.", 629 .tags = sync_issue.tags, 630 } }, 631 }, .{ 632 .id = issue_events[issue_data.len - 2].id, 633 .timestamp = 105, 634 .author_email = user_data[2].email, 635 .event = .{ .issue = .{ 636 .title = desc_issue.title, 637 .description = tz_p1 ++ "\n\n" ++ tz_p2 ++ "\n\n" ++ 638 "Most other clients already render local time by default, which makes our UTC output stand out as a bug." ++ "\n\n" ++ tz_p4 ++ "\n\n" ++ 639 "Log exports inherit the same UTC rendering, so downstream tooling has to guess the source timezone.", 640 .tags = desc_issue.tags, 641 } }, 642 } }; 643 644 try evt.consume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &ours); 645 646 // consume can't root a new branch, so theirs commits by hand 647 var json: std.Io.Writer.Allocating = .init(allocator); 648 defer json.deinit(); 649 for (theirs, 0..) |event, i| { 650 json.clearRetainingCapacity(); 651 try std.json.Stringify.value(event, .{}, &json.writer); 652 const author = try std.fmt.allocPrint(allocator, "haxy <{s}>", .{event.author_email}); 653 defer allocator.free(author); 654 _ = try template_repo.commitAtRef(io, allocator, .{ 655 .author = author, 656 .message = json.written(), 657 .timestamp = event.timestamp, 658 // root the branch at the shared seed tip 659 .parent_oids = if (i == 0) &.{seed_tip} else null, 660 }, null, other_ref); 661 } 662 663 { 664 var to_events = try template_repo.switchDir(io, allocator, .{ .target = .{ .ref = evt.events_ref } }); 665 defer to_events.deinit(); 666 } 667 { 668 var merge = try template_repo.merge(io, allocator, .{ .kind = .full, .action = .{ .new = .{ .source = &.{.{ .ref = other_ref }} } } }, null); 669 defer merge.deinit(); 670 if (merge.result != .success) return error.MergeFailed; 671 } 672 { 673 var to_master = try template_repo.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = "master" } } }); 674 defer to_master.deinit(); 675 } 676 try template_repo.removeBranch(io, .{ .name = other_ref.name }); 677 } 678 679 try evt.consume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &.{}); 680 681 // seed a small comment tree on the second-newest issue 682 var comment_ids: [5][evt.event_id_size]u8 = undefined; 683 for (&comment_ids) |*id| id.* = evt.EventWithId.randomId(prng.random()); 684 685 const comment_bodies = [_][]const u8{ 686 "I can take this. The compatibility scanner already reports which repositories still use the legacy format.", 687 "Can we keep loading legacy plugins for one release after the warning lands? That would give downstream maintainers time to migrate.", 688 "That sounds good. I'll include the scanner output in the warning so each affected plugin is named.", 689 "Please include the replacement manifest path too. That should make the warning actionable without opening the migration guide.", 690 "I'll add release-note text once the warning format is settled.", 691 }; 692 693 var comment_events: [comment_ids.len]evt.EventWithId = undefined; 694 for (&comment_events, 0..) |*event, i| { 695 event.* = .{ 696 .id = std.fmt.bytesToHex(comment_ids[i], .lower), 697 .timestamp = @intCast(200 + i), 698 .author_email = user_data[(i + 1) % user_data.len].email, 699 .event = .{ .comment = .{ 700 .thread_id = issue_events[issue_events.len - 2].id, 701 .parent_id = switch (i) { 702 0, 1 => issue_events[issue_events.len - 2].id, 703 2, 4 => std.fmt.bytesToHex(comment_ids[0], .lower), 704 3 => std.fmt.bytesToHex(comment_ids[2], .lower), 705 else => unreachable, 706 }, 707 .body = comment_bodies[i], 708 } }, 709 }; 710 } 711 try evt.consume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &comment_events); 712 } 713 714 // copy the template to each repo's on-disk location, named by its 715 // hex-encoded event id. the template repo is deinitialized above, so its 716 // db file is fully written before we copy it. 717 { 718 var template_dir = try cwd.openDir(io, template_path, .{ .iterate = true }); 719 defer template_dir.close(io); 720 721 for (repo_event_ids) |id_bytes| { 722 const repo_id = std.fmt.bytesToHex(id_bytes, .lower); 723 const repo_path = try std.fs.path.join(arena.allocator(), &.{ cwd_path, temp_dir_name, "server", "repos", &repo_id }); 724 var dest_dir = try cwd.createDirPathOpen(io, repo_path, .{}); 725 defer dest_dir.close(io); 726 try copyDir(io, template_dir, dest_dir); 727 } 728 } 729 730 break :blk try ui.Session.init(&session_arena, &repo, .{ .user_id = &admin_user_id }); 731 }; 732 session.is_terminal = true; 733 734 // start the server 735 736 var cli = false; 737 738 var arg_it = try init.minimal.args.iterateAllocator(allocator); 739 defer arg_it.deinit(); 740 _ = arg_it.skip(); 741 while (arg_it.next()) |arg| { 742 if (std.mem.eql(u8, "--cli", arg)) { 743 cli = true; 744 } 745 } 746 747 const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server" }); 748 defer allocator.free(server_path); 749 750 // let the native TUI's page builders open the on-disk repos for the file tree 751 session.io = io; 752 session.repos_dir = try std.fs.path.join(session_arena.allocator(), &.{ server_path, "repos" }); 753 754 // leave a one-shot session for the first browser to hit the web ui, so it 755 // starts logged in as admin 756 { 757 var data_dir = try cwd.createDirPathOpen(io, server_path, .{}); 758 defer data_dir.close(io); 759 const store = try hx.web.SessionStore.init(io, data_dir); 760 defer store.deinit(); 761 const token = try store.create(&admin_user_id); 762 try store.offerAutoLogin(&token); 763 } 764 765 if (cli) { 766 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 767 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 768 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 769 770 const key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 771 defer allocator.free(key_path); 772 773 const Runnable = struct { 774 io: std.Io, 775 key_path: []const u8, 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