╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1428 repo_name: []const u8, 1429 create: bool, 1430 ) !?[]u8 { 1431 const cwd_path = try std.process.currentPathAlloc(io, allocator); 1432 defer allocator.free(cwd_path); 1433 1434 const admin_repo_path = try std.fs.path.join(allocator, &.{ cwd_path, data_dir_name, "admin" }); 1435 defer allocator.free(admin_repo_path); 1436 1437 const event_id_hex = (try evt.resolveOrCreateRepo(io, allocator, admin_repo_path, "admin", repo_name, create)) orelse return null; 1438 return try std.fs.path.join(allocator, &.{ cwd_path, data_dir_name, "repos", &event_id_hex }); 1439 } 1440 1441 // build the remote URL addressing admin/<repo_name> over the given transport 1442 fn remoteUrl( 1443 comptime transport_def: net.TransportDefinition, 1444 allocator: std.mem.Allocator, 1445 repo_name: []const u8, 1446 ) ![]u8 { 1447 return switch (transport_def) { 1448 .file => unreachable, 1449 .wire => |wire_kind| switch (wire_kind) { 1450 .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/admin/{s}", .{ http_port, repo_name }), 1451 .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/admin/{s}", .{ http_port, repo_name }), 1452 .ssh => try std.fmt.allocPrint(allocator, "git@localhost:admin/{s}", .{repo_name}), 1453 }, 1454 }; 1455 } 1456 1457 // the ssh command the haxy git client should invoke, or null when not using 1458 // ssh. haxy generates a fresh host key on every run, so accept the unknown host 1459 // and skip writing to known_hosts. 1460 fn sshCommand( 1461 is_ssh: bool, 1462 allocator: std.mem.Allocator, 1463 cwd_path: []const u8, 1464 temp_dir_name: []const u8, 1465 ) !?[]u8 { 1466 if (!is_ssh) return null; 1467 1468 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1469 defer allocator.free(priv_key_path); 1470 1471 return try std.fmt.allocPrint(allocator, "ssh -p {} -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o IdentitiesOnly=yes -o IdentityFile=\"{s}\"", .{ ssh_port, priv_key_path }); 1472 } 1473