comparison rust/hg-core/src/revlog/index.rs @ 51213:62e39bef36ca

rust-index: add support for delta-chain computation
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 03 Aug 2023 15:50:14 +0200
parents 9b06e7f32bc5
children a7bba7df9189
comparison
equal deleted inserted replaced
51212:9b06e7f32bc5 51213:62e39bef36ca
510 bytes, 510 bytes,
511 offset_override, 511 offset_override,
512 } 512 }
513 } 513 }
514 514
515 /// Obtain the delta chain for a revision.
516 ///
517 /// `stop_rev` specifies a revision to stop at. If not specified, we
518 /// stop at the base of the chain.
519 ///
520 /// Returns a 2-tuple of (chain, stopped) where `chain` is a vec of
521 /// revs in ascending order and `stopped` is a bool indicating whether
522 /// `stoprev` was hit.
523 pub fn delta_chain(
524 &self,
525 rev: Revision,
526 stop_rev: Option<Revision>,
527 ) -> Result<(Vec<Revision>, bool), HgError> {
528 let mut current_rev = rev;
529 let mut entry = self.get_entry(rev).unwrap();
530 let mut chain = vec![];
531 while current_rev.0 != entry.base_revision_or_base_of_delta_chain().0
532 && stop_rev.map(|r| r != current_rev).unwrap_or(true)
533 {
534 chain.push(current_rev);
535 let new_rev = if self.uses_generaldelta() {
536 entry.base_revision_or_base_of_delta_chain()
537 } else {
538 UncheckedRevision(current_rev.0 - 1)
539 };
540 if new_rev.0 == NULL_REVISION.0 {
541 break;
542 }
543 current_rev = self.check_revision(new_rev).ok_or_else(|| {
544 HgError::corrupted(format!("Revision {new_rev} out of range"))
545 })?;
546 entry = self.get_entry(current_rev).unwrap()
547 }
548
549 let stopped = if stop_rev.map(|r| current_rev == r).unwrap_or(false) {
550 true
551 } else {
552 chain.push(current_rev);
553 false
554 };
555 chain.reverse();
556 Ok((chain, stopped))
557 }
558
515 pub fn find_snapshots( 559 pub fn find_snapshots(
516 &self, 560 &self,
517 start_rev: UncheckedRevision, 561 start_rev: UncheckedRevision,
518 end_rev: UncheckedRevision, 562 end_rev: UncheckedRevision,
519 cache: &mut impl SnapshotsCache, 563 cache: &mut impl SnapshotsCache,