╭ changed ───╮ │src/push.zig│ ╰────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 97 } │ │ 98 │ │ 99 // the oid a ref update sends when it has no side: all zeros │ │100 +// point HEAD at a pushed branch while the branch it names doesn't exist, so a │ │101 +// repo whose first push is only `main` shows it rather than an empty `master` │ │102 +fn adoptPushedBranch( │ │103 + comptime repo_opts: rp.RepoOpts(.xit), │ │104 + state: rp.Repo(.xit, repo_opts).State(.read_write), │ │105 + io: std.Io, │ │106 + updates: []const xit.net_server_receive_pack.AppliedRefUpdate, │ │107 +) !void { │ │108 + var head_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; │ │109 + const head_ref = switch ((try rf.readHead(.xit, repo_opts, state.readOnly(), io, &head_buffer)) orelse return) {│ │110 + .ref => |ref| ref, │ │111 + .oid => return, │ │112 + }; │ │113 + if (null != try rf.readRecur(.xit, repo_opts, state.readOnly(), io, .{ .ref = head_ref })) return; │ │114 + for (updates) |update| { │ │115 + if (zeroOid(update.new_oid)) continue; │ │116 + const ref = rf.Ref.initFromPath(update.ref_name, null) orelse continue; │ │117 + // the events branch holds haxy's metadata, not the project │ │118 + if (ref.kind != .head or std.mem.eql(u8, ref.name, evt.events_ref.name)) continue; │ │119 + return rf.replaceHead(.xit, repo_opts, state, io, .{ .ref = ref }); │ │120 + } │ │121 +} │ │122 + │ │123 fn zeroOid(oid: []const u8) bool { │ │124 for (oid) |char| if (char != '0') return false; │ │125 return true; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │195 // lets go of the lock. │ │196 const applied = ctx.updates.items.items; │ │197 if (applied.len == 1 and std.mem.eql(u8, applied[0].ref_name, clear_undo_ref)) return error.ClearUndoHistory;│ │198 + try adoptPushedBranch(repo_opts, state, ctx.io, applied); │ │199 try writeReceivedPatches(repo_opts, state, ctx.io, ctx.allocator, ctx.response, ctx.writer); │ │200 if (ctx.sideband.gone) return error.ClientGone; │ │201 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯