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