mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-11 06:42:47 +00:00
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> {
|
pub struct DefaultSymbolResolver<'a> {
|
||||||
repo: &'a dyn Repo,
|
repo: &'a dyn Repo,
|
||||||
workspace_id: Option<&'a WorkspaceId>,
|
workspace_id: Option<&'a WorkspaceId>,
|
||||||
commit_id_resolver: Option<PrefixResolver<'a, CommitId>>,
|
commit_id_resolver: PrefixResolver<'a, CommitId>,
|
||||||
change_id_resolver: Option<PrefixResolver<'a, Vec<CommitId>>>,
|
change_id_resolver: PrefixResolver<'a, Vec<CommitId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DefaultSymbolResolver<'a> {
|
impl<'a> DefaultSymbolResolver<'a> {
|
||||||
|
@ -1663,8 +1663,8 @@ impl<'a> DefaultSymbolResolver<'a> {
|
||||||
DefaultSymbolResolver {
|
DefaultSymbolResolver {
|
||||||
repo,
|
repo,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
commit_id_resolver: None,
|
commit_id_resolver: Box::new(|repo, prefix| repo.index().resolve_prefix(prefix)),
|
||||||
change_id_resolver: None,
|
change_id_resolver: Box::new(|repo, prefix| repo.resolve_change_id_prefix(prefix)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1672,7 +1672,7 @@ impl<'a> DefaultSymbolResolver<'a> {
|
||||||
mut self,
|
mut self,
|
||||||
commit_id_resolver: PrefixResolver<'a, CommitId>,
|
commit_id_resolver: PrefixResolver<'a, CommitId>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.commit_id_resolver = Some(commit_id_resolver);
|
self.commit_id_resolver = commit_id_resolver;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1680,7 +1680,7 @@ impl<'a> DefaultSymbolResolver<'a> {
|
||||||
mut self,
|
mut self,
|
||||||
change_id_resolver: PrefixResolver<'a, Vec<CommitId>>,
|
change_id_resolver: PrefixResolver<'a, Vec<CommitId>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.change_id_resolver = Some(change_id_resolver);
|
self.change_id_resolver = change_id_resolver;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1727,12 +1727,7 @@ impl SymbolResolver for DefaultSymbolResolver<'_> {
|
||||||
|
|
||||||
// Try to resolve as a commit id.
|
// Try to resolve as a commit id.
|
||||||
if let Some(prefix) = HexPrefix::new(symbol) {
|
if let Some(prefix) = HexPrefix::new(symbol) {
|
||||||
let prefix_resolution = if let Some(commit_id_resolver) = &self.commit_id_resolver {
|
match (self.commit_id_resolver)(self.repo, &prefix) {
|
||||||
commit_id_resolver(self.repo, &prefix)
|
|
||||||
} else {
|
|
||||||
self.repo.index().resolve_prefix(&prefix)
|
|
||||||
};
|
|
||||||
match prefix_resolution {
|
|
||||||
PrefixResolution::AmbiguousMatch => {
|
PrefixResolution::AmbiguousMatch => {
|
||||||
return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned()));
|
return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned()));
|
||||||
}
|
}
|
||||||
|
@ -1747,12 +1742,7 @@ impl SymbolResolver for DefaultSymbolResolver<'_> {
|
||||||
|
|
||||||
// Try to resolve as a change id.
|
// Try to resolve as a change id.
|
||||||
if let Some(prefix) = to_forward_hex(symbol).as_deref().and_then(HexPrefix::new) {
|
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 {
|
match (self.change_id_resolver)(self.repo, &prefix) {
|
||||||
change_id_resolver(self.repo, &prefix)
|
|
||||||
} else {
|
|
||||||
self.repo.resolve_change_id_prefix(&prefix)
|
|
||||||
};
|
|
||||||
match prefix_resolution {
|
|
||||||
PrefixResolution::AmbiguousMatch => {
|
PrefixResolution::AmbiguousMatch => {
|
||||||
return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned()));
|
return Err(RevsetResolutionError::AmbiguousIdPrefix(symbol.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue