╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────╮ │124 name: []const u8, │ │125 oid: []const u8, │ │126 }, │ │127 +}; │ │128 + │ │129 +pub const HostKind = enum { │ │130 + local, │ │131 + server, │ │132 }; │ │133 │ │134 // who a commit is attributed to│ ╰─────────────────────────────────────╯ ╭────────────────────────────────────────────────────╮ │245 │ │246 // remove an event by emitting a null payload │ │247 pub fn remove( │ │248 + host_kind: HostKind, │ │249 comptime role: RepoRole, │ │250 comptime repo_kind: rp.RepoKind, │ │251 comptime repo_opts: rp.RepoOpts(repo_kind),│ ╰────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │283 .patchrev => .{ .patchrev = null }, │ │284 .patch => .{ .patch = null }, │ │285 }; │ │280 - try consume(role, repo_kind, repo_opts, io, allocator, repo, events_ref, &.{.{ │ │286 + try consume(host_kind, role, repo_kind, repo_opts, io, allocator, repo, events_ref, &.{.{│ │287 .id = std.fmt.bytesToHex(id.*, .lower), │ │288 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), │ │289 .author = author, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │294 // commit `events` (if any) as JSON commit messages on `ref`, then consume the│ │295 // events on `ref` into the db the repo's views read: the repo's own db for a │ │296 // xit repo, or the standalone event db next to a git repo. for a xit repo the│ │291 -// commits and the consume run in one transaction. │ │297 +// commits and the consume run in one transaction. server writes refresh │ │298 +// mergeability after the transaction releases its lock. │ │299 pub fn consume( │ │300 + host_kind: HostKind, │ │301 comptime role: RepoRole, │ │302 comptime repo_kind: rp.RepoKind, │ │303 comptime repo_opts: rp.RepoOpts(repo_kind), │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────╮ │380 .events = events, │ │381 .first_parent_oids = first_parent_oids,│ │382 }) catch |err| switch (err) { │ │375 - error.CancelTransaction => {}, │ │383 + error.CancelTransaction => return, │ │384 else => |e| return e, │ │385 }; │ │386 }, │ ╰────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────╮ │387 } │ │388 + │ │389 + if (role == .repo and repo_kind == .xit and host_kind == .server) { │ │390 + // syncing history may affect several patches │ │391 + if (events.len == 0) { │ │392 + pch.refreshMergeability(repo_opts, io, allocator, repo, null); │ │393 + return; │ │394 + } │ │395 + │ │396 + // ordinary edits only need to refresh the patches they change │ │397 + for (events) |event| { │ │398 + if (event.event != .patch) continue; │ │399 + const id = parseEventId(&event.id) catch continue; │ │400 + pch.refreshMergeability(repo_opts, io, allocator, repo, id); │ │401 + } │ │402 + } │ │403 } │ │404 │ │405 // merge the remote events ref into the local events ref without touching head,│ ╰────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1556 io.random(&id_bytes); │ │1557 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); │ │1558 │ │1536 - try consume(.admin, .xit, admin_repo_opts, io, allocator, &repo, events_ref, &[_]EventWithId{.{ │ │1559 + try consume(.server, .admin, .xit, admin_repo_opts, io, allocator, &repo, events_ref, &[_]EventWithId{.{│ │1560 .id = event_id_hex, │ │1561 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), │ │1562 .author = .{ .name = owner.event.name, .email = owner.event.email }, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯