forked from mirrors/jj
revset: initialize with default prefix resolver
Since repo is passed as argument, we can define the default resolver as a plain function.
This commit is contained in:
parent
f58beca760
commit
8d56b199bc
1 changed files with 8 additions and 18 deletions
|
@ -1654,8 +1654,8 @@ pub type PrefixResolver<'a, T> = Box<dyn Fn(&dyn Repo, &HexPrefix) -> PrefixReso
|
|||
pub struct DefaultSymbolResolver<'a> {
|
||||
repo: &'a dyn Repo,
|
||||
workspace_id: Option<&'a WorkspaceId>,
|
||||
commit_id_resolver: Option<PrefixResolver<'a, CommitId>>,
|
||||
change_id_resolver: Option<PrefixResolver<'a, Vec<CommitId>>>,
|
||||
commit_id_resolver: PrefixResolver<'a, CommitId>,
|
||||
change_id_resolver: PrefixResolver<'a, Vec<CommitId>>,
|
||||
}
|
||||
|
||||
impl<'a> DefaultSymbolResolver<'a> {
|
||||
|
@ -1663,8 +1663,8 @@ impl<'a> DefaultSymbolResolver<'a> {
|
|||
DefaultSymbolResolver {
|
||||
repo,
|
||||
workspace_id,
|
||||
commit_id_resolver: None,
|
||||
change_id_resolver: None,
|
||||
commit_id_resolver: Box::new(|repo, prefix| repo.index().resolve_prefix(prefix)),
|
||||
change_id_resolver: Box::new(|repo, prefix| repo.resolve_change_id_prefix(prefix)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1672,7 +1672,7 @@ impl<'a> DefaultSymbolResolver<'a> {
|
|||
mut self,
|
||||
commit_id_resolver: PrefixResolver<'a, CommitId>,
|
||||
) -> Self {
|
||||
self.commit_id_resolver = Some(commit_id_resolver);
|
||||
self.commit_id_resolver = commit_id_resolver;
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -1680,7 +1680,7 @@ impl<'a> DefaultSymbolResolver<'a> {
|
|||
mut self,
|
||||
change_id_resolver: PrefixResolver<'a, Vec<CommitId>>,
|
||||
) -> Self {
|
||||
self.change_id_resolver = Some(change_id_resolver);
|
||||
self.change_id_resolver = change_id_resolver;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -1727,12 +1727,7 @@ impl SymbolResolver for DefaultSymbolResolver<'_> {
|
|||
|
||||
// Try to resolve as a commit id.
|
||||
if let Some(prefix) = HexPrefix::new(symbol) {
|
||||
let prefix_resolution = if let Some(commit_id_resolver) = &self.commit_id_resolver {
|
||||
commit_id_resolver(self.repo, &prefix)
|
||||
} else {
|
||||
self.repo.index().resolve_prefix(&prefix)
|
||||
};
|
||||
match prefix_resolution {
|
||||
match (self.commit_id_resolver)(self.repo, &prefix) {
|
||||
PrefixResolution::AmbiguousMatch => {
|
||||
return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned()));
|
||||
}
|
||||
|
@ -1747,12 +1742,7 @@ impl SymbolResolver for DefaultSymbolResolver<'_> {
|
|||
|
||||
// Try to resolve as a change id.
|
||||
if let Some(prefix) = to_forward_hex(symbol).as_deref().and_then(HexPrefix::new) {
|
||||
let prefix_resolution = if let Some(change_id_resolver) = &self.change_id_resolver {
|
||||
change_id_resolver(self.repo, &prefix)
|
||||
} else {
|
||||
self.repo.resolve_change_id_prefix(&prefix)
|
||||
};
|
||||
match prefix_resolution {
|
||||
match (self.change_id_resolver)(self.repo, &prefix) {
|
||||
PrefixResolution::AmbiguousMatch => {
|
||||
return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue