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