Show More
@@ -512,8 +512,73 b' impl Index {' | |||||
512 | // clear caches. This implies re-populating the offsets on-demand. |
|
512 | // clear caches. This implies re-populating the offsets on-demand. | |
513 | self.offsets = RwLock::new(None); |
|
513 | self.offsets = RwLock::new(None); | |
514 | } |
|
514 | } | |
|
515 | ||||
|
516 | /// Unchecked version of `is_snapshot`. | |||
|
517 | /// Assumes the caller checked that `rev` is within a valid revision range. | |||
|
518 | pub fn is_snapshot_unchecked( | |||
|
519 | &self, | |||
|
520 | mut rev: Revision, | |||
|
521 | ) -> Result<bool, RevlogError> { | |||
|
522 | while rev.0 >= 0 { | |||
|
523 | let entry = self.get_entry(rev).unwrap(); | |||
|
524 | let mut base = entry.base_revision_or_base_of_delta_chain().0; | |||
|
525 | if base == rev.0 { | |||
|
526 | base = NULL_REVISION.0; | |||
|
527 | } | |||
|
528 | if base == NULL_REVISION.0 { | |||
|
529 | return Ok(true); | |||
|
530 | } | |||
|
531 | let [mut p1, mut p2] = self | |||
|
532 | .parents(rev) | |||
|
533 | .map_err(|_| RevlogError::InvalidRevision)?; | |||
|
534 | while let Some(p1_entry) = self.get_entry(p1) { | |||
|
535 | if p1_entry.compressed_len() != 0 || p1.0 == 0 { | |||
|
536 | break; | |||
|
537 | } | |||
|
538 | let parent_base = | |||
|
539 | p1_entry.base_revision_or_base_of_delta_chain(); | |||
|
540 | if parent_base.0 == p1.0 { | |||
|
541 | break; | |||
|
542 | } | |||
|
543 | p1 = self | |||
|
544 | .check_revision(parent_base) | |||
|
545 | .ok_or(RevlogError::InvalidRevision)?; | |||
|
546 | } | |||
|
547 | while let Some(p2_entry) = self.get_entry(p2) { | |||
|
548 | if p2_entry.compressed_len() != 0 || p2.0 == 0 { | |||
|
549 | break; | |||
|
550 | } | |||
|
551 | let parent_base = | |||
|
552 | p2_entry.base_revision_or_base_of_delta_chain(); | |||
|
553 | if parent_base.0 == p2.0 { | |||
|
554 | break; | |||
|
555 | } | |||
|
556 | p2 = self | |||
|
557 | .check_revision(parent_base) | |||
|
558 | .ok_or(RevlogError::InvalidRevision)?; | |||
|
559 | } | |||
|
560 | if base == p1.0 || base == p2.0 { | |||
|
561 | return Ok(false); | |||
|
562 | } | |||
|
563 | rev = self | |||
|
564 | .check_revision(base.into()) | |||
|
565 | .ok_or(RevlogError::InvalidRevision)?; | |||
|
566 | } | |||
|
567 | Ok(rev == NULL_REVISION) | |||
|
568 | } | |||
|
569 | ||||
|
570 | /// Return whether the given revision is a snapshot. Returns an error if | |||
|
571 | /// `rev` is not within a valid revision range. | |||
|
572 | pub fn is_snapshot( | |||
|
573 | &self, | |||
|
574 | rev: UncheckedRevision, | |||
|
575 | ) -> Result<bool, RevlogError> { | |||
|
576 | let rev = self | |||
|
577 | .check_revision(rev) | |||
|
578 | .ok_or_else(|| RevlogError::corrupted("test"))?; | |||
|
579 | self.is_snapshot_unchecked(rev) | |||
|
580 | } | |||
515 | } |
|
581 | } | |
516 |
|
||||
517 | fn inline_scan(bytes: &[u8]) -> (usize, Vec<usize>) { |
|
582 | fn inline_scan(bytes: &[u8]) -> (usize, Vec<usize>) { | |
518 | let mut offset: usize = 0; |
|
583 | let mut offset: usize = 0; | |
519 | let mut offsets = Vec::new(); |
|
584 | let mut offsets = Vec::new(); |
@@ -257,8 +257,16 b' py_class!(pub class MixedIndex |py| {' | |||||
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /// True if the object is a snapshot |
|
259 | /// True if the object is a snapshot | |
260 |
def issnapshot(&self, *args, **kw) -> PyResult< |
|
260 | def issnapshot(&self, *args, **kw) -> PyResult<bool> { | |
261 | self.call_cindex(py, "issnapshot", args, kw) |
|
261 | let index = self.index(py).borrow(); | |
|
262 | let result = index | |||
|
263 | .is_snapshot(UncheckedRevision(args.get_item(py, 0).extract(py)?)) | |||
|
264 | .map_err(|e| { | |||
|
265 | PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string()) | |||
|
266 | })?; | |||
|
267 | let cresult = self.call_cindex(py, "issnapshot", args, kw)?; | |||
|
268 | assert_eq!(result, cresult.extract(py)?); | |||
|
269 | Ok(result) | |||
262 | } |
|
270 | } | |
263 |
|
271 | |||
264 | /// Gather snapshot data in a cache dict |
|
272 | /// Gather snapshot data in a cache dict |
General Comments 0
You need to be logged in to leave comments.
Login now