╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Events.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
832 defer allocator.free(remote_name); 833 834 var config = try repo.listConfig(io, allocator); 835 defer config.deinit(); 836 const configured_ssh = if (config.sections.get("core")) |core| core.get("sshcommand") else null; 837 const ssh = if (configured_ssh) |command| if (command.len > 0) command else "ssh" else "ssh"; 838 const remote_section = try std.fmt.allocPrint(allocator, "remote.{s}", .{remote_name}); 839 defer allocator.free(remote_section); 840 const remote_config = config.sections.get(remote_section) orelse return error.RemoteNotFound; 841 const fetch_url = remote_config.get("url") orelse return error.UrlNotFound; 842 const push_url = remote_config.get("pushurl") orelse fetch_url; 843 const loopback_opts = " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"; 844 const fetch_ssh_command = try std.fmt.allocPrint(allocator, "{s}{s} -o BatchMode=yes -o LogLevel=QUIET", .{ ssh, if (isLoopbackSshUrl(fetch_url)) loopback_opts else "" }); 845 defer allocator.free(fetch_ssh_command); 846 const push_ssh_command = try std.fmt.allocPrint(allocator, "{s}{s} -o BatchMode=yes -o LogLevel=QUIET", .{ ssh, if (isLoopbackSshUrl(push_url)) loopback_opts else "" }); 847 defer allocator.free(push_ssh_command); 848 const fetch_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = fetch_ssh_command } } }; 849 const push_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = push_ssh_command } } }; 850 851 const fetch_refspec = try std.fmt.allocPrint(allocator, "+refs/heads/{s}:refs/remotes/{s}/{s}", .{ evt.events_ref.name, remote_name, evt.events_ref.name }); 852 defer allocator.free(fetch_refspec); 853 var fetch_opts = fetch_transport_opts; 854 fetch_opts.refspecs = &.{fetch_refspec}; 855 message.clearRetainingCapacity(); 856 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 857 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 858 return err; 859 }; 860 861 const remote_ref: rf.Ref = .{ .kind = .{ .remote = remote_name }, .name = evt.events_ref.name }; 862 const local_oid = try repo.readRef(io, evt.events_ref); 863 const remote_oid = try repo.readRef(io, remote_ref); 864 if (local_oid == null and remote_oid == null) { 865 try evt.consume(.local, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 866 return null; 867 } 868 if (remote_oid != null) try evt.mergeEvents(repo_kind, repo_opts, io, allocator, repo, remote_ref); 869 try evt.consume(.local, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 870 871 const push_refspec = try std.fmt.allocPrint(allocator, "refs/heads/{s}:refs/heads/{s}", .{ evt.events_ref.name, evt.events_ref.name }); 872 defer allocator.free(push_refspec); 873 message.clearRetainingCapacity(); 874 repo.push(io, allocator, remote_name, push_refspec, false, push_transport_opts) catch |err| { 875 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 876 return err; 877 }; 878 message.clearRetainingCapacity(); 879 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 880 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 881 return err; 882 }; 883 }, 884 } 885 }, 886 } 887 return null; 888 } 889