Mercurial > hg
comparison rust/hg-core/src/repo.rs @ 49150:f2ef6a4f918f stable
rhg: fix dirstate-v2 data file removal system
In D12581 I introduced logic to remove the previous dirstate-v2 data file
after a new one is created (and its corresponding docket), but the logic was
flawed. I fixed it and made it simpler to understand by gather all logic in
a single expression.
Differential Revision: https://phab.mercurial-scm.org/D12586
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 25 Apr 2022 16:45:03 +0200 |
parents | 802e2c25dab8 |
children | a932cad26d37 2d0e22171ef9 |
comparison
equal
deleted
inserted
replaced
49149:006688e36e12 | 49150:f2ef6a4f918f |
---|---|
433 let map = self.dirstate_map()?; | 433 let map = self.dirstate_map()?; |
434 // TODO: Maintain a `DirstateMap::dirty` flag, and return early here if | 434 // TODO: Maintain a `DirstateMap::dirty` flag, and return early here if |
435 // it’s unset | 435 // it’s unset |
436 let parents = self.dirstate_parents()?; | 436 let parents = self.dirstate_parents()?; |
437 let (packed_dirstate, old_uuid_to_remove) = if self.has_dirstate_v2() { | 437 let (packed_dirstate, old_uuid_to_remove) = if self.has_dirstate_v2() { |
438 let uuid = self.dirstate_data_file_uuid.get_or_init(self)?; | 438 let uuid_opt = self.dirstate_data_file_uuid.get_or_init(self)?; |
439 let mut uuid = uuid.as_ref(); | 439 let uuid_opt = uuid_opt.as_ref(); |
440 let can_append = uuid.is_some(); | 440 let can_append = uuid_opt.is_some(); |
441 let (data, tree_metadata, append, old_data_size) = | 441 let (data, tree_metadata, append, old_data_size) = |
442 map.pack_v2(can_append)?; | 442 map.pack_v2(can_append)?; |
443 if !append { | 443 |
444 uuid = None | 444 // Reuse the uuid, or generate a new one, keeping the old for |
445 } | 445 // deletion. |
446 let (uuid, old_uuid) = if let Some(uuid) = uuid { | 446 let (uuid, old_uuid) = match uuid_opt { |
447 let as_str = std::str::from_utf8(uuid) | 447 Some(uuid) => { |
448 .map_err(|_| { | 448 let as_str = std::str::from_utf8(uuid) |
449 HgError::corrupted("non-UTF-8 dirstate data file ID") | 449 .map_err(|_| { |
450 })? | 450 HgError::corrupted( |
451 .to_owned(); | 451 "non-UTF-8 dirstate data file ID", |
452 let old_uuid_to_remove = Some(as_str.to_owned()); | 452 ) |
453 (as_str, old_uuid_to_remove) | 453 })? |
454 } else { | 454 .to_owned(); |
455 (DirstateDocket::new_uid(), None) | 455 if append { |
456 (as_str, None) | |
457 } else { | |
458 (DirstateDocket::new_uid(), Some(as_str)) | |
459 } | |
460 } | |
461 None => (DirstateDocket::new_uid(), None), | |
456 }; | 462 }; |
463 | |
457 let data_filename = format!("dirstate.{}", uuid); | 464 let data_filename = format!("dirstate.{}", uuid); |
458 let data_filename = self.hg_vfs().join(data_filename); | 465 let data_filename = self.hg_vfs().join(data_filename); |
459 let mut options = std::fs::OpenOptions::new(); | 466 let mut options = std::fs::OpenOptions::new(); |
460 if append { | 467 if append { |
461 options.append(true); | 468 options.append(true); |