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); |