╭ changed ─────────────╮ │src/event/PatchRev.zig│ ╰──────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────╮ │27 pub const record_map_key = "event-id->patchrev"; │ │28 pub const id_set_key = "patchrev-id-set"; │ │29 │ │30 +// create the mergeable squash commit represented by this patch revision │ │31 +pub fn writeSquashCommit( │ │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 + allocator: std.mem.Allocator, │ │37 + event: Self, │ │38 + head_tree_oid: *const [hash.hexLen(repo_opts.hash)]u8, │ │39 + author: []const u8, │ │40 + committer: []const u8, │ │41 + timestamp: u64, │ │42 +) ![hash.hexLen(repo_opts.hash)]u8 { │ │43 + var base_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; │ │44 + if (event.base_oid.len != base_oid.len) return error.InvalidPatch; │ │45 + @memcpy(&base_oid, event.base_oid); │ │46 + try validateOid(repo_opts.hash, &base_oid); │ │47 + const parent_oids = [_][hash.hexLen(repo_opts.hash)]u8{base_oid}; │ │48 + return try obj.writeCommitWithoutRef(repo_kind, repo_opts, state, io, allocator, .{│ │49 + .author = author, │ │50 + .committer = committer, │ │51 + .message = event.message, │ │52 + .parent_oids = &parent_oids, │ │53 + .timestamp = timestamp, │ │54 + }, head_tree_oid); │ │55 +} │ │56 + │ │57 pub fn readTrees( │ │58 comptime repo_kind: rp.RepoKind, │ │59 comptime repo_opts: rp.RepoOpts(repo_kind), │ ╰───────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────╮ │116 │ │117 try validateOid(hash_kind, record.event.base_oid); │ │118 try validateOid(hash_kind, record.event.source_oid); │ │ 92 - if (!std.mem.startsWith(u8, record.event.target_ref, "refs/heads/") or │ │ 93 - !xit.ref.validateName(record.event.target_ref["refs/".len..])) return error.InvalidTarget;│ │119 + try validateTarget(record.event.target_ref); │ │120 try validateOid(hash_kind, record.event_oid); │ │121 try validateOid(hash_kind, record.base_tree_oid); │ │122 try validateOid(hash_kind, record.head_tree_oid); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────╮ │148 } │ │149 } │ │150 │ │125 -fn validateOid(comptime hash_kind: hash.HashKind, oid: []const u8) !void { │ │151 +pub fn validateOid(comptime hash_kind: hash.HashKind, oid: []const u8) !void { │ │152 var bytes: [hash.byteLen(hash_kind)]u8 = undefined; │ │153 _ = try std.fmt.hexToBytes(&bytes, oid); │ │154 if (!std.mem.eql(u8, oid, &std.fmt.bytesToHex(bytes, .lower))) return error.InvalidOid;│ ╰────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────╮ │155 } │ │156 │ │157 +pub fn validateTarget(target_ref: []const u8) !void { │ │158 + if (!std.mem.startsWith(u8, target_ref, "refs/heads/") or │ │159 + !xit.ref.validateName(target_ref["refs/".len..])) return error.InvalidTarget;│ │160 +} │ │161 + │ │162 pub fn readById( │ │163 comptime DB: type, │ │164 comptime hash_kind: hash.HashKind, │ ╰──────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────╮ │194 return null; │ │195 } │ │196 │ │166 -// derived commits referenced only by patch revision records│ │197 +// squash commits referenced only by patch revision records │ │198 pub fn gcRoots( │ │199 comptime DB: type, │ │200 comptime hash_kind: hash.HashKind, │ ╰─────────────────────────────────────────────────────────────────╯