Skip to content

Commit 62b4e19

Browse files
committed
rename AliasId to CommitAlias, add UnwalkedAlias
1 parent 5bfb232 commit 62b4e19

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

asyncgit/src/graph/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,28 @@ pub struct LaneIndex(u8);
1919
/// The alias is a dense integer index created by [`GraphOids`](super::oids::GraphOids)
2020
/// that avoids storing full [`CommitId`](crate::sync::CommitId)s inside the lane state.
2121
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
22-
pub struct AliasId(usize);
22+
pub struct CommitAlias(usize);
2323

24-
impl std::ops::Deref for AliasId {
24+
/// An alias for a commit that had not yet been walked when the value
25+
/// was minted.
26+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
27+
pub struct UnwalkedAlias(CommitAlias);
28+
29+
impl UnwalkedAlias {
30+
/// The underlying alias, for comparisons against walked commits.
31+
pub const fn get(self) -> CommitAlias {
32+
self.0
33+
}
34+
}
35+
36+
impl std::ops::Deref for CommitAlias {
2537
type Target = usize;
2638
fn deref(&self) -> &usize {
2739
&self.0
2840
}
2941
}
3042

31-
impl From<usize> for AliasId {
43+
impl From<usize> for CommitAlias {
3244
fn from(v: usize) -> Self {
3345
Self(v)
3446
}

asyncgit/src/graph/oids.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
use super::AliasId;
1+
use super::CommitAlias;
22
use crate::sync::CommitId;
33
use std::collections::HashMap;
44

55
/// mapping of `CommitId` to a numeric alias
6-
pub struct GraphOids(HashMap<CommitId, AliasId>);
7-
8-
impl Default for GraphOids {
9-
fn default() -> Self {
10-
Self::new()
11-
}
12-
}
6+
#[derive(Default)]
7+
pub struct GraphOids(HashMap<CommitId, CommitAlias>);
138

149
impl GraphOids {
1510
/// Create an empty alias map.
1611
pub fn new() -> Self {
17-
Self(HashMap::new())
12+
Self::default()
1813
}
1914

2015
/// Get the alias for `id`, assigning a new one if it doesn't exist yet.
21-
pub fn get_or_insert(&mut self, id: &CommitId) -> AliasId {
16+
pub fn get_or_insert(&mut self, id: &CommitId) -> CommitAlias {
2217
if let Some(&alias) = self.0.get(id) {
2318
return alias;
2419
}
2520

26-
let alias = AliasId::from(self.0.len());
21+
let alias = CommitAlias::from(self.0.len());
2722
self.0.insert(*id, alias);
2823
alias
2924
}
3025

3126
/// Look up the alias for `id`, returning `None` if not found.
32-
pub fn get(&self, id: &CommitId) -> Option<AliasId> {
27+
pub fn get(&self, id: &CommitId) -> Option<CommitAlias> {
3328
self.0.get(id).copied()
3429
}
3530
}

0 commit comments

Comments
 (0)