revset: merge AmbiguousChange/CommitIdPrefix error into one

Follows up c5ed3e1477. Now change/commit ids are resolved at the same
precedence, which means there are at least three types of ambiguity.
I don't think we would need to discriminate these.
This commit is contained in:
Yuya Nishihara 2022-11-28 19:48:24 +09:00
parent c5ed3e1477
commit e40c041384
2 changed files with 13 additions and 23 deletions

View file

@ -45,10 +45,8 @@ use crate::store::Store;
pub enum RevsetError { pub enum RevsetError {
#[error("Revision \"{0}\" doesn't exist")] #[error("Revision \"{0}\" doesn't exist")]
NoSuchRevision(String), NoSuchRevision(String),
#[error("Commit id prefix \"{0}\" is ambiguous")] #[error("Commit or change id prefix \"{0}\" is ambiguous")]
AmbiguousCommitIdPrefix(String), AmbiguousIdPrefix(String),
#[error("Change id prefix \"{0}\" is ambiguous")]
AmbiguousChangeIdPrefix(String),
#[error("Unexpected error from store: {0}")] #[error("Unexpected error from store: {0}")]
StoreError(#[from] BackendError), StoreError(#[from] BackendError),
} }
@ -107,7 +105,7 @@ fn resolve_short_commit_id(
match repo.index().resolve_prefix(&prefix) { match repo.index().resolve_prefix(&prefix) {
PrefixResolution::NoMatch => Ok(None), PrefixResolution::NoMatch => Ok(None),
PrefixResolution::AmbiguousMatch => { PrefixResolution::AmbiguousMatch => {
Err(RevsetError::AmbiguousCommitIdPrefix(symbol.to_owned())) Err(RevsetError::AmbiguousIdPrefix(symbol.to_owned()))
} }
PrefixResolution::SingleMatch(commit_id) => Ok(Some(vec![commit_id])), PrefixResolution::SingleMatch(commit_id) => Ok(Some(vec![commit_id])),
} }
@ -129,9 +127,7 @@ fn resolve_change_id(
if change_id.hex().starts_with(hex_prefix.hex()) { if change_id.hex().starts_with(hex_prefix.hex()) {
if let Some(previous_change_id) = found_change_id.replace(change_id.clone()) { if let Some(previous_change_id) = found_change_id.replace(change_id.clone()) {
if previous_change_id != change_id { if previous_change_id != change_id {
return Err(RevsetError::AmbiguousChangeIdPrefix( return Err(RevsetError::AmbiguousIdPrefix(change_id_prefix.to_owned()));
change_id_prefix.to_owned(),
));
} }
} }
commit_ids.push(index_entry.commit_id()); commit_ids.push(index_entry.commit_id());
@ -197,8 +193,7 @@ pub fn resolve_symbol(
) { ) {
// Likely a root_commit_id, but not limited to it. // Likely a root_commit_id, but not limited to it.
(Some(ids1), Some(ids2)) if ids1 == ids2 => Ok(ids1), (Some(ids1), Some(ids2)) if ids1 == ids2 => Ok(ids1),
// TODO: maybe unify Ambiguous*IdPrefix error variants? (Some(_), Some(_)) => Err(RevsetError::AmbiguousIdPrefix(symbol.to_owned())),
(Some(_), Some(_)) => Err(RevsetError::AmbiguousCommitIdPrefix(symbol.to_owned())),
(Some(ids), None) | (None, Some(ids)) => Ok(ids), (Some(ids), None) | (None, Some(ids)) => Ok(ids),
(None, None) => Err(RevsetError::NoSuchRevision(symbol.to_owned())), (None, None) => Err(RevsetError::NoSuchRevision(symbol.to_owned())),
} }
@ -1718,11 +1713,7 @@ pub fn evaluate_expression<'repo>(
RevsetExpression::Present(candidates) => match candidates.evaluate(repo, workspace_ctx) { RevsetExpression::Present(candidates) => match candidates.evaluate(repo, workspace_ctx) {
Ok(set) => Ok(set), Ok(set) => Ok(set),
Err(RevsetError::NoSuchRevision(_)) => Ok(Box::new(EagerRevset::empty())), Err(RevsetError::NoSuchRevision(_)) => Ok(Box::new(EagerRevset::empty())),
r @ Err( r @ Err(RevsetError::AmbiguousIdPrefix(_) | RevsetError::StoreError(_)) => r,
RevsetError::AmbiguousCommitIdPrefix(_)
| RevsetError::AmbiguousChangeIdPrefix(_)
| RevsetError::StoreError(_),
) => r,
}, },
RevsetExpression::Union(expression1, expression2) => { RevsetExpression::Union(expression1, expression2) => {
let set1 = expression1.evaluate(repo, workspace_ctx)?; let set1 = expression1.evaluate(repo, workspace_ctx)?;

View file

@ -106,7 +106,7 @@ fn test_resolve_symbol_commit_id() {
// Test empty commit id // Test empty commit id
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "", None), resolve_symbol(repo_ref, "", None),
Err(RevsetError::AmbiguousCommitIdPrefix("".to_string())) Err(RevsetError::AmbiguousIdPrefix("".to_string()))
); );
// Test commit id prefix // Test commit id prefix
@ -116,11 +116,11 @@ fn test_resolve_symbol_commit_id() {
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "04", None), resolve_symbol(repo_ref, "04", None),
Err(RevsetError::AmbiguousCommitIdPrefix("04".to_string())) Err(RevsetError::AmbiguousIdPrefix("04".to_string()))
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "", None), resolve_symbol(repo_ref, "", None),
Err(RevsetError::AmbiguousCommitIdPrefix("".to_string())) Err(RevsetError::AmbiguousIdPrefix("".to_string()))
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "040", None), resolve_symbol(repo_ref, "040", None),
@ -139,7 +139,7 @@ fn test_resolve_symbol_commit_id() {
optimize(parse("present(04)", &RevsetAliasesMap::new(), None).unwrap()) optimize(parse("present(04)", &RevsetAliasesMap::new(), None).unwrap())
.evaluate(repo_ref, None) .evaluate(repo_ref, None)
.map(|_| ()), .map(|_| ()),
Err(RevsetError::AmbiguousCommitIdPrefix("04".to_string())) Err(RevsetError::AmbiguousIdPrefix("04".to_string()))
); );
assert_eq!( assert_eq!(
resolve_commit_ids(repo_ref, "present(046)"), resolve_commit_ids(repo_ref, "present(046)"),
@ -247,12 +247,11 @@ fn test_resolve_symbol_change_id() {
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "04e1", None), resolve_symbol(repo_ref, "04e1", None),
Err(RevsetError::AmbiguousChangeIdPrefix("04e1".to_string())) Err(RevsetError::AmbiguousIdPrefix("04e1".to_string()))
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "", None), resolve_symbol(repo_ref, "", None),
// Commit id is checked first, so this is considered an ambiguous commit id Err(RevsetError::AmbiguousIdPrefix("".to_string()))
Err(RevsetError::AmbiguousCommitIdPrefix("".to_string()))
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "04e13", None), resolve_symbol(repo_ref, "04e13", None),
@ -268,7 +267,7 @@ fn test_resolve_symbol_change_id() {
); );
assert_eq!( assert_eq!(
resolve_symbol(repo_ref, "040", None), resolve_symbol(repo_ref, "040", None),
Err(RevsetError::AmbiguousCommitIdPrefix("040".to_string())) Err(RevsetError::AmbiguousIdPrefix("040".to_string()))
); );
// Test non-hex string // Test non-hex string