From a3cb0ee3d1d0aa738b21dfc61ed7a644a8ba6382 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 29 May 2021 23:52:50 -0700 Subject: [PATCH] index: add a type parameter to PrefixResolution to prepare for ChangeId prefix --- lib/src/index.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/index.rs b/lib/src/index.rs index 05167f791..e212c0fc8 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -79,7 +79,7 @@ impl<'a> IndexRef<'a> { } } - pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { + pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { match self { IndexRef::Readonly(index) => index.resolve_prefix(prefix), IndexRef::Mutable(index) => index.resolve_prefix(prefix), @@ -298,14 +298,14 @@ impl HexPrefix { } #[derive(Debug, Clone, PartialEq, Eq)] -pub enum PrefixResolution { +pub enum PrefixResolution { NoMatch, - SingleMatch(CommitId), + SingleMatch(T), AmbiguousMatch, } -impl PrefixResolution { - fn plus(&self, other: &PrefixResolution) -> PrefixResolution { +impl PrefixResolution { + fn plus(&self, other: &PrefixResolution) -> PrefixResolution { match (self, other) { (PrefixResolution::NoMatch, other) => other.clone(), (local, PrefixResolution::NoMatch) => local.clone(), @@ -634,7 +634,7 @@ impl MutableIndex { CompositeIndex(self).commit_id_to_pos(commit_id) } - pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { + pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { CompositeIndex(self).resolve_prefix(prefix) } @@ -688,7 +688,7 @@ trait IndexSegment { fn segment_commit_id_to_pos(&self, commit_id: &CommitId) -> Option; - fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution; + fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution; fn segment_is_pruned(&self, local_pos: u32) -> bool; @@ -790,7 +790,7 @@ impl<'a> CompositeIndex<'a> { }) } - pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { + pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { let local_match = self.0.segment_resolve_prefix(prefix); if local_match == PrefixResolution::AmbiguousMatch { // return early to avoid checking the parent file(s) @@ -1139,7 +1139,7 @@ impl IndexSegment for ReadonlyIndex { } } - fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { + fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes(); match self.commit_id_byte_prefix_to_pos(&min_bytes_prefix) { None => PrefixResolution::NoMatch, @@ -1253,7 +1253,7 @@ impl IndexSegment for MutableIndex { self.lookup.get(commit_id).cloned() } - fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { + fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes(); let mut potential_range = self .lookup @@ -1482,7 +1482,7 @@ impl ReadonlyIndex { CompositeIndex(self).commit_id_to_pos(commit_id) } - pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { + pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { CompositeIndex(self).resolve_prefix(prefix) }