rust/hg-core/src/dirstate_tree/dirstate_map.rs
changeset 48026 1b2ee68e85f9
parent 48023 357307feaf61
child 48045 32ef647821b2
equal deleted inserted replaced
48025:631f6b445a77 48026:1b2ee68e85f9
   591     }
   591     }
   592 
   592 
   593     fn add_or_remove_file(
   593     fn add_or_remove_file(
   594         &mut self,
   594         &mut self,
   595         path: &HgPath,
   595         path: &HgPath,
   596         old_state: EntryState,
   596         old_state: Option<EntryState>,
   597         new_entry: DirstateEntry,
   597         new_entry: DirstateEntry,
   598     ) -> Result<(), DirstateV2ParseError> {
   598     ) -> Result<(), DirstateV2ParseError> {
   599         let had_entry = old_state != EntryState::Unknown;
   599         let had_entry = old_state.is_some();
       
   600         let was_tracked = old_state.map_or(false, |s| s.is_tracked());
   600         let tracked_count_increment =
   601         let tracked_count_increment =
   601             match (old_state.is_tracked(), new_entry.state().is_tracked()) {
   602             match (was_tracked, new_entry.state().is_tracked()) {
   602                 (false, true) => 1,
   603                 (false, true) => 1,
   603                 (true, false) => -1,
   604                 (true, false) => -1,
   604                 _ => 0,
   605                 _ => 0,
   605             };
   606             };
   606 
   607 
   806             mtime = entry.mtime() & V1_RANGEMASK;
   807             mtime = entry.mtime() & V1_RANGEMASK;
   807         }
   808         }
   808         let mode = entry.mode();
   809         let mode = entry.mode();
   809         let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
   810         let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
   810 
   811 
   811         let old_state = match self.get(filename)? {
   812         let old_state = self.get(filename)?.map(|e| e.state());
   812             Some(e) => e.state(),
       
   813             None => EntryState::Unknown,
       
   814         };
       
   815 
   813 
   816         Ok(self.add_or_remove_file(filename, old_state, entry)?)
   814         Ok(self.add_or_remove_file(filename, old_state, entry)?)
   817     }
   815     }
   818 
   816 
   819     fn remove_file(
   817     fn remove_file(
   820         &mut self,
   818         &mut self,
   821         filename: &HgPath,
   819         filename: &HgPath,
   822         in_merge: bool,
   820         in_merge: bool,
   823     ) -> Result<(), DirstateError> {
   821     ) -> Result<(), DirstateError> {
   824         let old_entry_opt = self.get(filename)?;
   822         let old_entry_opt = self.get(filename)?;
   825         let old_state = match old_entry_opt {
   823         let old_state = old_entry_opt.map(|e| e.state());
   826             Some(e) => e.state(),
       
   827             None => EntryState::Unknown,
       
   828         };
       
   829         let mut size = 0;
   824         let mut size = 0;
   830         if in_merge {
   825         if in_merge {
   831             // XXX we should not be able to have 'm' state and 'FROM_P2' if not
   826             // XXX we should not be able to have 'm' state and 'FROM_P2' if not
   832             // during a merge. So I (marmoute) am not sure we need the
   827             // during a merge. So I (marmoute) am not sure we need the
   833             // conditionnal at all. Adding double checking this with assert
   828             // conditionnal at all. Adding double checking this with assert
   850         let entry = DirstateEntry::new_removed(size);
   845         let entry = DirstateEntry::new_removed(size);
   851         Ok(self.add_or_remove_file(filename, old_state, entry)?)
   846         Ok(self.add_or_remove_file(filename, old_state, entry)?)
   852     }
   847     }
   853 
   848 
   854     fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
   849     fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
   855         let old_state = match self.get(filename)? {
   850         let was_tracked = self
   856             Some(e) => e.state(),
   851             .get(filename)?
   857             None => EntryState::Unknown,
   852             .map_or(false, |e| e.state().is_tracked());
   858         };
       
   859         struct Dropped {
   853         struct Dropped {
   860             was_tracked: bool,
   854             was_tracked: bool,
   861             had_entry: bool,
   855             had_entry: bool,
   862             had_copy_source: bool,
   856             had_copy_source: bool,
   863         }
   857         }
   953             if dropped.had_copy_source {
   947             if dropped.had_copy_source {
   954                 self.nodes_with_copy_source_count -= 1
   948                 self.nodes_with_copy_source_count -= 1
   955             }
   949             }
   956             Ok(dropped.had_entry)
   950             Ok(dropped.had_entry)
   957         } else {
   951         } else {
   958             debug_assert!(!old_state.is_tracked());
   952             debug_assert!(!was_tracked);
   959             Ok(false)
   953             Ok(false)
   960         }
   954         }
   961     }
   955     }
   962 
   956 
   963     fn clear_ambiguous_times(
   957     fn clear_ambiguous_times(