mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
index: use IndexEntry::position() instead of direct field access
This commit is contained in:
parent
9fb0f00f2d
commit
b89ae7c0b5
4 changed files with 23 additions and 14 deletions
|
@ -151,7 +151,7 @@ impl<'a> CompositeIndex<'a> {
|
|||
if descendant_pos == ancestor_pos {
|
||||
return true;
|
||||
}
|
||||
if !visited.insert(descendant_entry.pos) {
|
||||
if !visited.insert(descendant_entry.position()) {
|
||||
continue;
|
||||
}
|
||||
if descendant_entry.generation_number() <= ancestor_generation {
|
||||
|
@ -183,7 +183,7 @@ impl<'a> CompositeIndex<'a> {
|
|||
let item1 = dedup_pop(&mut items1).unwrap();
|
||||
let entry1 = self.entry_by_pos(item1.pos);
|
||||
for parent_entry in entry1.parents() {
|
||||
assert!(parent_entry.pos < entry1.pos);
|
||||
assert!(parent_entry.position() < entry1.position());
|
||||
items1.push(IndexPositionByGeneration::from(&parent_entry));
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ impl<'a> CompositeIndex<'a> {
|
|||
let item2 = dedup_pop(&mut items2).unwrap();
|
||||
let entry2 = self.entry_by_pos(item2.pos);
|
||||
for parent_entry in entry2.parents() {
|
||||
assert!(parent_entry.pos < entry2.pos);
|
||||
assert!(parent_entry.position() < entry2.position());
|
||||
items2.push(IndexPositionByGeneration::from(&parent_entry));
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ impl<'a> CompositeIndex<'a> {
|
|||
candidate_positions.remove(&item.pos);
|
||||
let entry = self.entry_by_pos(item.pos);
|
||||
for parent_entry in entry.parents() {
|
||||
assert!(parent_entry.pos < entry.pos);
|
||||
assert!(parent_entry.position() < entry.position());
|
||||
work.push(IndexPositionByGeneration::from(&parent_entry));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(super) type SmallIndexPositionsVec = SmallVec<[IndexPosition; 4]>;
|
|||
#[derive(Clone)]
|
||||
pub struct IndexEntry<'a> {
|
||||
source: &'a dyn IndexSegment,
|
||||
pub(super) pos: IndexPosition,
|
||||
pos: IndexPosition,
|
||||
// Position within the source segment
|
||||
local_pos: u32,
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ mod tests {
|
|||
assert_eq!(index.commit_id_to_pos(&CommitId::from_hex("ffffff")), None);
|
||||
// Check properties of root entry
|
||||
let entry = index.entry_by_id(&id_0).unwrap();
|
||||
assert_eq!(entry.pos, IndexPosition(0));
|
||||
assert_eq!(entry.position(), IndexPosition(0));
|
||||
assert_eq!(entry.commit_id(), id_0);
|
||||
assert_eq!(entry.change_id(), change_id0);
|
||||
assert_eq!(entry.generation_number(), 0);
|
||||
|
@ -240,9 +240,9 @@ mod tests {
|
|||
let entry_4 = index.entry_by_id(&id_4).unwrap();
|
||||
let entry_5 = index.entry_by_id(&id_5).unwrap();
|
||||
// Check properties of some entries
|
||||
assert_eq!(entry_0.pos, IndexPosition(0));
|
||||
assert_eq!(entry_0.position(), IndexPosition(0));
|
||||
assert_eq!(entry_0.commit_id(), id_0);
|
||||
assert_eq!(entry_1.pos, IndexPosition(1));
|
||||
assert_eq!(entry_1.position(), IndexPosition(1));
|
||||
assert_eq!(entry_1.commit_id(), id_1);
|
||||
assert_eq!(entry_1.change_id(), change_id1);
|
||||
assert_eq!(entry_1.generation_number(), 1);
|
||||
|
@ -252,8 +252,11 @@ mod tests {
|
|||
smallvec_inline![IndexPosition(0)]
|
||||
);
|
||||
assert_eq!(entry_1.parents().len(), 1);
|
||||
assert_eq!(entry_1.parents().next().unwrap().pos, IndexPosition(0));
|
||||
assert_eq!(entry_2.pos, IndexPosition(2));
|
||||
assert_eq!(
|
||||
entry_1.parents().next().unwrap().position(),
|
||||
IndexPosition(0)
|
||||
);
|
||||
assert_eq!(entry_2.position(), IndexPosition(2));
|
||||
assert_eq!(entry_2.commit_id(), id_2);
|
||||
assert_eq!(entry_2.change_id(), change_id2);
|
||||
assert_eq!(entry_2.generation_number(), 1);
|
||||
|
@ -268,7 +271,7 @@ mod tests {
|
|||
entry_3.parent_positions(),
|
||||
smallvec_inline![IndexPosition(2)]
|
||||
);
|
||||
assert_eq!(entry_4.pos, IndexPosition(4));
|
||||
assert_eq!(entry_4.position(), IndexPosition(4));
|
||||
assert_eq!(entry_4.generation_number(), 2);
|
||||
assert_eq!(entry_4.num_parents(), 1);
|
||||
assert_eq!(
|
||||
|
@ -282,8 +285,14 @@ mod tests {
|
|||
smallvec_inline![IndexPosition(4), IndexPosition(2)]
|
||||
);
|
||||
assert_eq!(entry_5.parents().len(), 2);
|
||||
assert_eq!(entry_5.parents().next().unwrap().pos, IndexPosition(4));
|
||||
assert_eq!(entry_5.parents().nth(1).unwrap().pos, IndexPosition(2));
|
||||
assert_eq!(
|
||||
entry_5.parents().next().unwrap().position(),
|
||||
IndexPosition(4)
|
||||
);
|
||||
assert_eq!(
|
||||
entry_5.parents().nth(1).unwrap().position(),
|
||||
IndexPosition(2)
|
||||
);
|
||||
}
|
||||
|
||||
#[test_case(false; "in memory")]
|
||||
|
|
|
@ -121,7 +121,7 @@ impl MutableIndexSegment {
|
|||
entry.generation_number,
|
||||
parent_entry.generation_number() + 1,
|
||||
);
|
||||
entry.parent_positions.push(parent_entry.pos);
|
||||
entry.parent_positions.push(parent_entry.position());
|
||||
}
|
||||
self.lookup.insert(
|
||||
entry.commit_id.clone(),
|
||||
|
|
Loading…
Reference in a new issue