Showing the changes to git-pack/src (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 | if self.items.is_empty() { | 64 | if self.items.is_empty() { |
| 65 | return Ok(()); | 65 | return Ok(()); |
| 66 | } | 66 | } |
| @@ -84,7 +84,7 @@ impl<T> Tree<T> { · 17 unmodified lines | |||
| 84 | /// Add a new root node, one that only has children but is not a child itself, at the given pack `offset` and associate | 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 | /// custom `data` with it. | 85 | /// custom `data` with it. |
| 86 | pub fn add_root(&mut self, offset: u64, data: T) -> Result<(), Error> { | 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 | self.last_index = 0; | 88 | self.last_index = 0; |
| 89 | self.items.push_front(Item { | 89 | self.items.push_front(Item { |
| 90 | offset, | 90 | offset, |
| @@ -98,17 +98,18 @@ impl<T> Tree<T> { · 7 unmodified lines | |||
| 98 | 98 | ||
| 99 | /// Add a child of the item at `base_offset` which itself resides at pack `offset` and associate custom `data` with it. | 99 | /// Add a child of the item at `base_offset` which itself resides at pack `offset` and associate custom `data` with it. |
| 100 | pub fn add_child(&mut self, base_offset: u64, offset: u64, data: T) -> Result<(), Error> { | 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 | let (roots, children) = self.items.as_mut_slices(); | 102 | let (roots, children) = self.items.as_mut_slices(); |
| 103 | assert_eq!( | 103 | assert_eq!( |
| 104 | roots.len(), | 104 | roots.len(), |
| 105 | self.roots, | 105 | self.roots, |
| 106 | "item deque has been resized, maybe we added more nodes than we declared in the constructor?" | 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 | if let Ok(i) = children.binary_search_by_key(&base_offset, |i| i.offset) { | 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 | } else if let Ok(i) = roots.binary_search_by(|i| base_offset.cmp(&i.offset)) { | 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 | } else { | 113 | } else { |
| 113 | return Err(Error::InvariantBasesBeforeDeltasNeedThem { | 114 | return Err(Error::InvariantBasesBeforeDeltasNeedThem { |
| 114 | delta_pack_offset: offset, | 115 | delta_pack_offset: offset, |