Showing the changes to git-pack (1 of 1 file). Show all
Unified · Split
| @@ -60,7 +60,7 @@ impl<T> Tree<T> { · 59 unmodified lines | ||
| 60 | 60 | }) |
| 61 | 61 | } |
| 62 | 62 | |
| 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> { | |
| 64 | 64 | if self.items.is_empty() { |
| 65 | 65 | return Ok(()); |
| 66 | 66 | } |
| @@ -84,7 +84,7 @@ impl<T> Tree<T> { · 17 unmodified lines | ||
| 84 | 84 | /// Add a new root node, one that only has children but is not a child itself, at the given pack `offset` and associate |
| 85 | 85 | /// custom `data` with it. |
| 86 | 86 | 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)?; | |
| 88 | 88 | self.last_index = 0; |
| 89 | 89 | self.items.push_front(Item { |
| 90 | 90 | offset, |
| @@ -98,17 +98,18 @@ impl<T> Tree<T> { · 7 unmodified lines | ||
| 98 | 98 | |
| 99 | 99 | /// Add a child of the item at `base_offset` which itself resides at pack `offset` and associate custom `data` with it. |
| 100 | 100 | 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)?; | |
| 102 | 102 | let (roots, children) = self.items.as_mut_slices(); |
| 103 | 103 | assert_eq!( |
| 104 | 104 | roots.len(), |
| 105 | 105 | self.roots, |
| 106 | 106 | "item deque has been resized, maybe we added more nodes than we declared in the constructor?" |
| 107 | 107 | ); |
| 108 | + let next_child_index = children.len(); | |
| 108 | 109 | 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); | |
| 110 | 111 | } 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); | |
| 112 | 113 | } else { |
| 113 | 114 | return Err(Error::InvariantBasesBeforeDeltasNeedThem { |
| 114 | 115 | delta_pack_offset: offset, |