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
use std::ffi::{OsStr, OsString};
use crate::bstr::{BString, ByteVec};
pub fn agent() -> &'static str {
concat!("oxide-", env!("CARGO_PKG_VERSION"))
}
#[cfg(not(target_vendor = "apple"))]
pub fn args_os() -> impl Iterator<Item = OsString> {
std::env::args_os()
}
#[cfg(target_vendor = "apple")]
pub fn args_os() -> impl Iterator<Item = OsString> {
use unicode_normalization::UnicodeNormalization;
std::env::args_os().map(|arg| match arg.to_str() {
Some(arg) => arg.nfc().collect::<String>().into(),
None => arg,
})
}
pub fn os_str_to_bstring(input: &OsStr) -> Option<BString> {
Vec::from_os_string(input.into()).map(Into::into).ok()
}
pub mod collate {
pub mod fetch {
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error<E: std::error::Error + Send + Sync + 'static = std::convert::Infallible> {
#[error(transparent)]
Open(#[from] crate::open::Error),
#[error(transparent)]
FindExistingReference(#[from] crate::reference::find::existing::Error),
#[error(transparent)]
RemoteInit(#[from] crate::remote::init::Error),
#[error(transparent)]
FindExistingRemote(#[from] crate::remote::find::existing::Error),
#[error(transparent)]
CredentialHelperConfig(#[from] crate::config::credential_helpers::Error),
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
#[error(transparent)]
Connect(#[from] crate::remote::connect::Error),
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
#[error(transparent)]
PrepareFetch(#[from] crate::remote::fetch::prepare::Error),
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
#[error(transparent)]
Fetch(#[from] crate::remote::fetch::Error),
#[error(transparent)]
Other(E),
}
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
impl<E> crate::protocol::transport::IsSpuriousError for Error<E>
where
E: std::error::Error + Send + Sync + 'static,
{
fn is_spurious(&self) -> bool {
match self {
Error::Open(_)
| Error::CredentialHelperConfig(_)
| Error::RemoteInit(_)
| Error::FindExistingReference(_)
| Error::FindExistingRemote(_)
| Error::Other(_) => false,
Error::Connect(err) => err.is_spurious(),
Error::PrepareFetch(err) => err.is_spurious(),
Error::Fetch(err) => err.is_spurious(),
}
}
}
impl<E> Error<E>
where
E: std::error::Error + Send + Sync + 'static,
{
pub fn is_corrupted(&self) -> bool {
match self {
Error::Open(crate::open::Error::NotARepository { .. } | crate::open::Error::Config(_)) => true,
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
Error::PrepareFetch(crate::remote::fetch::prepare::Error::RefMap(
crate::remote::ref_map::Error::GatherTransportConfig { .. }
| crate::remote::ref_map::Error::ConfigureCredentials(_),
)) => true,
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
Error::Fetch(
crate::remote::fetch::Error::PackThreads(_)
| crate::remote::fetch::Error::PackIndexVersion(_)
| crate::remote::fetch::Error::RemovePackKeepFile { .. },
) => true,
_ => false,
}
}
}
}
}