Enum git_revision::spec::parse::delegate::SiblingBranch
source · pub enum SiblingBranch {
Upstream,
Push,
}
Expand description
The kind of sibling branch to obtain.
Variants§
Upstream
The upstream branch as configured in branch.<name>.remote
or branch.<name>.merge
.
Push
The upstream branch to which we would push.
Implementations§
source§impl SiblingBranch
impl SiblingBranch
sourcepub fn parse(input: &BStr) -> Option<Self>
pub fn parse(input: &BStr) -> Option<Self>
Parse input
as branch representation, if possible.
Examples found in repository?
src/spec/parse/function.rs (line 428)
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
fn revision<'a, T>(mut input: &'a BStr, delegate: &mut InterceptRev<'_, T>) -> Result<&'a BStr, Error>
where
T: Delegate,
{
use delegate::{Navigate, Revision};
fn consume_all(res: Option<()>) -> Result<&'static BStr, Error> {
res.ok_or(Error::Delegate).map(|_| "".into())
}
match input.as_ref() {
[b':'] => return Err(Error::MissingColonSuffix),
[b':', b'/'] => return Err(Error::EmptyTopLevelRegex),
[b':', b'/', regex @ ..] => {
let (regex, negated) = parse_regex_prefix(regex.as_bstr())?;
if regex.is_empty() {
return Err(Error::UnconsumedInput { input: input.into() });
}
return consume_all(delegate.find(regex, negated));
}
[b':', b'0', b':', path @ ..] => return consume_all(delegate.index_lookup(path.as_bstr(), 0)),
[b':', b'1', b':', path @ ..] => return consume_all(delegate.index_lookup(path.as_bstr(), 1)),
[b':', b'2', b':', path @ ..] => return consume_all(delegate.index_lookup(path.as_bstr(), 2)),
[b':', path @ ..] => return consume_all(delegate.index_lookup(path.as_bstr(), 0)),
_ => {}
};
let mut sep_pos = None;
let mut consecutive_hex_chars = Some(0);
{
let mut cursor = input;
let mut ofs = 0;
while let Some((pos, b)) = cursor.iter().enumerate().find(|(_, b)| {
if b"@~^:.".contains(b) {
true
} else {
if let Some(num) = consecutive_hex_chars.as_mut() {
if b.is_ascii_hexdigit() {
*num += 1;
} else {
consecutive_hex_chars = None;
}
}
false
}
}) {
if *b != b'.' || cursor.get(pos + 1) == Some(&b'.') {
sep_pos = Some(ofs + pos);
break;
}
ofs += pos + 1;
cursor = &cursor[pos + 1..];
}
}
let name = &input[..sep_pos.unwrap_or(input.len())].as_bstr();
let mut sep = sep_pos.map(|pos| input[pos]);
let mut has_ref_or_implied_name = name.is_empty();
if name.is_empty() && sep == Some(b'@') && sep_pos.and_then(|pos| input.get(pos + 1)) != Some(&b'{') {
delegate.find_ref("HEAD".into()).ok_or(Error::Delegate)?;
sep_pos = sep_pos.map(|pos| pos + 1);
sep = match sep_pos.and_then(|pos| input.get(pos).copied()) {
None => return Ok("".into()),
Some(pos) => Some(pos),
};
} else {
(consecutive_hex_chars.unwrap_or(0) >= git_hash::Prefix::MIN_HEX_LEN)
.then(|| try_set_prefix(delegate, name, None))
.flatten()
.or_else(|| {
let (prefix, hint) = long_describe_prefix(name)
.map(|(c, h)| (c, Some(h)))
.or_else(|| short_describe_prefix(name).map(|c| (c, None)))?;
try_set_prefix(delegate, prefix, hint)
})
.or_else(|| {
name.is_empty().then(|| ()).or_else(|| {
#[allow(clippy::let_unit_value)]
{
let res = delegate.find_ref(name)?;
has_ref_or_implied_name = true;
res.into()
}
})
})
.ok_or(Error::Delegate)?;
}
input = {
if let Some(b'@') = sep {
let past_sep = input[sep_pos.map(|pos| pos + 1).unwrap_or(input.len())..].as_bstr();
let (nav, rest, _consumed) = parens(past_sep)?.ok_or_else(|| Error::AtNeedsCurlyBrackets {
input: input[sep_pos.unwrap_or(input.len())..].into(),
})?;
let nav = nav.as_ref();
if let Some(n) = try_parse::<isize>(nav)? {
if n < 0 {
if name.is_empty() {
delegate
.nth_checked_out_branch(n.abs().try_into().expect("non-negative isize fits usize"))
.ok_or(Error::Delegate)?;
} else {
return Err(Error::RefnameNeedsPositiveReflogEntries { nav: nav.into() });
}
} else if has_ref_or_implied_name {
delegate
.reflog(delegate::ReflogLookup::Entry(
n.try_into().expect("non-negative isize fits usize"),
))
.ok_or(Error::Delegate)?;
} else {
return Err(Error::ReflogLookupNeedsRefName { name: (*name).into() });
}
} else if let Some(kind) = SiblingBranch::parse(nav) {
if has_ref_or_implied_name {
delegate.sibling_branch(kind).ok_or(Error::Delegate)
} else {
Err(Error::SiblingBranchNeedsBranchName { name: (*name).into() })
}?
} else if has_ref_or_implied_name {
let time = nav
.to_str()
.map_err(|_| Error::Time {
input: nav.into(),
source: None,
})
.and_then(|date| {
git_date::parse(date, Some(SystemTime::now())).map_err(|err| Error::Time {
input: nav.into(),
source: err.into(),
})
})?;
delegate
.reflog(delegate::ReflogLookup::Date(time))
.ok_or(Error::Delegate)?;
} else {
return Err(Error::ReflogLookupNeedsRefName { name: (*name).into() });
}
rest
} else {
if sep_pos == Some(0) && sep == Some(b'~') {
return Err(Error::MissingTildeAnchor);
}
input[sep_pos.unwrap_or(input.len())..].as_bstr()
}
};
navigate(input, delegate)
}
Trait Implementations§
source§impl Clone for SiblingBranch
impl Clone for SiblingBranch
source§fn clone(&self) -> SiblingBranch
fn clone(&self) -> SiblingBranch
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SiblingBranch
impl Debug for SiblingBranch
source§impl Hash for SiblingBranch
impl Hash for SiblingBranch
source§impl Ord for SiblingBranch
impl Ord for SiblingBranch
source§fn cmp(&self, other: &SiblingBranch) -> Ordering
fn cmp(&self, other: &SiblingBranch) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<SiblingBranch> for SiblingBranch
impl PartialEq<SiblingBranch> for SiblingBranch
source§fn eq(&self, other: &SiblingBranch) -> bool
fn eq(&self, other: &SiblingBranch) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<SiblingBranch> for SiblingBranch
impl PartialOrd<SiblingBranch> for SiblingBranch
source§fn partial_cmp(&self, other: &SiblingBranch) -> Option<Ordering>
fn partial_cmp(&self, other: &SiblingBranch) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for SiblingBranch
impl Eq for SiblingBranch
impl StructuralEq for SiblingBranch
impl StructuralPartialEq for SiblingBranch
Auto Trait Implementations§
impl RefUnwindSafe for SiblingBranch
impl Send for SiblingBranch
impl Sync for SiblingBranch
impl Unpin for SiblingBranch
impl UnwindSafe for SiblingBranch
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