git_policy_cli/transaction_journal.rs
1//! What:
2//! The values a commit's preparation and the service's landing share about the repository state they work on: the base,
3//! the symbolic head, the private index mode, the sequencer conclusion, the ref storage format and a policy-added path.
4//! Why:
5//! The records the earlier transaction wrote into its registry (preparing, prepared, ref-updated, landing and index-lock
6//! records) are gone with the transaction; only the types the service route still passes between its steps remain
7//! (`src/policy-engine/commit-transaction-journal-states.ts` is their incumbent).
8//!
9//! In TS you'd write (pseudocode):
10//! ```ts
11//! type Base = { kind: 'unborn' } | { kind: 'commit'; oid: string };
12//! ```
13
14
15/// What:
16/// The target at invocation,
17/// or the expected old target of a landing.
18/// Why:
19/// An unborn branch has no commit;
20/// compare-and-swap then expects the all-zero OID.
21///
22/// In TS you'd write (pseudocode):
23/// ```ts
24/// type PreparationBase = { kind: 'unborn' } | { kind: 'commit'; oid: string };
25/// ```
26#[derive(Clone, Debug, Eq, PartialEq)]
27pub enum Base {
28 /// The target names no commit yet.
29 Unborn,
30 /// The target names this commit.
31 Commit(String),
32}
33
34/// What:
35/// The symbolic `HEAD` target at invocation.
36/// Why:
37/// A branch switch between preparation and landing fails the commit.
38///
39/// In TS you'd write (pseudocode):
40/// ```ts
41/// type SymbolicHeadTarget = { kind: 'branch'; ref: string } | { kind: 'detached' };
42/// ```
43#[derive(Clone, Debug, Eq, PartialEq)]
44pub enum SymbolicHead {
45 /// `HEAD` is symbolic to this ref.
46 Branch(String),
47 /// `HEAD` is detached.
48 Detached,
49}
50
51/// What:
52/// How the commit selects its content.
53/// Why:
54/// Explicit-path commits build the tree from the base plus selected paths;
55/// index
56/// commits use the captured index.
57///
58/// In TS you'd write (pseudocode):
59/// ```ts
60/// type TransactionMode = 'explicit-path' | 'index';
61/// ```
62#[derive(Clone, Copy, Debug, Eq, PartialEq)]
63pub enum TransactionMode {
64 /// `git commit -- <paths>` with commit-only semantics.
65 ExplicitPath,
66 /// A commit of the index.
67 Index,
68}
69
70/// What:
71/// The commit kind that decides whether a moved target fails instead of replaying.
72/// Why:
73/// An amend or a conclusion cannot replay onto a moved branch.
74///
75/// In TS you'd write (pseudocode):
76/// ```ts
77/// type ConclusionKind = 'none' | 'amend' | 'merge' | 'cherry-pick' | 'revert';
78/// ```
79#[derive(Clone, Copy, Debug, Eq, PartialEq)]
80pub enum Conclusion {
81 /// An ordinary commit.
82 None,
83 /// `--amend`.
84 Amend,
85 /// The conclusion of a merge.
86 Merge,
87 /// The conclusion of a cherry-pick.
88 CherryPick,
89 /// The conclusion of a revert.
90 Revert,
91}
92
93/// What:
94/// The ref storage backend of the real repository.
95/// Why:
96/// The shadow ref snapshot and the conclusion pseudorefs differ by backend.
97///
98/// In TS you'd write (pseudocode):
99/// ```ts
100/// type RefStorageFormat = 'files' | 'reftable';
101/// ```
102#[derive(Clone, Copy, Debug, Eq, PartialEq)]
103pub enum RefFormat {
104 /// Loose refs and `packed-refs`.
105 Files,
106 /// The reftable backend.
107 Reftable,
108}
109
110
111/// What:
112/// One policy-added path,
113/// or one selected path whose worktree copy receives settled
114/// bytes:
115/// its mode,
116/// the blob before the commit and the blob the commit lands.
117/// Why:
118/// After landing,
119/// the worktree copy is replaced only while it still holds the original.
120///
121/// In TS you'd write (pseudocode):
122/// ```ts
123/// type AddedPathRecord = { path: string; gitMode: '100644' | '100755'; originalOid: string; intendedOid: string };
124/// ```
125#[derive(Clone, Debug, Eq, PartialEq)]
126pub struct AddedPath {
127 /// Repository-relative path, the exact bytes Git reported.
128 pub path: Vec<u8>,
129 /// `100644` or `100755`.
130 pub git_mode: String,
131 /// Blob at `HEAD`,
132 /// in the real index and in the worktree before the commit.
133 pub original_oid: String,
134 /// Blob the commit lands and the worktree receives.
135 pub intended_oid: String,
136}