History

minor refactor (#254)

Sebastian Thiel committed 4 years ago

Commit 227c8b11 parent 20b39941 file · +6 −5Browse files

Showing the changes to git-pack/src (1 of 1 file). Show all

Unified · Split

git-pack/src/cache/delta/mod.rs+6−5
@@ -60,7 +60,7 @@ impl<T> Tree<T> { · 59 unmodified lines
6060 })
6161 }
6262
63− fn assert_is_incrementing(&mut self, offset: u64) -> Result<(), Error> {
63+ fn assert_is_incrementing_and_update_next_offset(&mut self, offset: u64) -> Result<(), Error> {
6464 if self.items.is_empty() {
6565 return Ok(());
6666 }
@@ -84,7 +84,7 @@ impl<T> Tree<T> { · 17 unmodified lines
8484 /// Add a new root node, one that only has children but is not a child itself, at the given pack `offset` and associate
8585 /// custom `data` with it.
8686 pub fn add_root(&mut self, offset: u64, data: T) -> Result<(), Error> {
87− self.assert_is_incrementing(offset)?;
87+ self.assert_is_incrementing_and_update_next_offset(offset)?;
8888 self.last_index = 0;
8989 self.items.push_front(Item {
9090 offset,
@@ -98,17 +98,18 @@ impl<T> Tree<T> { · 7 unmodified lines
9898
9999 /// Add a child of the item at `base_offset` which itself resides at pack `offset` and associate custom `data` with it.
100100 pub fn add_child(&mut self, base_offset: u64, offset: u64, data: T) -> Result<(), Error> {
101− self.assert_is_incrementing(offset)?;
101+ self.assert_is_incrementing_and_update_next_offset(offset)?;
102102 let (roots, children) = self.items.as_mut_slices();
103103 assert_eq!(
104104 roots.len(),
105105 self.roots,
106106 "item deque has been resized, maybe we added more nodes than we declared in the constructor?"
107107 );
108+ let next_child_index = children.len();
108109 if let Ok(i) = children.binary_search_by_key(&base_offset, |i| i.offset) {
109− children[i].children.push(children.len());
110+ children[i].children.push(next_child_index);
110111 } else if let Ok(i) = roots.binary_search_by(|i| base_offset.cmp(&i.offset)) {
111− roots[i].children.push(children.len());
112+ roots[i].children.push(next_child_index);
112113 } else {
113114 return Err(Error::InvariantBasesBeforeDeltasNeedThem {
114115 delta_pack_offset: offset,