rust/hg-core/src/dirstate_tree/dispatch.rs
changeset 47335 ed1583a845d2
parent 47332 4ee9f419c52e
child 47351 3b9914b28133
equal deleted inserted replaced
47334:18b3060fe598 47335:ed1583a845d2
     1 use std::path::PathBuf;
     1 use std::path::PathBuf;
     2 
     2 
     3 use crate::dirstate::parsers::Timestamp;
     3 use crate::dirstate::parsers::Timestamp;
       
     4 use crate::dirstate_tree::on_disk::DirstateV2ParseError;
     4 use crate::matchers::Matcher;
     5 use crate::matchers::Matcher;
     5 use crate::utils::hg_path::{HgPath, HgPathBuf};
     6 use crate::utils::hg_path::{HgPath, HgPathBuf};
     6 use crate::CopyMapIter;
     7 use crate::CopyMapIter;
     7 use crate::DirstateEntry;
     8 use crate::DirstateEntry;
     8 use crate::DirstateError;
     9 use crate::DirstateError;
     9 use crate::DirstateMap;
    10 use crate::DirstateMap;
    10 use crate::DirstateMapError;
       
    11 use crate::DirstateParents;
    11 use crate::DirstateParents;
    12 use crate::DirstateStatus;
    12 use crate::DirstateStatus;
    13 use crate::EntryState;
    13 use crate::EntryState;
    14 use crate::PatternFileWarning;
    14 use crate::PatternFileWarning;
    15 use crate::StateMapIter;
    15 use crate::StateMapIter;
    22     fn add_file(
    22     fn add_file(
    23         &mut self,
    23         &mut self,
    24         filename: &HgPath,
    24         filename: &HgPath,
    25         old_state: EntryState,
    25         old_state: EntryState,
    26         entry: DirstateEntry,
    26         entry: DirstateEntry,
    27     ) -> Result<(), DirstateMapError>;
    27     ) -> Result<(), DirstateError>;
    28 
    28 
    29     fn remove_file(
    29     fn remove_file(
    30         &mut self,
    30         &mut self,
    31         filename: &HgPath,
    31         filename: &HgPath,
    32         old_state: EntryState,
    32         old_state: EntryState,
    33         size: i32,
    33         size: i32,
    34     ) -> Result<(), DirstateMapError>;
    34     ) -> Result<(), DirstateError>;
    35 
    35 
    36     fn drop_file(
    36     fn drop_file(
    37         &mut self,
    37         &mut self,
    38         filename: &HgPath,
    38         filename: &HgPath,
    39         old_state: EntryState,
    39         old_state: EntryState,
    40     ) -> Result<bool, DirstateMapError>;
    40     ) -> Result<bool, DirstateError>;
    41 
    41 
    42     fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32);
    42     fn clear_ambiguous_times(
    43 
    43         &mut self,
    44     fn non_normal_entries_contains(&mut self, key: &HgPath) -> bool;
    44         filenames: Vec<HgPathBuf>,
       
    45         now: i32,
       
    46     ) -> Result<(), DirstateV2ParseError>;
       
    47 
       
    48     fn non_normal_entries_contains(
       
    49         &mut self,
       
    50         key: &HgPath,
       
    51     ) -> Result<bool, DirstateV2ParseError>;
    45 
    52 
    46     fn non_normal_entries_remove(&mut self, key: &HgPath);
    53     fn non_normal_entries_remove(&mut self, key: &HgPath);
    47 
    54 
    48     fn non_normal_or_other_parent_paths(
    55     fn non_normal_or_other_parent_paths(
    49         &mut self,
    56         &mut self,
    50     ) -> Box<dyn Iterator<Item = &HgPath> + '_>;
    57     ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_>;
    51 
    58 
    52     fn set_non_normal_other_parent_entries(&mut self, force: bool);
    59     fn set_non_normal_other_parent_entries(&mut self, force: bool);
    53 
    60 
    54     fn iter_non_normal_paths(
    61     fn iter_non_normal_paths(
    55         &mut self,
    62         &mut self,
    56     ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>;
    63     ) -> Box<
       
    64         dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_,
       
    65     >;
    57 
    66 
    58     fn iter_non_normal_paths_panic(
    67     fn iter_non_normal_paths_panic(
    59         &self,
    68         &self,
    60     ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>;
    69     ) -> Box<
       
    70         dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_,
       
    71     >;
    61 
    72 
    62     fn iter_other_parent_paths(
    73     fn iter_other_parent_paths(
    63         &mut self,
    74         &mut self,
    64     ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>;
    75     ) -> Box<
       
    76         dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_,
       
    77     >;
    65 
    78 
    66     fn has_tracked_dir(
    79     fn has_tracked_dir(
    67         &mut self,
    80         &mut self,
    68         directory: &HgPath,
    81         directory: &HgPath,
    69     ) -> Result<bool, DirstateMapError>;
    82     ) -> Result<bool, DirstateError>;
    70 
    83 
    71     fn has_dir(
    84     fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError>;
    72         &mut self,
       
    73         directory: &HgPath,
       
    74     ) -> Result<bool, DirstateMapError>;
       
    75 
    85 
    76     fn pack_v1(
    86     fn pack_v1(
    77         &mut self,
    87         &mut self,
    78         parents: DirstateParents,
    88         parents: DirstateParents,
    79         now: Timestamp,
    89         now: Timestamp,
    83         &mut self,
    93         &mut self,
    84         parents: DirstateParents,
    94         parents: DirstateParents,
    85         now: Timestamp,
    95         now: Timestamp,
    86     ) -> Result<Vec<u8>, DirstateError>;
    96     ) -> Result<Vec<u8>, DirstateError>;
    87 
    97 
    88     fn set_all_dirs(&mut self) -> Result<(), DirstateMapError>;
    98     fn set_all_dirs(&mut self) -> Result<(), DirstateError>;
    89 
    99 
    90     fn set_dirs(&mut self) -> Result<(), DirstateMapError>;
   100     fn set_dirs(&mut self) -> Result<(), DirstateError>;
    91 
   101 
    92     fn status<'a>(
   102     fn status<'a>(
    93         &'a mut self,
   103         &'a mut self,
    94         matcher: &'a (dyn Matcher + Sync),
   104         matcher: &'a (dyn Matcher + Sync),
    95         root_dir: PathBuf,
   105         root_dir: PathBuf,
    99 
   109 
   100     fn copy_map_len(&self) -> usize;
   110     fn copy_map_len(&self) -> usize;
   101 
   111 
   102     fn copy_map_iter(&self) -> CopyMapIter<'_>;
   112     fn copy_map_iter(&self) -> CopyMapIter<'_>;
   103 
   113 
   104     fn copy_map_contains_key(&self, key: &HgPath) -> bool;
   114     fn copy_map_contains_key(
   105 
   115         &self,
   106     fn copy_map_get(&self, key: &HgPath) -> Option<&HgPath>;
   116         key: &HgPath,
   107 
   117     ) -> Result<bool, DirstateV2ParseError>;
   108     fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf>;
   118 
       
   119     fn copy_map_get(
       
   120         &self,
       
   121         key: &HgPath,
       
   122     ) -> Result<Option<&HgPath>, DirstateV2ParseError>;
       
   123 
       
   124     fn copy_map_remove(
       
   125         &mut self,
       
   126         key: &HgPath,
       
   127     ) -> Result<Option<HgPathBuf>, DirstateV2ParseError>;
   109 
   128 
   110     fn copy_map_insert(
   129     fn copy_map_insert(
   111         &mut self,
   130         &mut self,
   112         key: HgPathBuf,
   131         key: HgPathBuf,
   113         value: HgPathBuf,
   132         value: HgPathBuf,
   114     ) -> Option<HgPathBuf>;
   133     ) -> Result<Option<HgPathBuf>, DirstateV2ParseError>;
   115 
   134 
   116     fn len(&self) -> usize;
   135     fn len(&self) -> usize;
   117 
   136 
   118     fn contains_key(&self, key: &HgPath) -> bool;
   137     fn contains_key(&self, key: &HgPath)
   119 
   138         -> Result<bool, DirstateV2ParseError>;
   120     fn get(&self, key: &HgPath) -> Option<DirstateEntry>;
   139 
       
   140     fn get(
       
   141         &self,
       
   142         key: &HgPath,
       
   143     ) -> Result<Option<DirstateEntry>, DirstateV2ParseError>;
   121 
   144 
   122     fn iter(&self) -> StateMapIter<'_>;
   145     fn iter(&self) -> StateMapIter<'_>;
   123 }
   146 }
   124 
   147 
   125 impl DirstateMapMethods for DirstateMap {
   148 impl DirstateMapMethods for DirstateMap {
   130     fn add_file(
   153     fn add_file(
   131         &mut self,
   154         &mut self,
   132         filename: &HgPath,
   155         filename: &HgPath,
   133         old_state: EntryState,
   156         old_state: EntryState,
   134         entry: DirstateEntry,
   157         entry: DirstateEntry,
   135     ) -> Result<(), DirstateMapError> {
   158     ) -> Result<(), DirstateError> {
   136         self.add_file(filename, old_state, entry)
   159         self.add_file(filename, old_state, entry)
   137     }
   160     }
   138 
   161 
   139     fn remove_file(
   162     fn remove_file(
   140         &mut self,
   163         &mut self,
   141         filename: &HgPath,
   164         filename: &HgPath,
   142         old_state: EntryState,
   165         old_state: EntryState,
   143         size: i32,
   166         size: i32,
   144     ) -> Result<(), DirstateMapError> {
   167     ) -> Result<(), DirstateError> {
   145         self.remove_file(filename, old_state, size)
   168         self.remove_file(filename, old_state, size)
   146     }
   169     }
   147 
   170 
   148     fn drop_file(
   171     fn drop_file(
   149         &mut self,
   172         &mut self,
   150         filename: &HgPath,
   173         filename: &HgPath,
   151         old_state: EntryState,
   174         old_state: EntryState,
   152     ) -> Result<bool, DirstateMapError> {
   175     ) -> Result<bool, DirstateError> {
   153         self.drop_file(filename, old_state)
   176         self.drop_file(filename, old_state)
   154     }
   177     }
   155 
   178 
   156     fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32) {
   179     fn clear_ambiguous_times(
   157         self.clear_ambiguous_times(filenames, now)
   180         &mut self,
   158     }
   181         filenames: Vec<HgPathBuf>,
   159 
   182         now: i32,
   160     fn non_normal_entries_contains(&mut self, key: &HgPath) -> bool {
   183     ) -> Result<(), DirstateV2ParseError> {
       
   184         Ok(self.clear_ambiguous_times(filenames, now))
       
   185     }
       
   186 
       
   187     fn non_normal_entries_contains(
       
   188         &mut self,
       
   189         key: &HgPath,
       
   190     ) -> Result<bool, DirstateV2ParseError> {
   161         let (non_normal, _other_parent) =
   191         let (non_normal, _other_parent) =
   162             self.get_non_normal_other_parent_entries();
   192             self.get_non_normal_other_parent_entries();
   163         non_normal.contains(key)
   193         Ok(non_normal.contains(key))
   164     }
   194     }
   165 
   195 
   166     fn non_normal_entries_remove(&mut self, key: &HgPath) {
   196     fn non_normal_entries_remove(&mut self, key: &HgPath) {
   167         self.non_normal_entries_remove(key)
   197         self.non_normal_entries_remove(key)
   168     }
   198     }
   169 
   199 
   170     fn non_normal_or_other_parent_paths(
   200     fn non_normal_or_other_parent_paths(
   171         &mut self,
   201         &mut self,
   172     ) -> Box<dyn Iterator<Item = &HgPath> + '_> {
   202     ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_>
       
   203     {
   173         let (non_normal, other_parent) =
   204         let (non_normal, other_parent) =
   174             self.get_non_normal_other_parent_entries();
   205             self.get_non_normal_other_parent_entries();
   175         Box::new(non_normal.union(other_parent).map(|p| &**p))
   206         Box::new(non_normal.union(other_parent).map(|p| Ok(&**p)))
   176     }
   207     }
   177 
   208 
   178     fn set_non_normal_other_parent_entries(&mut self, force: bool) {
   209     fn set_non_normal_other_parent_entries(&mut self, force: bool) {
   179         self.set_non_normal_other_parent_entries(force)
   210         self.set_non_normal_other_parent_entries(force)
   180     }
   211     }
   181 
   212 
   182     fn iter_non_normal_paths(
   213     fn iter_non_normal_paths(
   183         &mut self,
   214         &mut self,
   184     ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> {
   215     ) -> Box<
       
   216         dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_,
       
   217     > {
   185         let (non_normal, _other_parent) =
   218         let (non_normal, _other_parent) =
   186             self.get_non_normal_other_parent_entries();
   219             self.get_non_normal_other_parent_entries();
   187         Box::new(non_normal.iter().map(|p| &**p))
   220         Box::new(non_normal.iter().map(|p| Ok(&**p)))
   188     }
   221     }
   189 
   222 
   190     fn iter_non_normal_paths_panic(
   223     fn iter_non_normal_paths_panic(
   191         &self,
   224         &self,
   192     ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> {
   225     ) -> Box<
       
   226         dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_,
       
   227     > {
   193         let (non_normal, _other_parent) =
   228         let (non_normal, _other_parent) =
   194             self.get_non_normal_other_parent_entries_panic();
   229             self.get_non_normal_other_parent_entries_panic();
   195         Box::new(non_normal.iter().map(|p| &**p))
   230         Box::new(non_normal.iter().map(|p| Ok(&**p)))
   196     }
   231     }
   197 
   232 
   198     fn iter_other_parent_paths(
   233     fn iter_other_parent_paths(
   199         &mut self,
   234         &mut self,
   200     ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> {
   235     ) -> Box<
       
   236         dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_,
       
   237     > {
   201         let (_non_normal, other_parent) =
   238         let (_non_normal, other_parent) =
   202             self.get_non_normal_other_parent_entries();
   239             self.get_non_normal_other_parent_entries();
   203         Box::new(other_parent.iter().map(|p| &**p))
   240         Box::new(other_parent.iter().map(|p| Ok(&**p)))
   204     }
   241     }
   205 
   242 
   206     fn has_tracked_dir(
   243     fn has_tracked_dir(
   207         &mut self,
   244         &mut self,
   208         directory: &HgPath,
   245         directory: &HgPath,
   209     ) -> Result<bool, DirstateMapError> {
   246     ) -> Result<bool, DirstateError> {
   210         self.has_tracked_dir(directory)
   247         self.has_tracked_dir(directory)
   211     }
   248     }
   212 
   249 
   213     fn has_dir(
   250     fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError> {
   214         &mut self,
       
   215         directory: &HgPath,
       
   216     ) -> Result<bool, DirstateMapError> {
       
   217         self.has_dir(directory)
   251         self.has_dir(directory)
   218     }
   252     }
   219 
   253 
   220     fn pack_v1(
   254     fn pack_v1(
   221         &mut self,
   255         &mut self,
   233         panic!(
   267         panic!(
   234             "should have used dirstate_tree::DirstateMap to use the v2 format"
   268             "should have used dirstate_tree::DirstateMap to use the v2 format"
   235         )
   269         )
   236     }
   270     }
   237 
   271 
   238     fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> {
   272     fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
   239         self.set_all_dirs()
   273         self.set_all_dirs()
   240     }
   274     }
   241 
   275 
   242     fn set_dirs(&mut self) -> Result<(), DirstateMapError> {
   276     fn set_dirs(&mut self) -> Result<(), DirstateError> {
   243         self.set_dirs()
   277         self.set_dirs()
   244     }
   278     }
   245 
   279 
   246     fn status<'a>(
   280     fn status<'a>(
   247         &'a mut self,
   281         &'a mut self,
   257     fn copy_map_len(&self) -> usize {
   291     fn copy_map_len(&self) -> usize {
   258         self.copy_map.len()
   292         self.copy_map.len()
   259     }
   293     }
   260 
   294 
   261     fn copy_map_iter(&self) -> CopyMapIter<'_> {
   295     fn copy_map_iter(&self) -> CopyMapIter<'_> {
   262         Box::new(self.copy_map.iter().map(|(key, value)| (&**key, &**value)))
   296         Box::new(
   263     }
   297             self.copy_map
   264 
   298                 .iter()
   265     fn copy_map_contains_key(&self, key: &HgPath) -> bool {
   299                 .map(|(key, value)| Ok((&**key, &**value))),
   266         self.copy_map.contains_key(key)
   300         )
   267     }
   301     }
   268 
   302 
   269     fn copy_map_get(&self, key: &HgPath) -> Option<&HgPath> {
   303     fn copy_map_contains_key(
   270         self.copy_map.get(key).map(|p| &**p)
   304         &self,
   271     }
   305         key: &HgPath,
   272 
   306     ) -> Result<bool, DirstateV2ParseError> {
   273     fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf> {
   307         Ok(self.copy_map.contains_key(key))
   274         self.copy_map.remove(key)
   308     }
       
   309 
       
   310     fn copy_map_get(
       
   311         &self,
       
   312         key: &HgPath,
       
   313     ) -> Result<Option<&HgPath>, DirstateV2ParseError> {
       
   314         Ok(self.copy_map.get(key).map(|p| &**p))
       
   315     }
       
   316 
       
   317     fn copy_map_remove(
       
   318         &mut self,
       
   319         key: &HgPath,
       
   320     ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> {
       
   321         Ok(self.copy_map.remove(key))
   275     }
   322     }
   276 
   323 
   277     fn copy_map_insert(
   324     fn copy_map_insert(
   278         &mut self,
   325         &mut self,
   279         key: HgPathBuf,
   326         key: HgPathBuf,
   280         value: HgPathBuf,
   327         value: HgPathBuf,
   281     ) -> Option<HgPathBuf> {
   328     ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> {
   282         self.copy_map.insert(key, value)
   329         Ok(self.copy_map.insert(key, value))
   283     }
   330     }
   284 
   331 
   285     fn len(&self) -> usize {
   332     fn len(&self) -> usize {
   286         (&**self).len()
   333         (&**self).len()
   287     }
   334     }
   288 
   335 
   289     fn contains_key(&self, key: &HgPath) -> bool {
   336     fn contains_key(
   290         (&**self).contains_key(key)
   337         &self,
   291     }
   338         key: &HgPath,
   292 
   339     ) -> Result<bool, DirstateV2ParseError> {
   293     fn get(&self, key: &HgPath) -> Option<DirstateEntry> {
   340         Ok((&**self).contains_key(key))
   294         (&**self).get(key).cloned()
   341     }
       
   342 
       
   343     fn get(
       
   344         &self,
       
   345         key: &HgPath,
       
   346     ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> {
       
   347         Ok((&**self).get(key).cloned())
   295     }
   348     }
   296 
   349 
   297     fn iter(&self) -> StateMapIter<'_> {
   350     fn iter(&self) -> StateMapIter<'_> {
   298         Box::new((&**self).iter().map(|(key, value)| (&**key, *value)))
   351         Box::new((&**self).iter().map(|(key, value)| Ok((&**key, *value))))
   299     }
   352     }
   300 }
   353 }