rust/hg-core/src/dirstate/dirstate_map.rs
changeset 48026 1b2ee68e85f9
parent 48022 f2a9db29cb2d
child 48042 008959fcbfb2
equal deleted inserted replaced
48025:631f6b445a77 48026:1b2ee68e85f9
   109             mtime = entry.mtime() & V1_RANGEMASK;
   109             mtime = entry.mtime() & V1_RANGEMASK;
   110         }
   110         }
   111         let mode = entry.mode();
   111         let mode = entry.mode();
   112         let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
   112         let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
   113 
   113 
   114         let old_state = match self.get(filename) {
   114         let old_state = self.get(filename).map(|e| e.state());
   115             Some(e) => e.state(),
   115         if old_state.is_none() || old_state == Some(EntryState::Removed) {
   116             None => EntryState::Unknown,
       
   117         };
       
   118         if old_state == EntryState::Unknown || old_state == EntryState::Removed
       
   119         {
       
   120             if let Some(ref mut dirs) = self.dirs {
   116             if let Some(ref mut dirs) = self.dirs {
   121                 dirs.add_path(filename)?;
   117                 dirs.add_path(filename)?;
   122             }
   118             }
   123         }
   119         }
   124         if old_state == EntryState::Unknown {
   120         if old_state.is_none() {
   125             if let Some(ref mut all_dirs) = self.all_dirs {
   121             if let Some(ref mut all_dirs) = self.all_dirs {
   126                 all_dirs.add_path(filename)?;
   122                 all_dirs.add_path(filename)?;
   127             }
   123             }
   128         }
   124         }
   129         self.state_map.insert(filename.to_owned(), entry.to_owned());
   125         self.state_map.insert(filename.to_owned(), entry.to_owned());
   151         &mut self,
   147         &mut self,
   152         filename: &HgPath,
   148         filename: &HgPath,
   153         in_merge: bool,
   149         in_merge: bool,
   154     ) -> Result<(), DirstateError> {
   150     ) -> Result<(), DirstateError> {
   155         let old_entry_opt = self.get(filename);
   151         let old_entry_opt = self.get(filename);
   156         let old_state = match old_entry_opt {
   152         let old_state = old_entry_opt.map(|e| e.state());
   157             Some(e) => e.state(),
       
   158             None => EntryState::Unknown,
       
   159         };
       
   160         let mut size = 0;
   153         let mut size = 0;
   161         if in_merge {
   154         if in_merge {
   162             // XXX we should not be able to have 'm' state and 'FROM_P2' if not
   155             // XXX we should not be able to have 'm' state and 'FROM_P2' if not
   163             // during a merge. So I (marmoute) am not sure we need the
   156             // during a merge. So I (marmoute) am not sure we need the
   164             // conditionnal at all. Adding double checking this with assert
   157             // conditionnal at all. Adding double checking this with assert
   176                         .1
   169                         .1
   177                         .insert(filename.to_owned());
   170                         .insert(filename.to_owned());
   178                 }
   171                 }
   179             }
   172             }
   180         }
   173         }
   181         if old_state != EntryState::Unknown && old_state != EntryState::Removed
   174         if old_state.is_some() && old_state != Some(EntryState::Removed) {
   182         {
       
   183             if let Some(ref mut dirs) = self.dirs {
   175             if let Some(ref mut dirs) = self.dirs {
   184                 dirs.delete_path(filename)?;
   176                 dirs.delete_path(filename)?;
   185             }
   177             }
   186         }
   178         }
   187         if old_state == EntryState::Unknown {
   179         if old_state.is_none() {
   188             if let Some(ref mut all_dirs) = self.all_dirs {
   180             if let Some(ref mut all_dirs) = self.all_dirs {
   189                 all_dirs.add_path(filename)?;
   181                 all_dirs.add_path(filename)?;
   190             }
   182             }
   191         }
   183         }
   192         if size == 0 {
   184         if size == 0 {
   205     /// Returns `true` if the file was previously recorded.
   197     /// Returns `true` if the file was previously recorded.
   206     pub fn drop_file(
   198     pub fn drop_file(
   207         &mut self,
   199         &mut self,
   208         filename: &HgPath,
   200         filename: &HgPath,
   209     ) -> Result<bool, DirstateError> {
   201     ) -> Result<bool, DirstateError> {
   210         let old_state = match self.get(filename) {
   202         let old_state = self.get(filename).map(|e| e.state());
   211             Some(e) => e.state(),
       
   212             None => EntryState::Unknown,
       
   213         };
       
   214         let exists = self.state_map.remove(filename).is_some();
   203         let exists = self.state_map.remove(filename).is_some();
   215 
   204 
   216         if exists {
   205         if exists {
   217             if old_state != EntryState::Removed {
   206             if old_state != Some(EntryState::Removed) {
   218                 if let Some(ref mut dirs) = self.dirs {
   207                 if let Some(ref mut dirs) = self.dirs {
   219                     dirs.delete_path(filename)?;
   208                     dirs.delete_path(filename)?;
   220                 }
   209                 }
   221             }
   210             }
   222             if let Some(ref mut all_dirs) = self.all_dirs {
   211             if let Some(ref mut all_dirs) = self.all_dirs {