Mercurial > hg
comparison rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47107:7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Again, various counters need to be kept up to date.
Differential Revision: https://phab.mercurial-scm.org/D10491
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 09 Apr 2021 12:55:35 +0200 |
parents | 52906934b775 |
children | e3cebe96c0fc |
comparison
equal
deleted
inserted
replaced
47106:52906934b775 | 47107:7dfc598ddcfe |
---|---|
328 self.nodes_with_copy_source_count = 0; | 328 self.nodes_with_copy_source_count = 0; |
329 } | 329 } |
330 | 330 |
331 fn add_file( | 331 fn add_file( |
332 &mut self, | 332 &mut self, |
333 _filename: &HgPath, | 333 filename: &HgPath, |
334 _old_state: EntryState, | 334 _old_state: EntryState, |
335 _entry: DirstateEntry, | 335 entry: DirstateEntry, |
336 ) -> Result<(), DirstateMapError> { | 336 ) -> Result<(), DirstateMapError> { |
337 todo!() | 337 self.add_file_node(filename, entry, None); |
338 Ok(()) | |
338 } | 339 } |
339 | 340 |
340 fn remove_file( | 341 fn remove_file( |
341 &mut self, | 342 &mut self, |
342 _filename: &HgPath, | 343 filename: &HgPath, |
343 _old_state: EntryState, | 344 _old_state: EntryState, |
344 _size: i32, | 345 size: i32, |
345 ) -> Result<(), DirstateMapError> { | 346 ) -> Result<(), DirstateMapError> { |
346 todo!() | 347 let entry = DirstateEntry { |
348 state: EntryState::Removed, | |
349 mode: 0, | |
350 size, | |
351 mtime: 0, | |
352 }; | |
353 self.add_file_node(filename, entry, None); | |
354 Ok(()) | |
347 } | 355 } |
348 | 356 |
349 fn drop_file( | 357 fn drop_file( |
350 &mut self, | 358 &mut self, |
351 _filename: &HgPath, | 359 filename: &HgPath, |
352 _old_state: EntryState, | 360 _old_state: EntryState, |
353 ) -> Result<bool, DirstateMapError> { | 361 ) -> Result<bool, DirstateMapError> { |
354 todo!() | 362 if let Some(node) = Self::get_node_mut(&mut self.root, filename) { |
363 let was_tracked = node.is_tracked_file(); | |
364 let had_entry = node.entry.is_some(); | |
365 let had_copy_source = node.copy_source.is_some(); | |
366 | |
367 // TODO: this leaves in the tree a "non-file" node. Should we | |
368 // remove the node instead, together with ancestor nodes for | |
369 // directories that become empty? | |
370 node.entry = None; | |
371 node.copy_source = None; | |
372 | |
373 if had_entry { | |
374 self.nodes_with_entry_count -= 1 | |
375 } | |
376 if had_copy_source { | |
377 self.nodes_with_copy_source_count -= 1 | |
378 } | |
379 if was_tracked { | |
380 self.for_each_ancestor_node(filename, |node| { | |
381 node.tracked_descendants_count -= 1 | |
382 }) | |
383 } | |
384 Ok(had_entry) | |
385 } else { | |
386 Ok(false) | |
387 } | |
355 } | 388 } |
356 | 389 |
357 fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32) { | 390 fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32) { |
358 for filename in filenames { | 391 for filename in filenames { |
359 if let Some(node) = Self::get_node_mut(&mut self.root, &filename) { | 392 if let Some(node) = Self::get_node_mut(&mut self.root, &filename) { |