╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Events.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
437 } 438 439 fn contentStack(self: *View) *wgt.Stack(ui.Widget) { 440 return &self.box.children.values()[content_index].widget.stack; 441 } 442 443 fn selectedView(self: *View) ui.RoutablePage.EventsView { 444 const stack = self.contentStack(); 445 const id = stack.getFocus().child_id orelse return .active; 446 return @enumFromInt(stack.children.getIndex(id) orelse 0); 447 } 448 449 fn eventWindow(self: *View) *const Window { 450 return self.data.window(self.selectedView()); 451 } 452 453 fn content(self: *View) *wgt.Box(ui.Widget) { 454 const stack = self.contentStack(); 455 return &stack.children.values()[@intFromEnum(self.selectedView())].box; 456 } 457 458 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 459 return &self.content().children.values()[list_index].widget.scroll; 460 } 461 462 fn listBox(self: *View) *wgt.Box(ui.Widget) { 463 return &self.listScroll().child.box; 464 } 465 466 fn detailScroll(self: *View) *wgt.Scroll(ui.Widget) { 467 return &self.content().children.values()[detail_index].widget.scroll; 468 } 469 470 fn detailBox(self: *View) *wgt.Box(ui.Widget) { 471 return &self.detailScroll().child.box; 472 } 473 474 fn detailActive(self: *View) bool { 475 return self.content().getFocus().child_id == self.detailScroll().getFocus().id; 476 } 477 478 fn headerActive(self: *View) bool { 479 return self.box.getFocus().child_id == self.header().getFocus().id; 480 } 481 482 fn selectedEventIndex(self: *View) ?usize { 483 const id = self.listBox().getFocus().child_id orelse return null; 484 const index = self.listBox().children.getIndex(id) orelse return null; 485 return if (index < self.eventWindow().events.len) index else null; 486 } 487 488 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 489 self.clearGrid(); 490 if (self.header().getSelectedIndex()) |index| 491 self.contentStack().getFocus().child_id = self.contentStack().children.keys()[index]; 492 try self.refreshDetail(allocator); 493 494 const list = self.listBox(); 495 for (list.children.keys(), list.children.values()) |id, *child| switch (child.widget) { 496 .text_box => |*text_box| ui.widget.markSelected(text_box, list.getFocus().child_id == id), 497 else => {}, 498 }; 499 500 const both_fit = if (constraint.max_size.width) |width| width >= list_max_width + detail_min_width else true; 501 self.content().children.values()[list_index].max_size = if (both_fit) .{ .width = list_max_width, .height = null } else null; 502 const detail_width = if (constraint.max_size.width) |width| if (both_fit) width - list_max_width else width else detail_min_width; 503 self.content().children.values()[detail_index].min_size = .{ .width = detail_width, .height = null }; 504 for (self.detailBox().children.values()) |*child| child.max_size = .{ .width = detail_width -| 2, .height = null }; 505 506 try self.box.build(allocator, constraint, root_focus); 507 } 508 509 fn refreshDetail(self: *View, allocator: std.mem.Allocator) !void { 510 const index = self.selectedEventIndex() orelse return; 511 const detailed_index = &self.detailed_index[@intFromEnum(self.selectedView())]; 512 if (detailed_index.*) |old| if (old == index) return; 513 const box = self.detailBox(); 514 for (box.children.values()) |*child| child.widget.deinit(allocator); 515 box.children.clearAndFree(allocator); 516 box.getFocus().child_id = null; 517 518 const item = self.eventWindow().events[index]; 519 if (item.view_url) |url| { 520 var link = try wgt.TextBox.init(allocator, "view event", .{ .border_style = .single, .round_corners = true, .wrap_kind = .none }); 521 errdefer link.deinit(allocator); 522 link.getFocus().mode = .all; 523 link.getFocus().kind = .{ .custom = try std.fmt.allocPrint(self.session.page_arena.allocator(), "a:{s}", .{url}) }; 524 try box.children.put(allocator, link.getFocus().id, .{ .widget = .{ .text_box = link }, .rect = null, .min_size = null }); 525 } 526 { 527 var kind = try wgt.TextBox.init(allocator, @tagName(item.kind), .{ .border_style = .single, .round_corners = true, .wrap_kind = .word, .label = " kind " }); 528 errdefer kind.deinit(allocator); 529 kind.getFocus().mode = .all; 530 try box.children.put(allocator, kind.getFocus().id, .{ .widget = .{ .text_box = kind }, .rect = null, .min_size = null }); 531 } 532 { 533 var author = try ui.authorBox(allocator, self.session.page_arena, item.author); 534 errdefer author.deinit(allocator); 535 try box.children.put(allocator, author.getFocus().id, .{ .widget = .{ .text_box = author }, .rect = null, .min_size = null }); 536 } 537 538 if (box.children.count() > 0) box.getFocus().child_id = box.children.keys()[0]; 539 self.detailScroll().x = 0; 540 self.detailScroll().y = 0; 541 self.detailScroll().getFocus().version +%= 1; 542 detailed_index.* = index; 543 } 544 545 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 546 // scrolling crosses the sub header boundary the same way arrows do 547 const direction = inp.vertDirection(key); 548 if (self.headerActive()) { 549 if (direction == .down) root_focus.setFocus(self.content().getFocus().id) else try self.header().input(allocator, key, root_focus); 550 return; 551 } 552 if (direction == .up and self.contentAtTop()) { 553 self.header().focusCurrent(root_focus); 554 return; 555 } 556 if (self.detailActive()) { 557 if (key == .arrow_left) { 558 root_focus.setFocus(self.listScroll().getFocus().id); 559 } else if (inp.rowDelta(key, @intCast(self.detailBox().children.count()))) |delta| { 560 ui.widget.moveRowFocus(self.detailBox(), self.detailScroll(), root_focus, delta); 561 } 562 } else if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 563 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 564 } else switch (key) { 565 .arrow_right => if (self.detailBox().children.count() > 0) root_focus.setFocus(self.detailScroll().getFocus().id), 566 .enter => if (self.selectedEventIndex() != null) root_focus.setFocus(self.detailScroll().getFocus().id), 567 else => {}, 568 } 569 } 570 571 fn contentAtTop(self: *View) bool { 572 const box = if (self.detailActive()) self.detailBox() else self.listBox(); 573 const scroll = if (self.detailActive()) self.detailScroll() else self.listScroll(); 574 const id = box.getFocus().child_id orelse return true; 575 return box.children.getIndex(id) == 0 and scroll.y == 0; 576 } 577 578 pub fn atTop(self: *View) bool { 579 return self.headerActive(); 580 } 581 582 // arriving from the page's tabs lands on the sub header, not the content 583 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 584 self.header().focusCurrent(root_focus); 585 return true; 586 } 587 588 pub fn clearGrid(self: *View) void { 589 self.box.clearGrid(); 590 } 591 592 pub fn getGrid(self: View) ?Grid { 593 return self.box.getGrid(); 594 } 595 596 pub fn getFocus(self: *View) *Focus { 597 return self.box.getFocus(); 598 } 599 }; 600 601 pub const Header = struct { 602 sync_status: ?[]const u8, 603 604 const nothing = "nothing to sync"; 605 const unsynced = "sync needed!"; 606 607 const Progress = struct { 608 message: *std.Io.Writer.Allocating, 609 610 pub fn run(self: @This(), _: std.Io, event: rp.ProgressEvent) !void { 611 switch (event) { 612 .text => |value| { 613 self.message.clearRetainingCapacity(); 614 try self.message.writer.writeAll(value); 615 }, 616 else => {}, 617 } 618 } 619 }; 620 621 pub fn local( 622 comptime repo_kind: rp.RepoKind, 623 comptime repo_opts: rp.RepoOpts(repo_kind), 624 aa: std.mem.Allocator, 625 repo: *rp.Repo(repo_kind, repo_opts), 626 io: std.Io, 627 failure: ?[]const u8, 628 ) !Header { 629 if (failure != null) return Header.empty(aa, failure); 630 const remote_name = (try remoteName(repo_kind, repo_opts, repo, io, aa)) orelse return .{ .sync_status = nothing }; 631 const remote_ref: rf.Ref = .{ .kind = .{ .remote = remote_name }, .name = evt.events_ref.name }; 632 const local_oid = (try repo.readRef(io, evt.events_ref)) orelse return .{ .sync_status = nothing }; 633 const remote_oid = (try repo.readRef(io, remote_ref)) orelse return .{ .sync_status = nothing }; 634 return .{ .sync_status = if (std.mem.eql(u8, &local_oid, &remote_oid)) nothing else unsynced }; 635 } 636 637 pub fn empty(aa: std.mem.Allocator, failure: ?[]const u8) !Header { 638 return .{ .sync_status = if (failure) |name| try std.fmt.allocPrint(aa, "error: {s}", .{name}) else nothing }; 639 } 640 641 pub fn remote() Header { 642 return .{ .sync_status = null }; 643 } 644 645 pub const View = struct { 646 box: wgt.Box(ui.Widget), 647 session: *ui.Session, 648 tab_ids: [2]usize, 649 // the tab stays selected while the sync button has focus 650 selected_tab: usize, 651 button_id: ?usize, 652 653 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !Header.View { 654 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 655 errdefer box.deinit(allocator); 656 var tab_ids: [2]usize = undefined; 657 const view_labels = [_][]const u8{ active_tab_label, removed_tab_label }; 658 inline for ([_]ui.RoutablePage.EventsView{ .active, .removed }, view_labels, 0..) |view, view_label, i| { 659 const route = ui.RoutablePage.repoEventsRoute(data.identity, view, null, "", data.moment) orelse return error.RouteTooLong; 660 const count = data.window(view).count; 661 var label_buf: [64]u8 = undefined; 662 const label = try std.fmt.bufPrint(&label_buf, "{s} ({d})", .{ view_label, count }); 663 var tab = try wgt.TextBox.init(allocator, label, .{ .border_style = .hidden, .round_corners = true, .wrap_kind = .none }); 664 errdefer tab.deinit(allocator); 665 tab.getFocus().mode = .all; 666 const selected = std.meta.activeTag(session.data.current_page) == .repo_events and data.view == view; 667 tab.getFocus().kind = .{ .custom = try ui.inPageTabLink(session, route, selected) }; 668 tab_ids[i] = tab.getFocus().id; 669 try box.children.put(allocator, tab.getFocus().id, .{ .widget = .{ .text_box = tab }, .rect = null, .min_size = .{ .width = label.len + 2, .height = null } }); 670 } 671 672 var button_id: ?usize = null; 673 if (data.header.sync_status != null) { 674 box.getFocus().kind = .{ .custom = "form:/sync" }; 675 var button = try wgt.TextBox.init(allocator, "sync", .{ .border_style = .single, .round_corners = true, .wrap_kind = .none }); 676 errdefer button.deinit(allocator); 677 button.getFocus().mode = .all; 678 button.getFocus().kind = .{ .custom = "submit" }; 679 button_id = button.getFocus().id; 680 try box.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = null }); 681 } 682 683 if (data.header.sync_status) |status_text| { 684 var status = try wgt.TextBox.init(allocator, status_text, .{ .border_style = .hidden, .wrap_kind = .none }); 685 errdefer status.deinit(allocator); 686 try box.children.put(allocator, status.getFocus().id, .{ .widget = .{ .text_box = status }, .rect = null, .min_size = null, .flex = .shrink }); 687 } 688 box.getFocus().child_id = tab_ids[@intFromEnum(data.view)]; 689 return .{ .box = box, .session = session, .tab_ids = tab_ids, .selected_tab = @intFromEnum(data.view), .button_id = button_id }; 690 } 691 692 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 693 self.box.deinit(allocator); 694 } 695 696 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 697 self.clearGrid(); 698 if (self.getSelectedIndex()) |index| self.selected_tab = index; 699 for (self.tab_ids, 0..) |id, index| { 700 const child = self.box.children.getPtr(id) orelse continue; 701 const tab = switch (child.widget) { 702 .text_box => |*text_box| text_box, 703 else => continue, 704 }; 705 ui.widget.markSelected(tab, index == self.selected_tab); 706 } 707 try self.box.build(allocator, constraint, root_focus); 708 } 709 710 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 711 const selected = self.box.getFocus().child_id orelse return; 712 const current = self.box.children.getIndex(selected) orelse return; 713 const count = 2 + @as(usize, @intFromBool(self.button_id != null)); 714 if (inp.moveTab(key, current, count)) |next| { 715 root_focus.setFocus(self.box.children.keys()[next]); 716 return; 717 } 718 switch (key) { 719 .enter => if (self.syncFocused()) try self.requestSync(allocator), 720 .mouse => |mouse| if (self.button_id) |id| if (inp.leftClickOn(root_focus, id, mouse)) try self.requestSync(allocator), 721 else => {}, 722 } 723 } 724 725 fn requestSync(self: *Header.View, allocator: std.mem.Allocator) !void { 726 if (!self.session.is_terminal) return; 727 if (self.session.host_request != null) return; 728 const button_id = self.button_id orelse return; 729 const child = self.box.children.getPtr(button_id) orelse return; 730 const button = switch (child.widget) { 731 .text_box => |*button| button, 732 else => return, 733 }; 734 try button.setContent(allocator, "syncing..."); 735 self.session.host_request = .sync_events; 736 } 737 738 fn syncFocused(self: *Header.View) bool { 739 const button_id = self.button_id orelse return false; 740 return self.box.getFocus().child_id == button_id; 741 } 742 743 pub fn getSelectedIndex(self: *Header.View) ?usize { 744 const id = self.box.getFocus().child_id orelse return null; 745 return std.mem.indexOfScalar(usize, &self.tab_ids, id); 746 } 747 748 pub fn focusCurrent(self: *Header.View, root_focus: *Focus) void { 749 root_focus.setFocus(self.box.getFocus().child_id orelse self.tab_ids[0]); 750 } 751 752 pub fn clearGrid(self: *Header.View) void { 753 self.box.clearGrid(); 754 } 755 756 pub fn getGrid(self: Header.View) ?Grid { 757 return self.box.getGrid(); 758 } 759 760 pub fn getFocus(self: *Header.View) *Focus { 761 return self.box.getFocus(); 762 } 763 }; 764 }; 765 766 pub fn performSync(allocator: std.mem.Allocator, session: *ui.Session) !void { 767 if (comptime builtin.target.cpu.arch == .wasm32) return; 768 const io = session.io orelse return; 769 const source = session.local orelse return; 770 defer session.refresh_requested = true; 771 const failure = sync(io, allocator, source) catch |err| { 772 session.data.sync_failure = @errorName(err); 773 return; 774 }; 775 if (failure) |message| { 776 defer allocator.free(message); 777 session.data.sync_failure = try session.arena.allocator().dupe(u8, message); 778 return; 779 } 780 session.data.sync_failure = null; 781 switch (session.data.current_page) { 782 .repo_events => |route| { 783 if (ui.RoutablePage.repoEventsRoute(route.name.slice(), route.view, null, "", route.moment)) |first| 784 session.data.current_page = first; 785 }, 786 else => {}, 787 } 788 } 789 790 fn remoteName( 791 comptime repo_kind: rp.RepoKind, 792 comptime repo_opts: rp.RepoOpts(repo_kind), 793 repo: *rp.Repo(repo_kind, repo_opts), 794 io: std.Io, 795 allocator: std.mem.Allocator, 796 ) !?[]u8 { 797 var remotes = try repo.listRemotes(io, allocator); 798 defer remotes.deinit(); 799 const names = remotes.sections.keys(); 800 if (names.len == 0) return null; 801 for (names) |name| { 802 const remote_ref: rf.Ref = .{ .kind = .{ .remote = name }, .name = evt.events_ref.name }; 803 if (try repo.readRef(io, remote_ref) != null) return try allocator.dupe(u8, name); 804 } 805 return try allocator.dupe(u8, names[0]); 806 } 807 808 fn isLoopbackSshUrl(url: []const u8) bool { 809 const uri = std.Uri.parse(url) catch return false; 810 const host = switch (uri.host orelse return false) { 811 .raw => |value| value, 812 .percent_encoded => |value| value, 813 }; 814 return std.mem.eql(u8, host, "localhost") or 815 std.mem.eql(u8, host, "127.0.0.1") or 816 std.mem.eql(u8, host, "::1") or 817 std.mem.eql(u8, host, "[::1]"); 818 } 819 820 pub fn sync(io: std.Io, allocator: std.mem.Allocator, source: ui.RepoSource) !?[]u8 { 821 var message: std.Io.Writer.Allocating = .init(allocator); 822 defer message.deinit(); 823 824 switch (source.repo_kind) { 825 inline else => |repo_kind| { 826 var any_repo = try rp.AnyRepo(repo_kind, .{ .ProgressCtx = Header.Progress }).open(io, allocator, source.localInitOpts()); 827 defer any_repo.deinit(io, allocator); 828 switch (any_repo) { 829 inline else => |*repo| { 830 const repo_opts = repo.self_repo_opts; 831 const remote_name = (try remoteName(repo_kind, repo_opts, repo, io, allocator)) orelse return error.RemoteNotFound; 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