╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Events.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
757 defer allocator.free(remote_section); 758 const remote_config = config.sections.get(remote_section) orelse return error.RemoteNotFound; 759 const fetch_url = remote_config.get("url") orelse return error.UrlNotFound; 760 const push_url = remote_config.get("pushurl") orelse fetch_url; 761 const loopback_opts = " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"; 762 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 "" }); 763 defer allocator.free(fetch_ssh_command); 764 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 "" }); 765 defer allocator.free(push_ssh_command); 766 const fetch_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = fetch_ssh_command } } }; 767 const push_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = push_ssh_command } } }; 768 769 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 }); 770 defer allocator.free(fetch_refspec); 771 var fetch_opts = fetch_transport_opts; 772 fetch_opts.refspecs = &.{fetch_refspec}; 773 message.clearRetainingCapacity(); 774 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 775 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 776 return err; 777 }; 778 779 const remote_ref: rf.Ref = .{ .kind = .{ .remote = remote_name }, .name = evt.events_ref.name }; 780 const local_oid = try repo.readRef(io, evt.events_ref); 781 const remote_oid = try repo.readRef(io, remote_ref); 782 if (local_oid == null and remote_oid == null) { 783 try evt.consume(repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 784 return null; 785 } 786 if (remote_oid != null) try evt.mergeEvents(repo_kind, repo_opts, io, allocator, repo, remote_ref); 787 try evt.consume(repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 788 789 const push_refspec = try std.fmt.allocPrint(allocator, "refs/heads/{s}:refs/heads/{s}", .{ evt.events_ref.name, evt.events_ref.name }); 790 defer allocator.free(push_refspec); 791 message.clearRetainingCapacity(); 792 repo.push(io, allocator, remote_name, push_refspec, false, push_transport_opts) catch |err| { 793 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 794 return err; 795 }; 796 message.clearRetainingCapacity(); 797 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 798 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 799 return err; 800 }; 801 }, 802 } 803 }, 804 } 805 return null; 806 } 807