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