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