/
options.rs
395 lines (345 loc) · 15.5 KB
/
options.rs
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
use clap::AppSettings;
use gitoxide_core as core;
#[derive(Debug, clap::Parser)]
#[clap(name = "gix-plumbing", about = "The git underworld", version = clap::crate_version!())]
#[clap(setting = AppSettings::SubcommandRequiredElseHelp)]
pub struct Args {
#[clap(long, short = 't')]
/// The amount of threads to use for some operations.
///
/// If unset, or the value is 0, there is no limit and all logical cores can be used.
pub threads: Option<usize>,
/// Display verbose messages and progress information
#[clap(long, short = 'v')]
pub verbose: bool,
/// Bring up a terminal user interface displaying progress visually
#[cfg(feature = "prodash-render-tui")]
#[clap(long, conflicts_with("verbose"))]
pub progress: bool,
/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[cfg(feature = "prodash-render-tui")]
#[clap(long, conflicts_with("verbose"), requires("progress"))]
pub progress_keep_open: bool,
/// Determine the format to use when outputting statistics.
#[clap(
long,
short = 'f',
default_value = "human",
possible_values(core::OutputFormat::variants())
)]
pub format: core::OutputFormat,
/// The object format to assume when reading files that don't inherently know about it, or when writing files.
#[clap(long, default_value_t = git_repository::hash::Kind::default(), possible_values(&["SHA1"]))]
pub object_hash: git_repository::hash::Kind,
#[clap(subcommand)]
pub cmd: Subcommands,
}
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Subcommands for interacting with packs and their indices.
#[clap(subcommand)]
Pack(pack::Subcommands),
/// Subcommands for interacting with git remotes, e.g. git repositories hosted on servers.
#[clap(subcommand)]
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
Remote(remote::Subcommands),
/// Subcommands for interacting with commit-graphs
#[clap(subcommand)]
CommitGraph(commitgraph::Subcommands),
/// Subcommands for interacting with a worktree index, typically at .git/index
#[clap(subcommand)]
Index(index::Subcommands),
/// Subcommands for interacting with entire git repositories
#[clap(subcommand)]
Repository(repo::Subcommands),
}
///
pub mod pack {
use std::{ffi::OsString, path::PathBuf};
use gitoxide_core as core;
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Subcommands for interacting with pack indices (.idx)
#[clap(subcommand)]
Index(index::Subcommands),
/// Subcommands for interacting with multi-pack indices (named "multi-pack-index")
#[clap(subcommand)]
MultiIndex(multi_index::Subcommands),
/// Create a new pack with a set of objects.
Create {
#[clap(long, short = 'r')]
/// the directory containing the '.git' repository from which objects should be read.
repository: Option<PathBuf>,
#[clap(long, short = 'e', possible_values(core::pack::create::ObjectExpansion::variants()))]
/// the way objects are expanded. They differ in costs.
///
/// Possible values are "none" and "tree-traversal". Default is "none".
expansion: Option<core::pack::create::ObjectExpansion>,
#[clap(long)]
/// if set, the counting phase may be accelerated using multithreading.
///
/// On the flip side, however, one will loose deterministic counting results which affects the
/// way the resulting pack is structured.
nondeterministic_count: bool,
#[clap(long, short = 's')]
/// If set statistical information will be presented to inform about pack creation details.
/// It's a form of instrumentation for developers to help improve pack generation.
statistics: bool,
#[clap(long)]
/// The size in megabytes for a cache to speed up pack access for packs with long delta chains.
/// It is shared among all threads, so 4 threads would use their own cache 1/4th of the size.
///
/// If unset, no cache will be used.
pack_cache_size_mb: Option<usize>,
#[clap(long)]
/// The size in megabytes for a cache to speed up accessing entire objects, bypassing object database access when hit.
/// It is shared among all threads, so 4 threads would use their own cache 1/4th of the size.
///
/// This cache type is currently only effective when using the 'diff-tree' object expansion.
///
/// If unset, no cache will be used.
object_cache_size_mb: Option<usize>,
#[clap(long)]
/// if set, delta-objects whose base object wouldn't be in the pack will not be recompressed as base object, but instead
/// refer to its base object using its object id.
///
/// This allows for smaller packs but requires the receiver of the pack to resolve these ids before storing the pack.
/// Packs produced with this option enabled are only valid in transit, but not at rest.
thin: bool,
/// The directory into which to write the pack file.
#[clap(long, short = 'o')]
output_directory: Option<PathBuf>,
/// The tips from which to start the commit graph iteration, either as fully qualified commit hashes
/// or as branch names.
///
/// If empty, we expect to read objects on stdin and default to 'none' as expansion mode.
/// Otherwise the expansion mode is 'tree-traversal' by default.
tips: Vec<OsString>,
},
/// Use the git-protocol to receive a pack, emulating a clone.
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
Receive {
/// The protocol version to use. Valid values are 1 and 2
#[clap(long, short = 'p')]
protocol: Option<core::net::Protocol>,
/// the directory into which to write references. Existing files will be overwritten.
///
/// Note that the directory will be created if needed.
#[clap(long, short = 'd')]
refs_directory: Option<PathBuf>,
/// The URLs or path from which to receive the pack.
///
/// See here for a list of supported URLs: <https://www.git-scm.com/docs/git-clone#_git_urls>
url: String,
/// If set once or more times, these references will be fetched instead of all advertised ones.
///
/// Note that this requires a reasonably modern git server.
#[clap(long = "reference", short = 'r')]
refs: Vec<String>,
/// The directory into which to write the received pack and index.
///
/// If unset, they will be discarded.
directory: Option<PathBuf>,
},
/// Dissolve a pack into its loose objects.
///
/// Note that this effectively removes delta compression for an average compression of 2x, creating one file per object in the process.
/// Thus this should only be done to dissolve small packs after a fetch.
Explode {
#[clap(long)]
/// Read written objects back and assert they match their source. Fail the operation otherwise.
///
/// Only relevant if an object directory is set.
verify: bool,
/// delete the pack and index file after the operation is successful
#[clap(long)]
delete_pack: bool,
/// The amount of checks to run
#[clap(
long,
short = 'c',
default_value = "all",
possible_values(core::pack::explode::SafetyCheck::variants())
)]
check: core::pack::explode::SafetyCheck,
/// Compress bytes even when using the sink, i.e. no object directory is specified
///
/// This helps to determine overhead related to compression. If unset, the sink will
/// only create hashes from bytes, which is usually limited by the speed at which input
/// can be obtained.
#[clap(long)]
sink_compress: bool,
/// The '.pack' or '.idx' file to explode into loose objects
#[clap(parse(from_os_str))]
pack_path: PathBuf,
/// The path into which all objects should be written. Commonly '.git/objects'
#[clap(parse(from_os_str))]
object_path: Option<PathBuf>,
},
/// Verify the integrity of a pack, index or multi-index file
Verify {
#[clap(flatten)]
args: VerifyOptions,
/// The '.pack', '.idx' or 'multi-pack-index' file to validate.
#[clap(parse(from_os_str))]
path: PathBuf,
},
}
#[derive(Debug, clap::Parser)]
pub struct VerifyOptions {
/// output statistical information
#[clap(long, short = 's')]
pub statistics: bool,
/// The algorithm used to verify packs. They differ in costs.
#[clap(
long,
short = 'a',
default_value = "less-time",
possible_values(core::pack::verify::Algorithm::variants())
)]
pub algorithm: core::pack::verify::Algorithm,
#[clap(long, conflicts_with("re-encode"))]
/// Decode and parse tags, commits and trees to validate their correctness beyond hashing correctly.
///
/// Malformed objects should not usually occur, but could be injected on purpose or accident.
/// This will reduce overall performance.
pub decode: bool,
#[clap(long)]
/// Decode and parse tags, commits and trees to validate their correctness, and re-encode them.
///
/// This flag is primarily to test the implementation of encoding, and requires to decode the object first.
/// Encoding an object after decoding it should yield exactly the same bytes.
/// This will reduce overall performance even more, as re-encoding requires to transform zero-copy objects into
/// owned objects, causing plenty of allocation to occour.
pub re_encode: bool,
}
///
pub mod multi_index {
use std::path::PathBuf;
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Verify a multi-index quickly without inspecting objects themselves
Verify {
/// The path to the multi-pack-index to verify.
multi_index_path: PathBuf,
},
/// Create a multi-pack index from one or more pack index files
Create {
/// The path to which the multi-index file should be written, overwriting any possibly existing file.
///
/// Note for the multi-index to be useful, it should be side-by-side with the supplied `.idx` files.
#[clap(long, short = 'o')]
output_path: PathBuf,
/// Paths to the pack index files to read (with .idx extension).
#[clap(required = true)]
index_paths: Vec<PathBuf>,
},
}
}
///
pub mod index {
use std::path::PathBuf;
use gitoxide_core as core;
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// create a pack index from a pack data file.
Create {
/// Specify how to iterate the pack, defaults to 'verify'
///
/// Valid values are
///
/// **as-is** do not do anything and expect the pack file to be valid as per the trailing hash,
/// **verify** the input ourselves and validate that it matches with the hash provided in the pack,
/// **restore** hash the input ourselves and ignore failing entries, instead finish the pack with the hash we computed
/// to keep as many objects as possible.
#[clap(
long,
short = 'i',
default_value = "verify",
possible_values(core::pack::index::IterationMode::variants())
)]
iteration_mode: core::pack::index::IterationMode,
/// Path to the pack file to read (with .pack extension).
///
/// If unset, the pack file is expected on stdin.
#[clap(long, short = 'p')]
pack_path: Option<PathBuf>,
/// The folder into which to place the pack and the generated index file
///
/// If unset, only informational output will be provided to standard output.
#[clap(parse(from_os_str))]
directory: Option<PathBuf>,
},
}
}
}
///
pub mod repo {
use std::path::PathBuf;
#[derive(Debug, clap::Subcommand)]
#[clap(alias = "repo")]
pub enum Subcommands {
/// Verify the integrity of the entire repository
Verify {
#[clap(flatten)]
args: super::pack::VerifyOptions,
#[clap(short = 'r', long, default_value = ".")]
repository: PathBuf,
},
}
}
///
pub mod index {
use std::path::PathBuf;
#[derive(Debug, clap::Subcommand)]
#[clap(alias = "index")]
pub enum Subcommands {
/// Print all entries to standard output
Entries {
/// The object format to assume when reading files that don't inherently know about it, or when writing files.
#[clap(long, default_value_t = git_repository::hash::Kind::default(), possible_values(&["SHA1"]))]
object_hash: git_repository::hash::Kind,
/// The path to the index file.
index_path: PathBuf,
},
}
}
///
pub mod commitgraph {
use std::path::PathBuf;
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Verify the integrity of a commit graph
Verify {
/// The path to '.git/objects/info/', '.git/objects/info/commit-graphs/', or '.git/objects/info/commit-graph' to validate.
#[clap(parse(from_os_str))]
path: PathBuf,
/// output statistical information about the pack
#[clap(long, short = 's')]
statistics: bool,
},
}
}
///
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
pub mod remote {
use gitoxide_core as core;
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// List remote references from a remote identified by a url.
///
/// This is the plumbing equivalent of `git ls-remote`.
/// Supported URLs are documented here: <https://www.git-scm.com/docs/git-clone#_git_urls>
RefList {
/// The protocol version to use. Valid values are 1 and 2
#[clap(long, short = 'p')]
protocol: Option<core::net::Protocol>,
/// the URLs or path from which to receive references
///
/// See here for a list of supported URLs: <https://www.git-scm.com/docs/git-clone#_git_urls>
url: String,
},
}
}