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
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use anyhow::{Result, anyhow};
use clap::{CommandFactory, Parser};
use gitoxide_core as core;
use crate::{
porcelain::options::{Args, Subcommands},
shared::pretty::prepare_and_run,
};
pub fn main() -> Result<()> {
let args: Args = Args::parse_from(gix::env::args_os());
let should_interrupt = Arc::new(AtomicBool::new(false));
#[expect(unsafe_code)]
unsafe {
// SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
gix::interrupt::init_handler(1, {
let should_interrupt = Arc::clone(&should_interrupt);
move || should_interrupt.store(true, Ordering::SeqCst)
})?;
}
let trace = false;
let verbose = !args.quiet;
let progress = args.progress;
#[cfg(feature = "gitoxide-core-tools")]
let threads = args.threads;
let progress_keep_open = args.progress_keep_open;
match args.cmd {
#[cfg(debug_assertions)]
Subcommands::Panic => prepare_and_run(
"panic-behaviour",
trace,
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
move |_progress, _out, _err| panic!("something went very wrong"),
),
Subcommands::Init { directory } => core::repository::init(directory).map(|_| ()),
#[cfg(feature = "gitoxide-core-tools")]
Subcommands::Tool(tool) => match tool {
#[cfg(feature = "gitoxide-core-tools-query")]
crate::porcelain::options::ToolCommands::Query(crate::porcelain::options::tools::Query {
object_cache_size_mb,
find_copies_harder,
repo_dir,
cmd,
}) => {
use gitoxide_core::query;
prepare_and_run(
"query",
trace,
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
move |mut progress, out, err| {
let engine = query::prepare(
&repo_dir,
&mut progress,
&mut *err,
query::Options {
object_cache_size_mb,
find_copies_harder,
threads,
},
)?;
match cmd {
None => writeln!(err, "Choose a command for the query engine")?,
Some(crate::porcelain::options::tools::query::Command::TracePath { path }) => {
engine.run(
query::Command::TracePath {
spec: crate::shared::parse_pathspec_argument(path),
},
out,
progress,
)?;
}
}
Ok(())
},
)
}
crate::porcelain::options::ToolCommands::EstimateHours(
crate::porcelain::options::tools::EstimateHours {
working_dir,
rev_spec,
no_bots,
file_stats,
line_stats,
show_pii,
omit_unify_identities,
},
) => {
use gitoxide_core::hours;
prepare_and_run(
"estimate-hours",
trace,
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
move |progress, out, _err| {
hours::estimate(
&working_dir,
rev_spec.as_ref(),
progress,
hours::Context {
show_pii,
ignore_bots: no_bots,
threads,
file_stats,
line_stats,
omit_unify_identities,
out,
},
)
},
)
}
crate::porcelain::options::ToolCommands::Find { root, debug } => {
use gitoxide_core::organize;
prepare_and_run(
"find",
trace,
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
move |progress, out, _err| {
organize::discover(
root.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
out,
progress,
debug,
threads,
)
},
)
}
crate::porcelain::options::ToolCommands::Organize {
destination_directory,
execute,
repository_source,
} => {
use gitoxide_core::organize;
prepare_and_run(
"organize",
trace,
verbose,
progress,
progress_keep_open,
crate::shared::STANDARD_RANGE,
move |progress, _out, _err| {
organize::run(
if execute {
organize::Mode::Execute
} else {
organize::Mode::Simulate
},
repository_source.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
destination_directory.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
progress,
threads,
)
},
)
}
},
Subcommands::Completions { shell, out_dir } => {
let mut app = Args::command();
let shell = shell
.or_else(clap_complete::Shell::from_env)
.ok_or_else(|| anyhow!("The shell could not be derived from the environment"))?;
let bin_name = app.get_name().to_owned();
if let Some(out_dir) = out_dir {
clap_complete::generate_to(shell, &mut app, bin_name, &out_dir)?;
} else {
clap_complete::generate(shell, &mut app, bin_name, &mut std::io::stdout());
}
Ok(())
}
}?;
Ok(())
}