1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! What:
//! One complete policy pass over the shipped policies:
//! the built-in policies,
//! then
//! the fixed argument transforms of a forwarded command,
//! then the optional policies.
//! Why:
//! Every lifecycle runs the same three stages in the same order,
//! and each stage can
//! end the pass.
//! Keeping the sequence in one place means a wrapped command and a
//! direct `git cli-git check` cannot drift apart in what they run or when they stop.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! // const result = await runPolicyEngine({ args, trigger, config, selectedPolicyIds });
//! ```
/// What:
/// `use` brings names from sibling files into this file;
/// `super::` means "the parent
/// module",
/// where every sibling file of this crate is declared.
/// Why:
/// The pass joins the stage runner,
/// the shipped checks and the fixed transforms.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// import { runPolicyStage } from './policy_engine.ts';
/// ```
use crateShippedChecks;
use crate;
use cratePolicyEvent;
use crate;
use crate;
use crateTrigger;
use crateRepositoryFacts;
/// What:
/// `OsString` is owned operating-system text of raw bytes.
/// Sibling the reader might
/// expect:
/// `String`,
/// which must be valid UTF-8.
/// Why:
/// The pass hands back the arguments Git will receive,
/// byte for byte.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// // string, but byte-preserving.
/// ```
use OsString;
/// What:
/// What one pass produced.
/// A `struct` is a record with named fields;
/// `Vec<T>` is an
/// owned list.
/// `#[derive(...)]` asks the compiler to generate copying,
/// debug
/// printing and `==`.
/// Why:
/// The caller needs the arguments to forward,
/// every event in emission order,
/// and
/// how the pass ended.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type PassResult = { args: string[]; events: PolicyEvent[]; end: StageEnd };
/// ```
/// What:
/// The shipped policies of one kind,
/// in registry order.
/// `optional` selects the
/// policies that are off unless the configuration lists them;
/// `Vec<PolicyId>` is the
/// owned result.
/// Why:
/// The registry is the only list of policies;
/// the two stages are its two halves,
/// so
/// a policy added there lands in exactly one stage without a second list to update.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const policiesOfKind = (optional: boolean) => POLICY_REGISTRY.filter(p => p.offUnlessListed === optional).map(p => p.id);
/// ```
/// What:
/// Run one pass for `request` over `checks`.
/// `<F: RepositoryFacts>` says the function
/// works with any one facts provider `F`;
/// `&mut ShippedChecks<F>` lends the shipped
/// policies and their provider for writing,
/// because checks cache repository facts.
/// Why:
/// The order is the installed wrapper's.
/// Built-in policies read the command before
/// it is rewritten.
/// The fixed transforms run only for a forwarded command.
/// Optional
/// policies run last.
/// A stage that did not complete ends the pass with the
/// arguments it was given,
/// and nothing after it runs.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// async function runPolicyPass(request: StageRequest, checks: ShippedChecks): Promise<PassResult>;
/// ```
/// Stage order,
/// stopping and argument hand-over stay out of the release executable.