╭ changed ──╮ │src/try.zig│ ╰───────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │211 // public key matching temp-try/key, given to admin so we can push as admin │ │212 const admin_ssh_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKeIs8mJqigBZ5y84J4COgnAJJ5bHPKy+lM2SliMXbYm radar@roark";│ │213 │ │214 - var events_to_consume: [user_data.len + repo_data.len]evt.EventWithId = undefined; │ │214 + var events_to_consume: [user_data.len]evt.EventWithId = undefined; │ │215 // inserted back to front, so the newest-first listing shows them in the │ │216 // order they're written above │ │217 for (0..user_data.len) |slot| { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │232 }, │ │233 }; │ │234 } │ │235 + // commit the seed events and consume them into the database │ │236 + try evt.consume(.server, .admin, .xit, evt.admin_repo_opts, io, allocator, &repo, evt.events_ref, &events_to_consume);│ │237 + │ │238 // admin co-owns every repo, so it has full privileges everywhere │ │239 // (including undo) while the other users only own their own │ │240 const admin_user_id_hex = std.fmt.bytesToHex(admin_user_id, .lower); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │241 + var repo_events: [repo_data.len]evt.EventWithId = undefined; │ │242 for (repo_data, 0..) |r, i| { │ │239 - events_to_consume[user_data.len + i] = .{ │ │243 + repo_events[i] = .{ │ │244 .id = std.fmt.bytesToHex(repo_event_ids[i], .lower), │ │245 .timestamp = @intCast(user_data.len + i + 1), │ │246 .author = .{ .name = user_data[r.user_index].name, .email = user_data[r.user_index].email },│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │256 }; │ │257 } │ │258 │ │255 - // commit the seed events and consume them into the database │ │256 - try evt.consume(.server, .admin, .xit, evt.admin_repo_opts, io, allocator, &repo, evt.events_ref, &events_to_consume); │ │259 + // each user's repo holds the repos they own │ │260 + const repos_path = try std.fs.path.join(arena.allocator(), &.{ server_path, "repos" }); │ │261 + for (user_ids, 0..) |user_id, user_index| { │ │262 + const user_repo_path = try evt.userRepoPath(arena.allocator(), repos_path, &user_id); │ │263 + var user_repo = try evt.initUserRepo(io, allocator, user_repo_path); │ │264 + defer user_repo.deinit(io, allocator); │ │265 + var owned: std.ArrayList(evt.EventWithId) = .empty; │ │266 + for (repo_data, repo_events) |r, event| { │ │267 + if (r.user_index == user_index) try owned.append(arena.allocator(), event); │ │268 + } │ │269 + if (owned.items.len > 0) try evt.consume(.server, .user, .xit, evt.user_repo_opts, io, allocator, &user_repo, evt.events_ref, owned.items);│ │270 + } │ │271 │ │272 // every repo gets the same generated history, so build it once into a │ │273 // template repo and copy that to each repo's location below rather than │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │882 if (repo_index + 1 == repo_data.len) { │ │883 var target_repo = try rp.Repo(.xit, .{}).open(io, allocator, .{ .path = repo_path, .require_repo_root = true }); │ │884 defer target_repo.deinit(io, allocator); │ │871 - try seedPatches(io, allocator, server_path, &repo, &target_repo, &repo_event_ids[repo_index], &admin_user_id, prng.random()); │ │885 + try seedPatches(io, allocator, server_path, &repo, &target_repo, &repo_event_ids[repo_index], &user_ids[repo_data[repo_index].user_index], &admin_user_id, prng.random());│ │886 } │ │887 } │ │888 } │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────╮ │1149 admin_repo: *rp.Repo(.xit, evt.admin_repo_opts),│ │1150 target_repo: *rp.Repo(.xit, .{}), │ │1151 repo_id: *const [evt.event_id_size]u8, │ │1152 + repo_user_id: *const [evt.event_id_size]u8, │ │1153 user_id: *const [evt.event_id_size]u8, │ │1154 random: std.Random, │ │1155 ) !void { │ ╰──────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1206 const repos_path = try std.fs.path.join(allocator, &.{ server_path, "repos" }); │ │1207 defer allocator.free(repos_path); │ │1208 const patch_author = evt.CommitAuthor{ .name = "admin", .email = "admin@example.test" }; │ │1209 + var user_repo = (try evt.openUserRepo(io, allocator, repos_path, user_id)) orelse return error.NotFound;│ │1210 + defer user_repo.deinit(io, allocator); │ │1211 var patch_ids: [patch_data.len][evt.event_id_size]u8 = undefined; │ │1212 for (patch_data, 0..) |patch, i| { │ │1213 const timestamp: u64 = @intCast(500 + i * 10); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────╮ │1214 patch_ids[i] = evt.EventWithId.randomId(random); │ │1215 const patch_hex = std.fmt.bytesToHex(patch_ids[i], .lower); │ │1199 - const path = try fork.create(.{}, io, allocator, repos_path, admin_repo, .{│ │1216 + const path = try fork.create(.{}, io, allocator, repos_path, &user_repo, .{│ │1217 .id = patch_hex, │ │1218 .user_id = user_id.*, │ │1219 .repo_id = repo_id.*, │ ╰─────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────╮ │1220 + .repo_user_id = repo_user_id.*, │ │1221 .title = patch.title, │ │1222 .description = patch.description,│ │1223 .labels = patch.labels, │ ╰───────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1264 const status = patch.status orelse continue; │ │1265 const fork_path = try fork.forkPath(allocator, repos_path, &patch_hex); │ │1266 defer allocator.free(fork_path); │ │1249 - try pch.publish(.{}, io, allocator, admin_repo, target_repo, fork_path, .{ │ │1267 + try pch.publish(.{}, io, allocator, admin_repo, &user_repo, target_repo, fork_path, .{│ │1268 .id = patch_hex, │ │1269 .user_id = user_id.*, │ │1270 .repo_id = repo_id.*, │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯