Debian Codegraph @

src/main.rs

raw symbols SCIP
1 mod alignrust-analyzer cargo git-delta 0.19.2 align/;
2 mod ansirust-analyzer cargo git-delta 0.19.2 ansi/;
3 mod clirust-analyzer cargo git-delta 0.19.2 cli/;
4 mod colorrust-analyzer cargo git-delta 0.19.2 color/;
5 mod colorsrust-analyzer cargo git-delta 0.19.2 colors/;
6 mod configrust-analyzer cargo git-delta 0.19.2 config/;
7 mod deltarust-analyzer cargo git-delta 0.19.2 delta/;
8 mod editsrust-analyzer cargo git-delta 0.19.2 edits/;
9 mod envrust-analyzer cargo git-delta 0.19.2 env/;
10 mod featuresrust-analyzer cargo git-delta 0.19.2 features/;
11 mod formatrust-analyzer cargo git-delta 0.19.2 format/;
12 mod git_configrust-analyzer cargo git-delta 0.19.2 git_config/;
13 mod handlersrust-analyzer cargo git-delta 0.19.2 handlers/;
14 mod minusplusrust-analyzer cargo git-delta 0.19.2 minusplus/;
15 mod optionsrust-analyzer cargo git-delta 0.19.2 options/;
16 mod paintrust-analyzer cargo git-delta 0.19.2 paint/;
17 mod parse_stylerust-analyzer cargo git-delta 0.19.2 parse_style/;
18 mod parse_stylesrust-analyzer cargo git-delta 0.19.2 parse_styles/;
19 mod stylerust-analyzer cargo git-delta 0.19.2 style/;
20 mod utilsrust-analyzer cargo git-delta 0.19.2 utils/;
21 mod wrappingrust-analyzer cargo git-delta 0.19.2 wrapping/;
22
23 mod subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/;
24
25 mod testsrust-analyzer cargo git-delta 0.19.2 tests/;
26
27 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#};
28 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#, ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#, IsTerminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/IsTerminal#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
29 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/, Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#, Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#};
30
31 use bytelinesrust-analyzer cargo bytelines 2.5.0 crate/::ByteLinesReaderrust-analyzer cargo bytelines 2.5.0 std/ByteLinesReader#;
32
33 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/::Callrust-analyzer cargo git-delta 0.19.2 cli/Call#;
34 use craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/::delta_unreachablerust-analyzer cargo git-delta 0.19.2 config/delta_unreachable().;
35 use craterust-analyzer cargo git-delta 0.19.2 crate/::deltarust-analyzer cargo git-delta 0.19.2 delta/::deltarust-analyzer cargo git-delta 0.19.2 delta/delta().;
36 use craterust-analyzer cargo git-delta 0.19.2 crate/::subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::{SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#, SubCommandrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#};
37 use craterust-analyzer cargo git-delta 0.19.2 crate/::utilsrust-analyzer cargo git-delta 0.19.2 utils/::batrust-analyzer cargo git-delta 0.19.2 utils/bat/::assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/::list_languagesrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/list_languages().;
38 use craterust-analyzer cargo git-delta 0.19.2 crate/::utilsrust-analyzer cargo git-delta 0.19.2 utils/::batrust-analyzer cargo git-delta 0.19.2 utils/bat/::outputrust-analyzer cargo git-delta 0.19.2 utils/bat/output/::{OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#, PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#};
39
40 pub fn fatalrust-analyzer cargo git-delta 0.19.2 fatal().<T>(errmsg: T) -> !
41 where
42 T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
43 {
44 #[cfg(not(test))]
45 {
46 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{errmsg}");
47 // As in Config::error_exit_code: use 2 for error
48 // because diff uses 0 and 1 for non-error.
49 processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(2);
50 }
51 #[cfg(test)]
52 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("{}\n", errmsg);
53 }
54
55 pub mod errorsrust-analyzer cargo git-delta 0.19.2 errors/ {
56 pub use anyhowrust-analyzer cargo anyhow 1.0.102 crate/::{anyhowrust-analyzer cargo anyhow 1.0.102 macros/anyhow!, Contextrust-analyzer cargo anyhow 1.0.102 Context#, Errorrust-analyzer cargo anyhow 1.0.102 Error#, Resultrust-analyzer cargo anyhow 1.0.102 Result#};
57 }
58
59 #[cfg(not(tarpaulin_include))]
60 fn mainrust-analyzer cargo git-delta 0.19.2 main().() -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
61 // Do this first because both parsing all the input in `run_app()` and
62 // listing all processes takes about 50ms on Linux.
63 // It also improves the chance that the calling process is still around when
64 // input is piped into delta (e.g. `git show --word-diff=color | delta`).
65 utilsrust-analyzer cargo git-delta 0.19.2 utils/::processrust-analyzer cargo git-delta 0.19.2 utils/process/::start_determining_calling_process_in_threadrust-analyzer cargo git-delta 0.19.2 utils/process/start_determining_calling_process_in_thread().();
66
67 // Ignore ctrl-c (SIGINT) to avoid leaving an orphaned pager process.
68 // See https://github.com/dandavison/delta/issues/681
69 ctrlcrust-analyzer cargo ctrlc 3.4.2 crate/::set_handlerrust-analyzer cargo ctrlc 3.4.2 set_handler().(|| {})
70 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|err| eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Failed to set ctrl-c handler: {err}"));
71 let exit_code = run_apprust-analyzer cargo git-delta 0.19.2 run_app().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::args_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args_os().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
72 // when you call process::exit, no drop impls are called, so we want to do it only once, here
73 processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(exit_code);
74 }
75
76 #[cfg(not(tarpaulin_include))]
77 // An Ok result contains the desired process exit code. Note that 1 is used to
78 // report that two files differ when delta is called with two positional
79 // arguments and without standard input; 2 is used to report a real problem.
80 pub fn run_apprust-analyzer cargo git-delta 0.19.2 run_app().(
81 args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>,
82 capture_output: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>>,
83 ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<i32> {
84 let env = envrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().();
85 let assets = utilsrust-analyzer cargo git-delta 0.19.2 utils/::batrust-analyzer cargo git-delta 0.19.2 utils/bat/::assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/::load_highlighting_assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/load_highlighting_assets().();
86 let (call, opt) = clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 cli/impl#[Opt]from_args_and_git_config().(args, &env, assets);
87
88 if let Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::Versionrust-analyzer cargo git-delta 0.19.2 cli/Call#Version#(msg) = call {
89 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().(), "{}", msg.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
90 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
91 } else if let Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::Helprust-analyzer cargo git-delta 0.19.2 cli/Call#Help#(msg) = call {
92 OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::oneshot_writerust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]oneshot_write().(msg)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
93 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
94 } else if let Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::SubCommandrust-analyzer cargo git-delta 0.19.2 cli/Call#SubCommand#(_, cmd) = &call {
95 // Set before creating the Config, which already asks for the calling process
96 // (not required for Call::DeltaDiff)
97 utilsrust-analyzer cargo git-delta 0.19.2 utils/::processrust-analyzer cargo git-delta 0.19.2 utils/process/::set_calling_processrust-analyzer cargo git-delta 0.19.2 utils/process/set_calling_process().(
98 &cmd.argsrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#args.
99 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
100 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|arg| OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().(arg).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
101 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
102 );
103 }
104 let opt = opt.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| delta_unreachablerust-analyzer cargo git-delta 0.19.2 config/delta_unreachable().("Opt is set"));
105
106 let subcommand_result = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(shell) = opt.generate_completionrust-analyzer cargo git-delta 0.19.2 cli/Opt#generate_completion. {
107 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::generate_completionrust-analyzer cargo git-delta 0.19.2 subcommands/generate_completion/::generate_completion_filerust-analyzer cargo git-delta 0.19.2 subcommands/generate_completion/generate_completion_file().(
108 shell,
109 ))
110 } else if opt.list_languagesrust-analyzer cargo git-delta 0.19.2 cli/Opt#list_languages. {
111 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(list_languagesrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/list_languages().())
112 } else if opt.list_syntax_themesrust-analyzer cargo git-delta 0.19.2 cli/Opt#list_syntax_themes. {
113 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::list_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/::list_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/list_syntax_themes().())
114 } else if opt.show_syntax_themesrust-analyzer cargo git-delta 0.19.2 cli/Opt#show_syntax_themes. {
115 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/::show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/show_syntax_themes().())
116 } else if opt.show_themesrust-analyzer cargo git-delta 0.19.2 cli/Opt#show_themes. {
117 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::show_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_themes/::show_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_themes/show_themes().(
118 opt.darkrust-analyzer cargo git-delta 0.19.2 cli/Opt#dark.,
119 opt.lightrust-analyzer cargo git-delta 0.19.2 cli/Opt#light.,
120 opt.computedrust-analyzer cargo git-delta 0.19.2 cli/Opt#computed..color_moderust-analyzer cargo git-delta 0.19.2 cli/ComputedValues#color_mode.,
121 ))
122 } else if opt.show_colorsrust-analyzer cargo git-delta 0.19.2 cli/Opt#show_colors. {
123 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::show_colorsrust-analyzer cargo git-delta 0.19.2 subcommands/show_colors/::show_colorsrust-analyzer cargo git-delta 0.19.2 subcommands/show_colors/show_colors().())
124 } else if opt.parse_ansirust-analyzer cargo git-delta 0.19.2 cli/Opt#parse_ansi. {
125 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::parse_ansirust-analyzer cargo git-delta 0.19.2 subcommands/parse_ansi/::parse_ansirust-analyzer cargo git-delta 0.19.2 subcommands/parse_ansi/parse_ansi().())
126 } else {
127 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
128 };
129 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) = subcommand_result {
130 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = result {
131 match error.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() {
132 ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::BrokenPiperust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#BrokenPipe# => {}
133 _ => fatalrust-analyzer cargo git-delta 0.19.2 fatal().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{error}")),
134 }
135 }
136 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
137 };
138
139 let _show_config = opt.show_configrust-analyzer cargo git-delta 0.19.2 cli/Opt#show_config.;
140 let config = configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#::fromrust-analyzer cargo git-delta 0.19.2 config/impl#[Config][`From<cli::Opt>`]from().(opt);
141
142 if _show_config {
143 let stdout = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().();
144 let mut stdout = stdout.lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout]lock().();
145 subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::show_configrust-analyzer cargo git-delta 0.19.2 subcommands/show_config/::show_configrust-analyzer cargo git-delta 0.19.2 subcommands/show_config/show_config().(&config, &mut stdout)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
146 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
147 }
148
149 // The following block structure is because of `writer` and related lifetimes:
150 let pager_cfg = (&config).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
151 let paging_mode = if capture_output.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
152 PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#::Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Capture#
153 } else {
154 config.paging_moderust-analyzer cargo git-delta 0.19.2 config/Config#paging_mode.
155 };
156 let mut output_type =
157 OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::from_moderust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]from_mode().(&env, paging_mode, config.pagerrust-analyzer cargo git-delta 0.19.2 config/Config#pager..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().(), &pager_cfg).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
158 let mut writer: &mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# = if paging_mode rust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagingMode][`PartialEq<Self>`]eq().==rust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagingMode][`PartialEq<Self>`]eq(). rust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagingMode][`PartialEq<Self>`]eq().PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#::Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Capture# {
159 &mut capture_output.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
160 } else {
161 output_type.handlerust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]handle().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
162 };
163
164 let subcmd = match call {
165 Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::DeltaDiffrust-analyzer cargo git-delta 0.19.2 cli/Call#DeltaDiff#(_, minus, plus) => {
166 match subcommandsrust-analyzer cargo git-delta 0.19.2 subcommands/::diffrust-analyzer cargo git-delta 0.19.2 subcommands/diff/::build_diff_cmdrust-analyzer cargo git-delta 0.19.2 subcommands/diff/build_diff_cmd().(&minus, &plus, &config) {
167 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(code) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(code),
168 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(val) => val,
169 }
170 }
171 Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::SubCommandrust-analyzer cargo git-delta 0.19.2 cli/Call#SubCommand#(_, subcmd) => subcmd,
172 Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::Deltarust-analyzer cargo git-delta 0.19.2 cli/Call#Delta#(_) => SubCommandrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#::nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand]none().(),
173 Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::Helprust-analyzer cargo git-delta 0.19.2 cli/Call#Help#(_) | Callrust-analyzer cargo git-delta 0.19.2 cli/Call#::Versionrust-analyzer cargo git-delta 0.19.2 cli/Call#Version#(_) => delta_unreachablerust-analyzer cargo git-delta 0.19.2 config/delta_unreachable().("help/version handled earlier"),
174 };
175
176 if subcmd.is_nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand]is_none().() {
177 // Default delta run: read input from stdin, write to stdout or pager (pager started already^).
178
179 if iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin][IsTerminal]is_terminal().() {
180 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(
181 "\
182 The main way to use delta is to configure it as the pager for git: \
183 see https://github.com/dandavison/delta#get-started. \
184 You can also use delta to diff two files: `delta file_A file_B`."
185 );
186 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(config.error_exit_coderust-analyzer cargo git-delta 0.19.2 config/Config#error_exit_code.);
187 }
188
189 let res = deltarust-analyzer cargo git-delta 0.19.2 delta/delta().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]lock().().byte_linesrust-analyzer cargo bytelines 2.5.0 std/impl#[B][`ByteLinesReader<Self>`]byte_lines().(), &mut writer, &config);
190
191 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = res {
192 match error.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() {
193 ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::BrokenPiperust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#BrokenPipe# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0),
194 _ => {
195 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{error}");
196 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(config.error_exit_coderust-analyzer cargo git-delta 0.19.2 config/Config#error_exit_code.);
197 }
198 }
199 }
200
201 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0)
202 } else {
203 // First start a subcommand, and pipe input from it to delta(). Also handle
204 // subcommand exit code and stderr (maybe truncate it, e.g. for git and diff logic).
205
206 let (subcmd_bin, subcmd_args) = subcmd.argsrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#args..split_firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_first().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
207 let subcmd_kind = subcmd.kindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#kind.; // for easier {} formatting
208
209 let subcmd_bin_path = match grep_clirust-analyzer cargo grep-cli 0.1.12 crate/::resolve_binaryrust-analyzer cargo grep-cli 0.1.12 decompress/resolve_binary().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(subcmd_bin)) {
210 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(path) => path,
211 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
212 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Failed to resolve command {subcmd_bin:?}: {err}");
213 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(config.error_exit_coderust-analyzer cargo git-delta 0.19.2 config/Config#error_exit_code.);
214 }
215 };
216
217 let cmd = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(subcmd_bin)
218 .argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(subcmd_args.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().())
219 .stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]stdout().(Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#::pipedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Stdio]piped().())
220 .stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]stderr().(Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#::pipedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Stdio]piped().())
221 .spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]spawn().();
222
223 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) = cmd {
224 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Failed to execute the command {subcmd_bin:?}: {err}");
225 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(config.error_exit_coderust-analyzer cargo git-delta 0.19.2 config/Config#error_exit_code.);
226 }
227 let mut cmd = cmd.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
228
229 let cmd_stdout = cmd
230 .stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#stdout.
231 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().()
232 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to open stdout"));
233 let cmd_stdout_buf = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(cmd_stdout);
234
235 let res = deltarust-analyzer cargo git-delta 0.19.2 delta/delta().(cmd_stdout_buf.byte_linesrust-analyzer cargo bytelines 2.5.0 std/impl#[B][`ByteLinesReader<Self>`]byte_lines().(), &mut writer, &config);
236
237 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = res {
238 let _ = cmd.waitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Child]wait().(); // for clippy::zombie_processes
239 match error.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() {
240 ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::BrokenPiperust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#BrokenPipe# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0),
241 _ => {
242 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{error}");
243 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(config.error_exit_coderust-analyzer cargo git-delta 0.19.2 config/Config#error_exit_code.);
244 }
245 }
246 };
247
248 let subcmd_status = cmd
249 .waitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Child]wait().()
250 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| {
251 delta_unreachablerust-analyzer cargo git-delta 0.19.2 config/delta_unreachable().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{subcmd_kind:?} process not running."));
252 })
253 .coderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]code().()
254 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
255 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("delta: {subcmd_kind:?} process terminated without exit status.");
256 config.error_exit_coderust-analyzer cargo git-delta 0.19.2 config/Config#error_exit_code.
257 });
258
259 let mut stderr_lines = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(
260 cmd.stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#stderr.
261 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to open stderr")),
262 )
263 .linesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#lines().();
264 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(line1) = stderr_lines.nextrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`Lines<B>`][Iterator]next().() {
265 // prefix the first error line with the called subcommand
266 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(
267 "{}: {}",
268 subcmd_kind,
269 line1.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().("<delta: could not parse stderr line>".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
270 );
271 }
272
273 // On `git diff` unknown option error: stop after printing the first line above (which is
274 // an error message), because the entire --help text follows.
275 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(subcmd_status rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().129
276 && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(subcmd_kind, SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::GitDiffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#GitDiff# | SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(_)))
277 {
278 for line in stderr_lines {
279 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(
280 "{}",
281 line.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().("<delta: could not parse stderr line>".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
282 );
283 }
284 }
285
286 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(subcmd_kind, SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::GitDiffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#GitDiff# | SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Diffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Diff#) && subcmd_status rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().2 {
287 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(
288 "{subcmd_kind:?} process failed with exit status {subcmd_status}. Command was: {}",
289 format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!(
290 "{} {}",
291 subcmd_bin_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
292 shell_wordsrust-analyzer cargo shell-words 1.1.0 crate/::joinrust-analyzer cargo shell-words 1.1.0 join().(
293 subcmd_args
294 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
295 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|arg0: &OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#| stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().(arg0))
296 ),
297 )
298 );
299 }
300
301 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(subcmd_status)
302 }
303
304 // `output_type` drop impl runs here
305 }