422 let map = self.dirstate_map()?; |
422 let map = self.dirstate_map()?; |
423 // TODO: Maintain a `DirstateMap::dirty` flag, and return early here if |
423 // TODO: Maintain a `DirstateMap::dirty` flag, and return early here if |
424 // it’s unset |
424 // it’s unset |
425 let parents = self.dirstate_parents()?; |
425 let parents = self.dirstate_parents()?; |
426 let (packed_dirstate, old_uuid_to_remove) = if self.has_dirstate_v2() { |
426 let (packed_dirstate, old_uuid_to_remove) = if self.has_dirstate_v2() { |
427 let uuid = self.dirstate_data_file_uuid.get_or_init(self)?; |
427 let uuid_opt = self.dirstate_data_file_uuid.get_or_init(self)?; |
428 let mut uuid = uuid.as_ref(); |
428 let uuid_opt = uuid_opt.as_ref(); |
429 let can_append = uuid.is_some(); |
429 let can_append = uuid_opt.is_some(); |
430 let (data, tree_metadata, append, old_data_size) = |
430 let (data, tree_metadata, append, old_data_size) = |
431 map.pack_v2(can_append)?; |
431 map.pack_v2(can_append)?; |
432 if !append { |
432 |
433 uuid = None |
433 // Reuse the uuid, or generate a new one, keeping the old for |
434 } |
434 // deletion. |
435 let (uuid, old_uuid) = if let Some(uuid) = uuid { |
435 let (uuid, old_uuid) = match uuid_opt { |
436 let as_str = std::str::from_utf8(uuid) |
436 Some(uuid) => { |
437 .map_err(|_| { |
437 let as_str = std::str::from_utf8(uuid) |
438 HgError::corrupted("non-UTF-8 dirstate data file ID") |
438 .map_err(|_| { |
439 })? |
439 HgError::corrupted( |
440 .to_owned(); |
440 "non-UTF-8 dirstate data file ID", |
441 let old_uuid_to_remove = Some(as_str.to_owned()); |
441 ) |
442 (as_str, old_uuid_to_remove) |
442 })? |
443 } else { |
443 .to_owned(); |
444 (DirstateDocket::new_uid(), None) |
444 if append { |
|
445 (as_str, None) |
|
446 } else { |
|
447 (DirstateDocket::new_uid(), Some(as_str)) |
|
448 } |
|
449 } |
|
450 None => (DirstateDocket::new_uid(), None), |
445 }; |
451 }; |
|
452 |
446 let data_filename = format!("dirstate.{}", uuid); |
453 let data_filename = format!("dirstate.{}", uuid); |
447 let data_filename = self.hg_vfs().join(data_filename); |
454 let data_filename = self.hg_vfs().join(data_filename); |
448 let mut options = std::fs::OpenOptions::new(); |
455 let mut options = std::fs::OpenOptions::new(); |
449 if append { |
456 if append { |
450 options.append(true); |
457 options.append(true); |