mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 08:53:16 +00:00
id_prefix: add empty disambiguation index for convenience
Callers might want to fall back to an empty index if context.populate() failed.
This commit is contained in:
parent
bf6620d8d9
commit
3d41237efe
2 changed files with 14 additions and 10 deletions
|
@ -145,6 +145,11 @@ pub struct IdPrefixIndex<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdPrefixIndex<'_> {
|
impl IdPrefixIndex<'_> {
|
||||||
|
/// Returns an empty index that just falls back to a provided `repo`.
|
||||||
|
pub const fn empty() -> IdPrefixIndex<'static> {
|
||||||
|
IdPrefixIndex { indexes: None }
|
||||||
|
}
|
||||||
|
|
||||||
/// Resolve an unambiguous commit ID prefix.
|
/// Resolve an unambiguous commit ID prefix.
|
||||||
pub fn resolve_commit_prefix(
|
pub fn resolve_commit_prefix(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -41,6 +41,7 @@ use crate::fileset::FilesetExpression;
|
||||||
use crate::graph::GraphEdge;
|
use crate::graph::GraphEdge;
|
||||||
use crate::hex_util::to_forward_hex;
|
use crate::hex_util::to_forward_hex;
|
||||||
use crate::id_prefix::IdPrefixContext;
|
use crate::id_prefix::IdPrefixContext;
|
||||||
|
use crate::id_prefix::IdPrefixIndex;
|
||||||
use crate::object_id::HexPrefix;
|
use crate::object_id::HexPrefix;
|
||||||
use crate::object_id::PrefixResolution;
|
use crate::object_id::PrefixResolution;
|
||||||
use crate::op_store::RemoteRefState;
|
use crate::op_store::RemoteRefState;
|
||||||
|
@ -1624,11 +1625,10 @@ impl PartialSymbolResolver for CommitPrefixResolver<'_> {
|
||||||
symbol: &str,
|
symbol: &str,
|
||||||
) -> Result<Option<Vec<CommitId>>, RevsetResolutionError> {
|
) -> Result<Option<Vec<CommitId>>, RevsetResolutionError> {
|
||||||
if let Some(prefix) = HexPrefix::new(symbol) {
|
if let Some(prefix) = HexPrefix::new(symbol) {
|
||||||
let resolution = match self.context.map(|ctx| ctx.populate(repo)) {
|
let index = self
|
||||||
Some(index) => index.resolve_commit_prefix(repo, &prefix),
|
.context
|
||||||
None => repo.index().resolve_commit_id_prefix(&prefix),
|
.map_or(IdPrefixIndex::empty(), |ctx| ctx.populate(repo));
|
||||||
};
|
match index.resolve_commit_prefix(repo, &prefix) {
|
||||||
match resolution {
|
|
||||||
PrefixResolution::AmbiguousMatch => Err(
|
PrefixResolution::AmbiguousMatch => Err(
|
||||||
RevsetResolutionError::AmbiguousCommitIdPrefix(symbol.to_owned()),
|
RevsetResolutionError::AmbiguousCommitIdPrefix(symbol.to_owned()),
|
||||||
),
|
),
|
||||||
|
@ -1653,11 +1653,10 @@ impl PartialSymbolResolver for ChangePrefixResolver<'_> {
|
||||||
symbol: &str,
|
symbol: &str,
|
||||||
) -> Result<Option<Vec<CommitId>>, RevsetResolutionError> {
|
) -> Result<Option<Vec<CommitId>>, RevsetResolutionError> {
|
||||||
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 resolution = match self.context.map(|ctx| ctx.populate(repo)) {
|
let index = self
|
||||||
Some(index) => index.resolve_change_prefix(repo, &prefix),
|
.context
|
||||||
None => repo.resolve_change_id_prefix(&prefix),
|
.map_or(IdPrefixIndex::empty(), |ctx| ctx.populate(repo));
|
||||||
};
|
match index.resolve_change_prefix(repo, &prefix) {
|
||||||
match resolution {
|
|
||||||
PrefixResolution::AmbiguousMatch => Err(
|
PrefixResolution::AmbiguousMatch => Err(
|
||||||
RevsetResolutionError::AmbiguousChangeIdPrefix(symbol.to_owned()),
|
RevsetResolutionError::AmbiguousChangeIdPrefix(symbol.to_owned()),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue