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
//! What:
//! Run a read-only real-Git query and capture its output as raw bytes.
//! Why:
//! Repository facts (top level,
//! Git directory) come from Git itself,
//! and the
//! paths it prints need not be UTF-8.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! // const { stdout } = await spawn(gitPath, ['rev-parse', '--git-dir'], { stdout: 'pipe' });
//! ```
/// Import the shared child-command builder.
use crategit_command;
use cratetry_metadata;
/// Starts that ride out a short shortage of processes.
use crateRetryStart;
/// What:
/// `OsString` is owned operating-system text of raw OS bytes (sibling `String`
/// must be UTF-8).
/// Why:
/// Query arguments include the caller's unchanged global options.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// // string[] argv, but byte-preserving.
/// ```
use OsString;
/// `Path`/`PathBuf` are borrowed/owned filesystem paths of raw OS bytes.
use ;
/// `Stdio` selects where a child's stream is connected.
use Stdio;
/// What:
/// What one metadata query produced.
/// `Vec<u8>` is an owned byte list (`u8` is one byte);
/// sibling `String` would
/// require UTF-8.
/// Why:
/// Git prints paths as raw bytes,
/// and a failed query is an ordinary answer
/// ("not a repository"),
/// not an error.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type MetadataOutput = { success: boolean; code: number | null; stdout: Buffer; stderr: Buffer };
/// ```
/// What:
/// Run real Git with captured output and no standard input.
/// `std::io::Result<T>` is `Result<T, std::io::Error>`.
/// Why:
/// A query must never consume the caller's stdin (which belongs to the
/// forwarded command) or write to the caller's streams.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// async function runMetadataGit(realGit, args, overlay): Promise<MetadataOutput>;
/// ```
/// What:
/// Remove exactly one final line break (`\n` or `\r\n`) from Git output.
/// `&[u8]` borrows bytes;
/// the result borrows a shorter view of the same bytes.
/// Why:
/// Git terminates each printed value with one line break;
/// anything before it,
/// including other line breaks,
/// is part of the value.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function stripGitLine(output: Buffer): Buffer;
/// ```
/// What:
/// Turn path bytes printed by Git into a path,
/// without decoding on Unix.
/// `Option<PathBuf>` is "an owned path or nothing".
/// `#[cfg(unix)]` and
/// `#[cfg(not(unix))]` each compile one of the two inner blocks.
/// Why:
/// Unix paths are arbitrary bytes and must round-trip exactly;
/// other systems can
/// only build a path from valid UTF-8.
/// An empty value is never a path anywhere.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function pathFromGitBytes(bytes: Buffer): string | undefined;
/// ```
/// Byte-level controls stay out of the release executable.