From f66efcf6f9afe49725296c88a949a9072b3cb013 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 5 May 2023 16:45:52 -0700 Subject: [PATCH] revset: inline resolution of change/commit ids This prepares for adding callbacks to resolve these ids. --- lib/src/revset.rs | 62 ++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 964774450..397f72044 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -1631,40 +1631,6 @@ fn resolve_full_commit_id( } } -fn resolve_short_commit_id( - repo: &dyn Repo, - symbol: &str, -) -> Result>, RevsetResolutionError> { - if let Some(prefix) = HexPrefix::new(symbol) { - match repo.index().resolve_prefix(&prefix) { - PrefixResolution::NoMatch => Ok(None), - PrefixResolution::AmbiguousMatch => { - Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned())) - } - PrefixResolution::SingleMatch(commit_id) => Ok(Some(vec![commit_id])), - } - } else { - Ok(None) - } -} - -fn resolve_change_id( - repo: &dyn Repo, - symbol: &str, -) -> Result>, RevsetResolutionError> { - if let Some(prefix) = to_forward_hex(symbol).as_deref().and_then(HexPrefix::new) { - match repo.resolve_change_id_prefix(&prefix) { - PrefixResolution::NoMatch => Ok(None), - PrefixResolution::AmbiguousMatch => { - Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned())) - } - PrefixResolution::SingleMatch(entries) => Ok(Some(entries)), - } - } else { - Ok(None) - } -} - pub trait SymbolResolver { fn resolve_symbol(&self, symbol: &str) -> Result, RevsetResolutionError>; } @@ -1738,13 +1704,33 @@ impl SymbolResolver for DefaultSymbolResolver<'_> { } // Try to resolve as a commit id. - if let Some(ids) = resolve_short_commit_id(self.repo, symbol)? { - return Ok(ids); + if let Some(prefix) = HexPrefix::new(symbol) { + match self.repo.index().resolve_prefix(&prefix) { + PrefixResolution::AmbiguousMatch => { + return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned())); + } + PrefixResolution::SingleMatch(id) => { + return Ok(vec![id]); + } + PrefixResolution::NoMatch => { + // Fall through + } + } } // Try to resolve as a change id. - if let Some(ids) = resolve_change_id(self.repo, symbol)? { - return Ok(ids); + if let Some(prefix) = to_forward_hex(symbol).as_deref().and_then(HexPrefix::new) { + match self.repo.resolve_change_id_prefix(&prefix) { + PrefixResolution::AmbiguousMatch => { + return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned())); + } + PrefixResolution::SingleMatch(ids) => { + return Ok(ids); + } + PrefixResolution::NoMatch => { + // Fall through + } + } } Err(RevsetResolutionError::NoSuchRevision(symbol.to_owned()))