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
//! The modes, what each one prints, and the exit status it earns.
//!
//! [`Mode`] names what the caller asked for, [`ExitStatus`] is the documented
//! process status, and the rendering helpers here turn the difference an
//! [`Assessment`](super::source::Assessment) measured into the line `--check`
//! prints, the unified diff `--diff` prints, or the path `--list-files`
//! prints.
//!
//! Nothing here reads or writes a file: a mode is a value, and rendering is a
//! pure function of the assessment the boundary in the parent module made.
use Context;
use Utf8Path;
use ;
use debug;
use Assessment;
/// What the caller asked for.
/// The diff configuration the reporting rendering uses.
///
/// Three lines of context is the unified-diff convention. The degradation
/// threshold is a line count rather than a wall-clock budget: a timeout would
/// make the output depend on how fast the machine happened to be, which is
/// exactly what `INV-DETERMINISTIC` forbids.
const DIFF_OPTIONS: DiffOptions = DiffOptions ;
/// The documented process exit status.
/// Maps mode and observations onto an exit status.
///
/// An error yields [`ExitStatus::Error`] in every mode, because an incomplete
/// analysis must not be reported as merely drifted — and because a run that
/// could not read every file cannot claim the tree is clean. Drift yields
/// [`ExitStatus::Drift`] under the read-only reporting modes; in particular a
/// successful `--in-place` over drifting files yields [`ExitStatus::Success`],
/// as does a bare invocation, whose contract is to print the formatted text.
/// Renders one selected path as the single line `--list-files` prints for it.
///
/// A path is one line only while it holds no line terminator, and Git's index
/// may hold one that does: the NUL framing that lists the candidates is what
/// lets such a name through the selection in the first place. The terminator,
/// and the backslash that escapes it, are therefore written as `\n`, `\r`, and
/// `\\`, so that one printed line is one selected path and a reader can
/// recover the name from it. Every other character is printed as itself, so a
/// path that holds none of the three is unchanged.
pub
/// Renders the unified diff for one changed file.
///
/// The renderer streams into a byte sink rather than a `String`, because that
/// is what lets it go straight to standard output when the caller wants it to.
/// Here the payload has to be a `String`, so the bytes are collected and then
/// validated: both sides of the diff came from `String`s, so the validation
/// cannot fail in practice, but the driver does not get to assume it.
pub
/// Reports the line-ending decision at the command boundary that made it.
///
/// The library keeps the same report for its own entry points, but the binary
/// is a separate crate and cannot share it, so the message is repeated here with
/// the same fields: one filter finds every boundary. `operation` names the
/// boundary — `"file"` when formatting a file, `"stdin"` when reading standard
/// input — and `path` names the file being formatted, or is `None` for standard
/// input, which is reported as its own source rather than left nameless.
///
/// It takes the counts the pure `count_line_endings` query already produced, so
/// no query emits events and only the boundary that acts on the answer logs it:
/// [`analyse`](super::analyse) for a file, and `format_stdin` for standard
/// input. It is `pub` because the crate root is not a descendant of this module
/// and cannot see a private item, not because the library exposes it.