╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1271 // build the remote URL addressing admin/<repo_name> over the given transport 1272 fn remoteUrl( 1273 comptime transport_def: net.TransportDefinition, 1274 allocator: std.mem.Allocator, 1275 repo_name: []const u8, 1276 ) ![]u8 { 1277 return switch (transport_def) { 1278 .file => unreachable, 1279 .wire => |wire_kind| switch (wire_kind) { 1280 .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/admin/{s}", .{ http_port, repo_name }), 1281 .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/admin/{s}", .{ http_port, repo_name }), 1282 .ssh => try std.fmt.allocPrint(allocator, "git@localhost:admin/{s}", .{repo_name}), 1283 }, 1284 }; 1285 } 1286 1287 // the ssh command the haxy git client should invoke, or null when not using 1288 // ssh. haxy generates a fresh host key on every run, so accept the unknown host 1289 // and skip writing to known_hosts. 1290 fn sshCommand( 1291 is_ssh: bool, 1292 allocator: std.mem.Allocator, 1293 cwd_path: []const u8, 1294 temp_dir_name: []const u8, 1295 ) !?[]u8 { 1296 if (!is_ssh) return null; 1297 1298 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1299 defer allocator.free(priv_key_path); 1300 1301 return try std.fmt.allocPrint(allocator, "ssh -p {} -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=\"{s}\"", .{ ssh_port, priv_key_path }); 1302 } 1303