Debian Codegraph @

src/program/mod.rs

raw symbols SCIP
1 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/::{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#};
2
3 use bstrrust-analyzer cargo bstr 1.12.1 crate/::{BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#, ByteSlicerust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#, ByteVecrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#};
4
5 use craterust-analyzer cargo gix-credentials 0.38.0 crate/::{helperrust-analyzer cargo gix-credentials 0.38.0 helper/, Programrust-analyzer cargo gix-credentials 0.38.0 Program#};
6
7 /// The kind of helper program to use.
8 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
9 pub enum Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind# {
10 /// The built-in `git credential` helper program, part of any `git` distribution.
11 Builtinrust-analyzer cargo gix-credentials 0.38.0 program/Kind#Builtin#,
12 /// A custom credentials helper, as identified just by the name with optional arguments
13 ExternalNamerust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalName# {
14 /// The name like `foo` along with optional args, like `foo --arg --bar="a b"`, with arguments using `sh` shell quoting rules.
15 /// The program executed will be `git-credential-foo [args]` if `name_and_args` starts with `foo [args]`.
16 /// Note that a shell is only used if it's needed.
17 name_and_argsrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalName#name_and_args.: BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#,
18 },
19 /// A custom credentials helper, as identified just by the absolute path to the program and optional arguments. The program is executed through a shell.
20 ExternalPathrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalPath# {
21 /// The absolute path to the executable, like `/path/to/exe` along with optional args, like `/path/to/exe --arg --bar="a b"`, with arguments using `sh`
22 /// shell quoting rules.
23 path_and_argsrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalPath#path_and_args.: BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#,
24 },
25 /// A script to execute with `sh`.
26 ExternalShellScriptrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalShellScript#(BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#),
27 }
28
29 /// Initialization
30 impl Programrust-analyzer cargo gix-credentials 0.38.0 Program# {
31 /// Create a new program of the given `kind`.
32 pub fn from_kindrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]from_kind().(kind: Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#) -> Selfrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program] {
33 Programrust-analyzer cargo gix-credentials 0.38.0 Program# {
34 kindrust-analyzer cargo gix-credentials 0.38.0 Program#kind.,
35 childrust-analyzer cargo gix-credentials 0.38.0 Program#child.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
36 stderrrust-analyzer cargo gix-credentials 0.38.0 Program#stderr.: true,
37 }
38 }
39
40 /// Parse the given input as per the custom helper definition, supporting `!<script>`, `name` and `/absolute/name`, the latter two
41 /// also support arguments which are ignored here.
42 pub fn from_custom_definitionrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]from_custom_definition().(input: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#>) -> Selfrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program] {
43 fn from_custom_definition_innerrust-analyzer cargo gix-credentials 0.38.0 program/from_custom_definition_inner().(mut input: BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#) -> Programrust-analyzer cargo gix-credentials 0.38.0 Program# {
44 let kind = if input.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(b"!") {
45 input.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(0);
46 Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::ExternalShellScriptrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalShellScript#(input)
47 } else {
48 let path = gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::from_bstrrust-analyzer cargo gix-path 0.12.0 convert/from_bstr().(
49 input
50 .find_byterust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#find_byte().(b' ')
51 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(input.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), |pos| &input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)
52 .as_bstrrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#as_bstr().(),
53 );
54 if gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::is_absoluterust-analyzer cargo gix-path 0.12.0 util/is_absolute().(path) {
55 Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::ExternalPathrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalPath# { path_and_argsrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalPath#path_and_args.: input }
56 } else {
57 Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::ExternalNamerust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalName# { name_and_argsrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalName#name_and_args.: input }
58 }
59 };
60 Programrust-analyzer cargo gix-credentials 0.38.0 Program# {
61 kindrust-analyzer cargo gix-credentials 0.38.0 Program#kind.,
62 childrust-analyzer cargo gix-credentials 0.38.0 Program#child.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
63 stderrrust-analyzer cargo gix-credentials 0.38.0 Program#stderr.: true,
64 }
65 }
66 from_custom_definition_innerrust-analyzer cargo gix-credentials 0.38.0 program/from_custom_definition_inner().(input.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())
67 }
68
69 /// Convert the program into the respective command, suitable to invoke `action`.
70 pub fn to_commandrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]to_command().(&self, action: &helperrust-analyzer cargo gix-credentials 0.38.0 helper/::Actionrust-analyzer cargo gix-credentials 0.38.0 helper/Action#) -> 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/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command# {
71 let git_program = gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::envrust-analyzer cargo gix-path 0.12.0 env/::exe_invocationrust-analyzer cargo gix-path 0.12.0 env/exe_invocation().();
72 let mut cmd = match &self.kindrust-analyzer cargo gix-credentials 0.38.0 Program#kind. {
73 Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::Builtinrust-analyzer cargo gix-credentials 0.38.0 program/Kind#Builtin# => {
74 let mut cmd = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::fromrust-analyzer cargo gix-command 0.9.0 prepare/impl#[Command][`From<Prepare>`]from().(gix_commandrust-analyzer cargo gix-command 0.9.0 crate/::preparerust-analyzer cargo gix-command 0.9.0 prepare().(git_program));
75 cmd.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("credential").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().(action.as_argrust-analyzer cargo gix-credentials 0.38.0 helper/impl#[Action]as_arg().(false));
76 cmd
77 }
78 Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::ExternalNamerust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalName# { name_and_argsrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalName#name_and_args. } => {
79 let mut args = name_and_args.clonerust-analyzer cargo bstr 1.12.1 bstring/impl#[BString][Clone]clone().();
80 args.insert_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#insert_str().(0, "credential-");
81 args.insert_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#insert_str().(0, " ");
82 args.insert_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#insert_str().(0, git_program.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().().as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().());
83 gix_commandrust-analyzer cargo gix-command 0.9.0 crate/::preparerust-analyzer cargo gix-command 0.9.0 prepare().(gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::from_bstrrust-analyzer cargo gix-path 0.12.0 convert/from_bstr().(args.as_bstrrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#as_bstr().()).into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().())
84 .argrust-analyzer cargo gix-command 0.9.0 prepare/impl#[Prepare]arg().(action.as_argrust-analyzer cargo gix-credentials 0.38.0 helper/impl#[Action]as_arg().(true))
85 .command_may_be_shell_script_allow_manual_argument_splittingrust-analyzer cargo gix-command 0.9.0 prepare/impl#[Prepare]command_may_be_shell_script_allow_manual_argument_splitting().()
86 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
87 }
88 Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::ExternalShellScriptrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalShellScript#(for_shell)
89 | Kindrust-analyzer cargo gix-credentials 0.38.0 program/Kind#::ExternalPathrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalPath# {
90 path_and_argsrust-analyzer cargo gix-credentials 0.38.0 program/Kind#ExternalPath#path_and_args.: for_shell,
91 } => gix_commandrust-analyzer cargo gix-command 0.9.0 crate/::preparerust-analyzer cargo gix-command 0.9.0 prepare().(gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::from_bstrrust-analyzer cargo gix-path 0.12.0 convert/from_bstr().(for_shell.as_bstrrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#as_bstr().()).as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().())
92 .command_may_be_shell_scriptrust-analyzer cargo gix-command 0.9.0 prepare/impl#[Prepare]command_may_be_shell_script().()
93 .argrust-analyzer cargo gix-command 0.9.0 prepare/impl#[Prepare]arg().(action.as_argrust-analyzer cargo gix-credentials 0.38.0 helper/impl#[Action]as_arg().(true))
94 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
95 };
96 cmd.stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]stdin().(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().())
97 .stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]stdout().(if action.expects_outputrust-analyzer cargo gix-credentials 0.38.0 helper/impl#[Action]expects_output().() {
98 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().()
99 } else {
100 Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#::nullrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Stdio]null().()
101 })
102 .stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]stderr().(if self.stderrrust-analyzer cargo gix-credentials 0.38.0 Program#stderr. { Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#::inheritrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Stdio]inherit().() } else { Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#::nullrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Stdio]null().() });
103 cmd
104 }
105 }
106
107 /// Builder
108 impl Programrust-analyzer cargo gix-credentials 0.38.0 Program# {
109 /// By default `stderr` of programs is inherited and typically displayed in the terminal.
110 pub fn suppress_stderrrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]suppress_stderr().(mut self) -> Selfrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program] {
111 self.stderrrust-analyzer cargo gix-credentials 0.38.0 Program#stderr. = false;
112 self
113 }
114 }
115
116 impl Programrust-analyzer cargo gix-credentials 0.38.0 Program# {
117 pub(craterust-analyzer cargo gix-credentials 0.38.0 crate/) fn startrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]start().(
118 &mut self,
119 action: &helperrust-analyzer cargo gix-credentials 0.38.0 helper/::Actionrust-analyzer cargo gix-credentials 0.38.0 helper/Action#,
120 ) -> 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#<(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/::ChildStdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ChildStdin#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<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/::ChildStdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ChildStdout#>)> {
121 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.childrust-analyzer cargo gix-credentials 0.38.0 Program#child..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().(), "BUG: must not call `start()` twice");
122 let mut cmd = self.to_commandrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]to_command().(action);
123 gix_tracerust-analyzer cargo gix-trace 0.1.19 crate/::debugrust-analyzer cargo gix-trace 0.1.19 debug!!(cmd = ?cmd, "launching credential helper");
124 let mut child = cmd.spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]spawn().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
125 let stdin = child.stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#stdin..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("stdin to be configured");
126 let stdout = child.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#stdout..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
127
128 self.childrust-analyzer cargo gix-credentials 0.38.0 Program#child. = child.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
129 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((stdin, stdout))
130 }
131
132 pub(craterust-analyzer cargo gix-credentials 0.38.0 crate/) fn finishrust-analyzer cargo gix-credentials 0.38.0 program/impl#[Program]finish().(&mut self) -> 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#<()> {
133 let mut child = self.childrust-analyzer cargo gix-credentials 0.38.0 Program#child..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Call `start()` before calling finish()");
134 let status = child.waitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Child]wait().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
135 if status.successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() {
136 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
137 } else {
138 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(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/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
139 "Credentials helper program failed with status code {:?}",
140 status.coderust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]code().()
141 )))
142 }
143 }
144 }
145
146 ///
147 pub mod mainrust-analyzer cargo gix-credentials 0.38.0 program/main/;
148 pub use mainrust-analyzer cargo gix-credentials 0.38.0 program/main/::functionrust-analyzer cargo gix-credentials 0.38.0 program/main/function/::mainrust-analyzer cargo gix-credentials 0.38.0 program/main/function/main().;