╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Events.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
652 const repo_opts = repo.self_repo_opts; 653 const remote_name = (try remoteName(repo_kind, repo_opts, repo, io, allocator)) orelse return error.RemoteNotFound; 654 defer allocator.free(remote_name); 655 656 var config = try repo.listConfig(io, allocator); 657 defer config.deinit(); 658 const configured_ssh = if (config.sections.get("core")) |core| core.get("sshcommand") else null; 659 const ssh = if (configured_ssh) |command| if (command.len > 0) command else "ssh" else "ssh"; 660 const remote_section = try std.fmt.allocPrint(allocator, "remote.{s}", .{remote_name}); 661 defer allocator.free(remote_section); 662 const remote_config = config.sections.get(remote_section) orelse return error.RemoteNotFound; 663 const fetch_url = remote_config.get("url") orelse return error.UrlNotFound; 664 const push_url = remote_config.get("pushurl") orelse fetch_url; 665 const loopback_opts = " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"; 666 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 "" }); 667 defer allocator.free(fetch_ssh_command); 668 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 "" }); 669 defer allocator.free(push_ssh_command); 670 const fetch_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = fetch_ssh_command } } }; 671 const push_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = push_ssh_command } } }; 672 673 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 }); 674 defer allocator.free(fetch_refspec); 675 var fetch_opts = fetch_transport_opts; 676 fetch_opts.refspecs = &.{fetch_refspec}; 677 message.clearRetainingCapacity(); 678 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 679 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 680 return err; 681 }; 682 683 const remote_ref: rf.Ref = .{ .kind = .{ .remote = remote_name }, .name = evt.events_ref.name }; 684 const local_oid = try repo.readRef(io, evt.events_ref); 685 const remote_oid = try repo.readRef(io, remote_ref); 686 if (local_oid == null and remote_oid == null) { 687 try evt.consume(repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 688 return null; 689 } 690 if (remote_oid != null) try evt.mergeEvents(repo_kind, repo_opts, io, allocator, repo, remote_ref); 691 try evt.consume(repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 692 693 const push_refspec = try std.fmt.allocPrint(allocator, "refs/heads/{s}:refs/heads/{s}", .{ evt.events_ref.name, evt.events_ref.name }); 694 defer allocator.free(push_refspec); 695 message.clearRetainingCapacity(); 696 repo.push(io, allocator, remote_name, push_refspec, false, push_transport_opts) catch |err| { 697 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 698 return err; 699 }; 700 message.clearRetainingCapacity(); 701 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 702 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 703 return err; 704 }; 705 }, 706 } 707 }, 708 } 709 return null; 710 } 711