241 .compressed_len() as usize |
241 .compressed_len() as usize |
242 } |
242 } |
243 |
243 |
244 /// The end of the data chunk for this revision |
244 /// The end of the data chunk for this revision |
245 #[inline(always)] |
245 #[inline(always)] |
246 pub fn end(&self, rev: Revision) -> usize { |
246 pub fn data_end(&self, rev: Revision) -> usize { |
247 self.data_start(rev) + self.data_compressed_length(rev) |
247 self.data_start(rev) + self.data_compressed_length(rev) |
248 } |
248 } |
249 |
249 |
250 /// Return the delta parent of the given revision |
250 /// Return the delta parent of the given revision |
251 pub fn delta_parent(&self, rev: Revision) -> Revision { |
251 pub fn delta_parent(&self, rev: Revision) -> Revision { |
659 &self, |
659 &self, |
660 revs: &'a [Revision], |
660 revs: &'a [Revision], |
661 target_size: Option<u64>, |
661 target_size: Option<u64>, |
662 ) -> Result<Vec<&'a [Revision]>, RevlogError> { |
662 ) -> Result<Vec<&'a [Revision]>, RevlogError> { |
663 let mut start_data = self.data_start(revs[0]); |
663 let mut start_data = self.data_start(revs[0]); |
664 let end_data = self.end(revs[revs.len() - 1]); |
664 let end_data = self.data_end(revs[revs.len() - 1]); |
665 let full_span = end_data - start_data; |
665 let full_span = end_data - start_data; |
666 |
666 |
667 let nothing_to_do = target_size |
667 let nothing_to_do = target_size |
668 .map(|size| full_span <= size as usize) |
668 .map(|size| full_span <= size as usize) |
669 .unwrap_or(true); |
669 .unwrap_or(true); |
676 let mut start_rev_idx = 0; |
676 let mut start_rev_idx = 0; |
677 let mut end_rev_idx = 1; |
677 let mut end_rev_idx = 1; |
678 let mut chunks = vec![]; |
678 let mut chunks = vec![]; |
679 |
679 |
680 for (idx, rev) in revs.iter().enumerate().skip(1) { |
680 for (idx, rev) in revs.iter().enumerate().skip(1) { |
681 let span = self.end(*rev) - start_data; |
681 let span = self.data_end(*rev) - start_data; |
682 let is_snapshot = self.is_snapshot(*rev)?; |
682 let is_snapshot = self.is_snapshot(*rev)?; |
683 if span <= target_size && is_snapshot { |
683 if span <= target_size && is_snapshot { |
684 end_rev_idx = idx + 1; |
684 end_rev_idx = idx + 1; |
685 } else { |
685 } else { |
686 let chunk = |
686 let chunk = |
707 end_rev_idx = number_of_items; |
707 end_rev_idx = number_of_items; |
708 if number_of_items - start_rev_idx <= 1 { |
708 if number_of_items - start_rev_idx <= 1 { |
709 // Protect against individual chunks larger than the limit |
709 // Protect against individual chunks larger than the limit |
710 break; |
710 break; |
711 } |
711 } |
712 let mut local_end_data = self.end(revs[end_rev_idx - 1]); |
712 let mut local_end_data = self.data_end(revs[end_rev_idx - 1]); |
713 let mut span = local_end_data - start_data; |
713 let mut span = local_end_data - start_data; |
714 while span > target_size { |
714 while span > target_size { |
715 if end_rev_idx - start_rev_idx <= 1 { |
715 if end_rev_idx - start_rev_idx <= 1 { |
716 // Protect against individual chunks larger than the limit |
716 // Protect against individual chunks larger than the limit |
717 break; |
717 break; |
718 } |
718 } |
719 end_rev_idx -= (end_rev_idx - start_rev_idx) / 2; |
719 end_rev_idx -= (end_rev_idx - start_rev_idx) / 2; |
720 local_end_data = self.end(revs[end_rev_idx - 1]); |
720 local_end_data = self.data_end(revs[end_rev_idx - 1]); |
721 span = local_end_data - start_data; |
721 span = local_end_data - start_data; |
722 } |
722 } |
723 let chunk = |
723 let chunk = |
724 self.trim_chunk(revs, start_rev_idx, Some(end_rev_idx)); |
724 self.trim_chunk(revs, start_rev_idx, Some(end_rev_idx)); |
725 if !chunk.is_empty() { |
725 if !chunk.is_empty() { |
831 transaction: &mut impl Transaction, |
831 transaction: &mut impl Transaction, |
832 ) -> Result<(), HgError> { |
832 ) -> Result<(), HgError> { |
833 let data_size = if self.is_empty() { |
833 let data_size = if self.is_empty() { |
834 0 |
834 0 |
835 } else { |
835 } else { |
836 self.end(Revision((self.len() - 1) as BaseRevision)) |
836 self.data_end(Revision((self.len() - 1) as BaseRevision)) |
837 }; |
837 }; |
838 let data_handle = if !self.is_inline() { |
838 let data_handle = if !self.is_inline() { |
839 let data_handle = match self.vfs.open_write(&self.data_file) { |
839 let data_handle = match self.vfs.open_write(&self.data_file) { |
840 Ok(mut f) => { |
840 Ok(mut f) => { |
841 if let Some(end) = data_end { |
841 if let Some(end) = data_end { |