╭ changed ─────────────╮ │src/event/PatchRev.zig│ ╰──────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │26 pub const merge_policy: evt.MergePolicy = .target_wins; │ │27 pub const record_map_key = "event-id->patchrev"; │ │28 pub const all_id_set_key = "patchrev-id-set"; │ │29 + │ │30 +// prepare a revision event and its patch reference in the caller's arena │ │31 +pub fn prepare( │ │32 + comptime repo_kind: rp.RepoKind, │ │33 + comptime repo_opts: rp.RepoOpts(repo_kind), │ │34 + state: rp.Repo(repo_kind, repo_opts).State(.read_write), │ │35 + io: std.Io, │ │36 + arena: *std.heap.ArenaAllocator, │ │37 + base_oid: *const [hash.hexLen(repo_opts.hash)]u8, │ │38 + source_oid: *const [hash.hexLen(repo_opts.hash)]u8, │ │39 + message: []const u8, │ │40 + author: evt.CommitAuthor, │ │41 + timestamp: u64, │ │42 +) !struct { event: evt.EventWithId, revision: evt.Patch.Revision } { │ │43 + const allocator = arena.allocator(); │ │44 + var base_object = try obj.Object(repo_kind, repo_opts).initCommit(state.readOnly(), io, allocator, base_oid); │ │45 + defer base_object.deinit(); │ │46 + var source_object = try obj.Object(repo_kind, repo_opts).initCommit(state.readOnly(), io, allocator, source_oid); │ │47 + defer source_object.deinit(); │ │48 + const revision = Self{ .base_oid = try allocator.dupe(u8, base_oid), .source_oid = try allocator.dupe(u8, source_oid), .message = message }; │ │49 + const identity = try std.fmt.allocPrint(allocator, "{s} <{s}>", .{ author.name, author.email }); │ │50 + defer allocator.free(identity); │ │51 + const squash = try writeSquashCommit(repo_kind, repo_opts, state, io, allocator, revision, &source_object.content.commit.tree, identity, identity, timestamp);│ │52 + var id: [evt.event_id_size]u8 = undefined; │ │53 + io.random(&id); │ │54 + const id_hex = std.fmt.bytesToHex(id, .lower); │ │55 + const entries = try allocator.alloc(evt.EventTreeEntry, 2); │ │56 + entries[0] = .{ .tree = .{ .name = "base", .oid = try allocator.dupe(u8, &base_object.content.commit.tree) } }; │ │57 + entries[1] = .{ .tree = .{ .name = "head", .oid = try allocator.dupe(u8, &source_object.content.commit.tree) } }; │ │58 + return .{ │ │59 + .event = .{ .id = id_hex, .author = author, .timestamp = timestamp, .tree_entries = entries, .event = .{ .patchrev = revision } }, │ │60 + .revision = .{ .id = id_hex, .source_oid = revision.source_oid, .squash_oid = try allocator.dupe(u8, &squash) }, │ │61 + }; │ │62 +} │ │63 │ │64 // create the mergeable squash commit represented by this patch revision │ │65 pub fn writeSquashCommit( │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯