rust/hg-core/src/revlog/index.rs
changeset 51222 fc05dd74e907
parent 51220 c817d9f626d3
child 51223 42c8dbdb88ad
equal deleted inserted replaced
51221:5a7d5fd6808c 51222:fc05dd74e907
   981                 min_rev = *root;
   981                 min_rev = *root;
   982             }
   982             }
   983         }
   983         }
   984         min_rev
   984         min_rev
   985     }
   985     }
       
   986 
       
   987     /// Return `(heads(::(<roots> and <roots>::<heads>)))`
       
   988     /// If `include_path` is `true`, return `(<roots>::<heads>)`."""
       
   989     ///
       
   990     /// `min_root` and `roots` are unchecked since they are just used as
       
   991     /// a bound or for comparison and don't need to represent a valid revision.
       
   992     /// In practice, the only invalid revision passed is the working directory
       
   993     /// revision ([`i32::MAX`]).
       
   994     pub fn reachable_roots(
       
   995         &self,
       
   996         min_root: UncheckedRevision,
       
   997         mut heads: Vec<Revision>,
       
   998         roots: HashSet<UncheckedRevision>,
       
   999         include_path: bool,
       
  1000     ) -> Result<HashSet<Revision>, GraphError> {
       
  1001         if roots.is_empty() {
       
  1002             return Ok(HashSet::new());
       
  1003         }
       
  1004         let mut reachable = HashSet::new();
       
  1005         let mut seen = HashMap::new();
       
  1006 
       
  1007         while let Some(rev) = heads.pop() {
       
  1008             if roots.contains(&rev.into()) {
       
  1009                 reachable.insert(rev);
       
  1010                 if !include_path {
       
  1011                     continue;
       
  1012                 }
       
  1013             }
       
  1014             let parents = self.parents(rev)?;
       
  1015             seen.insert(rev, parents);
       
  1016             for parent in parents {
       
  1017                 if parent.0 >= min_root.0 && !seen.contains_key(&parent) {
       
  1018                     heads.push(parent);
       
  1019                 }
       
  1020             }
       
  1021         }
       
  1022         if !include_path {
       
  1023             return Ok(reachable);
       
  1024         }
       
  1025         let mut revs: Vec<_> = seen.keys().collect();
       
  1026         revs.sort_unstable();
       
  1027         for rev in revs {
       
  1028             for parent in seen[rev] {
       
  1029                 if reachable.contains(&parent) {
       
  1030                     reachable.insert(*rev);
       
  1031                 }
       
  1032             }
       
  1033         }
       
  1034         Ok(reachable)
       
  1035     }
   986 }
  1036 }
   987 
  1037 
   988 /// Set of roots of all non-public phases
  1038 /// Set of roots of all non-public phases
   989 pub type RootsPerPhase = [HashSet<Revision>; Phase::non_public_phases().len()];
  1039 pub type RootsPerPhase = [HashSet<Revision>; Phase::non_public_phases().len()];
   990 
  1040