Enum git_repository::remote::Name
source · Expand description
The name of a remote, either interpreted as symbol like origin
or as url as returned by Remote::name()
.
Variants§
Symbol(Cow<'repo, str>)
A symbolic name, like origin
.
Note that it has not necessarily been validated yet.
Url(Cow<'repo, BStr>)
A url pointing to the remote host directly.
Implementations§
source§impl Name<'_>
impl Name<'_>
sourcepub fn as_bstr(&self) -> &BStr
pub fn as_bstr(&self) -> &BStr
Obtain the name as string representation.
Examples found in repository?
More examples
src/remote/save.rs (line 46)
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
pub fn save_to(&self, config: &mut git_config::File<'static>) -> Result<(), Error> {
fn as_key(name: &str) -> git_config::parse::section::Key<'_> {
name.try_into().expect("valid")
}
let name = self.name().ok_or_else(|| Error::NameMissing {
url: self
.url
.as_ref()
.or(self.push_url.as_ref())
.expect("one url is always set")
.to_owned(),
})?;
if let Some(section_ids) = config.sections_and_ids_by_name("remote").map(|it| {
it.filter_map(|(s, id)| (s.header().subsection_name() == Some(name.as_bstr())).then(|| id))
.collect::<Vec<_>>()
}) {
let mut sections_to_remove = Vec::new();
const KEYS_TO_REMOVE: &[&str] = &["url", "pushurl", "fetch", "push", "tagOpt"];
for id in section_ids {
let mut section = config.section_mut_by_id(id).expect("just queried");
let was_empty = section.num_values() == 0;
for key in KEYS_TO_REMOVE {
while section.remove(key).is_some() {}
}
let is_empty_after_deletions_of_values_to_be_written = section.num_values() == 0;
if !was_empty && is_empty_after_deletions_of_values_to_be_written {
sections_to_remove.push(id);
}
}
for id in sections_to_remove {
config.remove_section_by_id(id);
}
}
let mut section = config
.section_mut_or_create_new("remote", Some(name.as_ref()))
.expect("section name is validated and 'remote' is acceptable");
if let Some(url) = self.url.as_ref() {
section.push(as_key("url"), Some(url.to_bstring().as_ref()))
}
if let Some(url) = self.push_url.as_ref() {
section.push(as_key("pushurl"), Some(url.to_bstring().as_ref()))
}
if self.fetch_tags != Default::default() {
section.push(
as_key("tagOpt"),
BStr::new(match self.fetch_tags {
remote::fetch::Tags::All => "--tags",
remote::fetch::Tags::None => "--no-tags",
remote::fetch::Tags::Included => unreachable!("BUG: the default shouldn't be written and we try"),
})
.into(),
)
}
for (key, spec) in self
.fetch_specs
.iter()
.map(|spec| ("fetch", spec))
.chain(self.push_specs.iter().map(|spec| ("push", spec)))
{
section.push(as_key(key), Some(spec.to_ref().to_bstring().as_ref()))
}
Ok(())
}
src/remote/connection/ref_map.rs (line 203)
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
async fn fetch_refs(
&mut self,
filter_by_prefix: bool,
extra_parameters: Vec<(String, Option<String>)>,
refspecs: &[git_refspec::RefSpec],
) -> Result<HandshakeWithRefs, Error> {
let mut credentials_storage;
let url = self.transport.to_url();
let authenticate = match self.authenticate.as_mut() {
Some(f) => f,
None => {
let url = self
.remote
.url(Direction::Fetch)
.map(ToOwned::to_owned)
.unwrap_or_else(|| git_url::parse(url.as_ref()).expect("valid URL to be provided by transport"));
credentials_storage = self.configured_credentials(url)?;
&mut credentials_storage
}
};
if self.transport_options.is_none() {
self.transport_options = self
.remote
.repo
.transport_options(url.as_ref(), self.remote.name().map(|n| n.as_bstr()))
.map_err(|err| Error::GatherTransportConfig {
source: err,
url: url.into_owned(),
})?;
}
if let Some(config) = self.transport_options.as_ref() {
self.transport.configure(&**config)?;
}
let mut outcome =
git_protocol::fetch::handshake(&mut self.transport, authenticate, extra_parameters, &mut self.progress)
.await?;
let refs = match outcome.refs.take() {
Some(refs) => refs,
None => {
let agent_feature = self.remote.repo.config.user_agent_tuple();
git_protocol::ls_refs(
&mut self.transport,
&outcome.capabilities,
move |_capabilities, arguments, features| {
features.push(agent_feature);
if filter_by_prefix {
let mut seen = HashSet::new();
for spec in refspecs {
let spec = spec.to_ref();
if seen.insert(spec.instruction()) {
let mut prefixes = Vec::with_capacity(1);
spec.expand_prefixes(&mut prefixes);
for mut prefix in prefixes {
prefix.insert_str(0, "ref-prefix ");
arguments.push(prefix);
}
}
}
}
Ok(git_protocol::ls_refs::Action::Continue)
},
&mut self.progress,
)
.await?
}
};
Ok(HandshakeWithRefs { outcome, refs })
}
Trait Implementations§
source§impl<'repo> PartialEq<Name<'repo>> for Name<'repo>
impl<'repo> PartialEq<Name<'repo>> for Name<'repo>
impl<'repo> Eq for Name<'repo>
impl<'repo> StructuralEq for Name<'repo>
impl<'repo> StructuralPartialEq for Name<'repo>
Auto Trait Implementations§
impl<'repo> RefUnwindSafe for Name<'repo>
impl<'repo> Send for Name<'repo>
impl<'repo> Sync for Name<'repo>
impl<'repo> Unpin for Name<'repo>
impl<'repo> UnwindSafe for Name<'repo>
Blanket Implementations§
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more