rust/hg-core/src/dirstate/dirstate_map.rs
changeset 48022 f2a9db29cb2d
parent 47944 e02f9af7aed1
child 48026 1b2ee68e85f9
equal deleted inserted replaced
48021:627cd8f33db0 48022:f2a9db29cb2d
    77         added: bool,
    77         added: bool,
    78         merged: bool,
    78         merged: bool,
    79         from_p2: bool,
    79         from_p2: bool,
    80         possibly_dirty: bool,
    80         possibly_dirty: bool,
    81     ) -> Result<(), DirstateError> {
    81     ) -> Result<(), DirstateError> {
    82         let mut entry = entry;
    82         let state;
       
    83         let size;
       
    84         let mtime;
    83         if added {
    85         if added {
    84             assert!(!merged);
       
    85             assert!(!possibly_dirty);
    86             assert!(!possibly_dirty);
    86             assert!(!from_p2);
    87             assert!(!from_p2);
    87             entry.state = EntryState::Added;
    88             state = EntryState::Added;
    88             entry.size = SIZE_NON_NORMAL;
    89             size = SIZE_NON_NORMAL;
    89             entry.mtime = MTIME_UNSET;
    90             mtime = MTIME_UNSET;
    90         } else if merged {
    91         } else if merged {
    91             assert!(!possibly_dirty);
    92             assert!(!possibly_dirty);
    92             assert!(!from_p2);
    93             assert!(!from_p2);
    93             entry.state = EntryState::Merged;
    94             state = EntryState::Merged;
    94             entry.size = SIZE_FROM_OTHER_PARENT;
    95             size = SIZE_FROM_OTHER_PARENT;
    95             entry.mtime = MTIME_UNSET;
    96             mtime = MTIME_UNSET;
    96         } else if from_p2 {
    97         } else if from_p2 {
    97             assert!(!possibly_dirty);
    98             assert!(!possibly_dirty);
    98             entry.state = EntryState::Normal;
    99             state = EntryState::Normal;
    99             entry.size = SIZE_FROM_OTHER_PARENT;
   100             size = SIZE_FROM_OTHER_PARENT;
   100             entry.mtime = MTIME_UNSET;
   101             mtime = MTIME_UNSET;
   101         } else if possibly_dirty {
   102         } else if possibly_dirty {
   102             entry.state = EntryState::Normal;
   103             state = EntryState::Normal;
   103             entry.size = SIZE_NON_NORMAL;
   104             size = SIZE_NON_NORMAL;
   104             entry.mtime = MTIME_UNSET;
   105             mtime = MTIME_UNSET;
   105         } else {
   106         } else {
   106             entry.state = EntryState::Normal;
   107             state = EntryState::Normal;
   107             entry.size = entry.size & V1_RANGEMASK;
   108             size = entry.size() & V1_RANGEMASK;
   108             entry.mtime = entry.mtime & V1_RANGEMASK;
   109             mtime = entry.mtime() & V1_RANGEMASK;
   109         }
   110         }
       
   111         let mode = entry.mode();
       
   112         let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
       
   113 
   110         let old_state = match self.get(filename) {
   114         let old_state = match self.get(filename) {
   111             Some(e) => e.state,
   115             Some(e) => e.state(),
   112             None => EntryState::Unknown,
   116             None => EntryState::Unknown,
   113         };
   117         };
   114         if old_state == EntryState::Unknown || old_state == EntryState::Removed
   118         if old_state == EntryState::Unknown || old_state == EntryState::Removed
   115         {
   119         {
   116             if let Some(ref mut dirs) = self.dirs {
   120             if let Some(ref mut dirs) = self.dirs {
   148         filename: &HgPath,
   152         filename: &HgPath,
   149         in_merge: bool,
   153         in_merge: bool,
   150     ) -> Result<(), DirstateError> {
   154     ) -> Result<(), DirstateError> {
   151         let old_entry_opt = self.get(filename);
   155         let old_entry_opt = self.get(filename);
   152         let old_state = match old_entry_opt {
   156         let old_state = match old_entry_opt {
   153             Some(e) => e.state,
   157             Some(e) => e.state(),
   154             None => EntryState::Unknown,
   158             None => EntryState::Unknown,
   155         };
   159         };
   156         let mut size = 0;
   160         let mut size = 0;
   157         if in_merge {
   161         if in_merge {
   158             // XXX we should not be able to have 'm' state and 'FROM_P2' if not
   162             // XXX we should not be able to have 'm' state and 'FROM_P2' if not
   159             // during a merge. So I (marmoute) am not sure we need the
   163             // during a merge. So I (marmoute) am not sure we need the
   160             // conditionnal at all. Adding double checking this with assert
   164             // conditionnal at all. Adding double checking this with assert
   161             // would be nice.
   165             // would be nice.
   162             if let Some(old_entry) = old_entry_opt {
   166             if let Some(old_entry) = old_entry_opt {
   163                 // backup the previous state
   167                 // backup the previous state
   164                 if old_entry.state == EntryState::Merged {
   168                 if old_entry.state() == EntryState::Merged {
   165                     size = SIZE_NON_NORMAL;
   169                     size = SIZE_NON_NORMAL;
   166                 } else if old_entry.state == EntryState::Normal
   170                 } else if old_entry.state() == EntryState::Normal
   167                     && old_entry.size == SIZE_FROM_OTHER_PARENT
   171                     && old_entry.size() == SIZE_FROM_OTHER_PARENT
   168                 {
   172                 {
   169                     // other parent
   173                     // other parent
   170                     size = SIZE_FROM_OTHER_PARENT;
   174                     size = SIZE_FROM_OTHER_PARENT;
   171                     self.get_non_normal_other_parent_entries()
   175                     self.get_non_normal_other_parent_entries()
   172                         .1
   176                         .1
   187         }
   191         }
   188         if size == 0 {
   192         if size == 0 {
   189             self.copy_map.remove(filename);
   193             self.copy_map.remove(filename);
   190         }
   194         }
   191 
   195 
   192         self.state_map.insert(
   196         self.state_map
   193             filename.to_owned(),
   197             .insert(filename.to_owned(), DirstateEntry::new_removed(size));
   194             DirstateEntry {
       
   195                 state: EntryState::Removed,
       
   196                 mode: 0,
       
   197                 size,
       
   198                 mtime: 0,
       
   199             },
       
   200         );
       
   201         self.get_non_normal_other_parent_entries()
   198         self.get_non_normal_other_parent_entries()
   202             .0
   199             .0
   203             .insert(filename.to_owned());
   200             .insert(filename.to_owned());
   204         Ok(())
   201         Ok(())
   205     }
   202     }
   209     pub fn drop_file(
   206     pub fn drop_file(
   210         &mut self,
   207         &mut self,
   211         filename: &HgPath,
   208         filename: &HgPath,
   212     ) -> Result<bool, DirstateError> {
   209     ) -> Result<bool, DirstateError> {
   213         let old_state = match self.get(filename) {
   210         let old_state = match self.get(filename) {
   214             Some(e) => e.state,
   211             Some(e) => e.state(),
   215             None => EntryState::Unknown,
   212             None => EntryState::Unknown,
   216         };
   213         };
   217         let exists = self.state_map.remove(filename).is_some();
   214         let exists = self.state_map.remove(filename).is_some();
   218 
   215 
   219         if exists {
   216         if exists {
   426 
   423 
   427         assert_eq!(0, map.len());
   424         assert_eq!(0, map.len());
   428 
   425 
   429         map.add_file(
   426         map.add_file(
   430             HgPath::new(b"meh"),
   427             HgPath::new(b"meh"),
   431             DirstateEntry {
   428             DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337),
   432                 state: EntryState::Normal,
       
   433                 mode: 1337,
       
   434                 mtime: 1337,
       
   435                 size: 1337,
       
   436             },
       
   437             false,
   429             false,
   438             false,
   430             false,
   439             false,
   431             false,
   440             false,
   432             false,
   441         )
   433         )
   463         ]
   455         ]
   464         .iter()
   456         .iter()
   465         .map(|(fname, (state, mode, size, mtime))| {
   457         .map(|(fname, (state, mode, size, mtime))| {
   466             (
   458             (
   467                 HgPathBuf::from_bytes(fname.as_ref()),
   459                 HgPathBuf::from_bytes(fname.as_ref()),
   468                 DirstateEntry {
   460                 DirstateEntry::from_v1_data(*state, *mode, *size, *mtime),
   469                     state: *state,
       
   470                     mode: *mode,
       
   471                     size: *size,
       
   472                     mtime: *mtime,
       
   473                 },
       
   474             )
   461             )
   475         })
   462         })
   476         .collect();
   463         .collect();
   477 
   464 
   478         let mut non_normal = [
   465         let mut non_normal = [