rust/hg-core/src/dirstate/dirstate_map.rs
changeset 43863 bc7d8f45c3b6
parent 43826 5ac243a92e37
child 43890 d8a96cebf75d
equal deleted inserted replaced
43862:5606e1cb4685 43863:bc7d8f45c3b6
   124                 dirs.delete_path(filename)?;
   124                 dirs.delete_path(filename)?;
   125             }
   125             }
   126         }
   126         }
   127         if old_state == EntryState::Unknown {
   127         if old_state == EntryState::Unknown {
   128             if let Some(ref mut all_dirs) = self.all_dirs {
   128             if let Some(ref mut all_dirs) = self.all_dirs {
   129                 all_dirs.add_path(filename);
   129                 all_dirs.add_path(filename)?;
   130             }
   130             }
   131         }
   131         }
   132 
   132 
   133         if let Some(ref mut file_fold_map) = self.file_fold_map {
   133         if let Some(ref mut file_fold_map) = self.file_fold_map {
   134             file_fold_map.remove(&normalize_case(filename));
   134             file_fold_map.remove(&normalize_case(filename));
   225 
   225 
   226     /// Both of these setters and their uses appear to be the simplest way to
   226     /// Both of these setters and their uses appear to be the simplest way to
   227     /// emulate a Python lazy property, but it is ugly and unidiomatic.
   227     /// emulate a Python lazy property, but it is ugly and unidiomatic.
   228     /// TODO One day, rewriting this struct using the typestate might be a
   228     /// TODO One day, rewriting this struct using the typestate might be a
   229     /// good idea.
   229     /// good idea.
   230     pub fn set_all_dirs(&mut self) {
   230     pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> {
   231         if self.all_dirs.is_none() {
   231         if self.all_dirs.is_none() {
   232             self.all_dirs =
   232             self.all_dirs =
   233                 Some(DirsMultiset::from_dirstate(&self.state_map, None));
   233                 Some(DirsMultiset::from_dirstate(&self.state_map, None)?);
   234         }
   234         }
   235     }
   235         Ok(())
   236 
   236     }
   237     pub fn set_dirs(&mut self) {
   237 
       
   238     pub fn set_dirs(&mut self) -> Result<(), DirstateMapError> {
   238         if self.dirs.is_none() {
   239         if self.dirs.is_none() {
   239             self.dirs = Some(DirsMultiset::from_dirstate(
   240             self.dirs = Some(DirsMultiset::from_dirstate(
   240                 &self.state_map,
   241                 &self.state_map,
   241                 Some(EntryState::Removed),
   242                 Some(EntryState::Removed),
   242             ));
   243             )?);
   243         }
   244         }
   244     }
   245         Ok(())
   245 
   246     }
   246     pub fn has_tracked_dir(&mut self, directory: &HgPath) -> bool {
   247 
   247         self.set_dirs();
   248     pub fn has_tracked_dir(
   248         self.dirs.as_ref().unwrap().contains(directory)
   249         &mut self,
   249     }
   250         directory: &HgPath,
   250 
   251     ) -> Result<bool, DirstateMapError> {
   251     pub fn has_dir(&mut self, directory: &HgPath) -> bool {
   252         self.set_dirs()?;
   252         self.set_all_dirs();
   253         Ok(self.dirs.as_ref().unwrap().contains(directory))
   253         self.all_dirs.as_ref().unwrap().contains(directory)
   254     }
       
   255 
       
   256     pub fn has_dir(
       
   257         &mut self,
       
   258         directory: &HgPath,
       
   259     ) -> Result<bool, DirstateMapError> {
       
   260         self.set_all_dirs()?;
       
   261         Ok(self.all_dirs.as_ref().unwrap().contains(directory))
   254     }
   262     }
   255 
   263 
   256     pub fn parents(
   264     pub fn parents(
   257         &mut self,
   265         &mut self,
   258         file_contents: &[u8],
   266         file_contents: &[u8],
   348     fn test_dirs_multiset() {
   356     fn test_dirs_multiset() {
   349         let mut map = DirstateMap::new();
   357         let mut map = DirstateMap::new();
   350         assert!(map.dirs.is_none());
   358         assert!(map.dirs.is_none());
   351         assert!(map.all_dirs.is_none());
   359         assert!(map.all_dirs.is_none());
   352 
   360 
   353         assert_eq!(false, map.has_dir(HgPath::new(b"nope")));
   361         assert_eq!(map.has_dir(HgPath::new(b"nope")).unwrap(), false);
   354         assert!(map.all_dirs.is_some());
   362         assert!(map.all_dirs.is_some());
   355         assert!(map.dirs.is_none());
   363         assert!(map.dirs.is_none());
   356 
   364 
   357         assert_eq!(false, map.has_tracked_dir(HgPath::new(b"nope")));
   365         assert_eq!(map.has_tracked_dir(HgPath::new(b"nope")).unwrap(), false);
   358         assert!(map.dirs.is_some());
   366         assert!(map.dirs.is_some());
   359     }
   367     }
   360 
   368 
   361     #[test]
   369     #[test]
   362     fn test_add_file() {
   370     fn test_add_file() {