equal
deleted
inserted
replaced
1 use crate::changelog::Changelog; |
1 use crate::changelog::Changelog; |
2 use crate::config::{Config, ConfigError, ConfigParseError}; |
2 use crate::config::{Config, ConfigError, ConfigParseError}; |
3 use crate::dirstate::DirstateParents; |
3 use crate::dirstate::DirstateParents; |
4 use crate::dirstate_tree::dirstate_map::DirstateMapWriteMode; |
4 use crate::dirstate_tree::dirstate_map::{ |
|
5 DirstateIdentity, DirstateMapWriteMode, |
|
6 }; |
5 use crate::dirstate_tree::on_disk::Docket as DirstateDocket; |
7 use crate::dirstate_tree::on_disk::Docket as DirstateDocket; |
6 use crate::dirstate_tree::owning::OwningDirstateMap; |
8 use crate::dirstate_tree::owning::OwningDirstateMap; |
7 use crate::errors::HgResultExt; |
9 use crate::errors::HgResultExt; |
8 use crate::errors::{HgError, IoResultExt}; |
10 use crate::errors::{HgError, IoResultExt}; |
9 use crate::lock::{try_with_lock_no_wait, LockError}; |
11 use crate::lock::{try_with_lock_no_wait, LockError}; |
32 use std::io::Write as IoWrite; |
34 use std::io::Write as IoWrite; |
33 use std::path::{Path, PathBuf}; |
35 use std::path::{Path, PathBuf}; |
34 |
36 |
35 const V2_MAX_READ_ATTEMPTS: usize = 5; |
37 const V2_MAX_READ_ATTEMPTS: usize = 5; |
36 |
38 |
37 type DirstateMapIdentity = (Option<u64>, Option<Vec<u8>>, usize); |
39 /// Docket file identity, data file uuid and the data size |
|
40 type DirstateV2Identity = (Option<DirstateIdentity>, Option<Vec<u8>>, usize); |
38 |
41 |
39 /// A repository on disk |
42 /// A repository on disk |
40 pub struct Repo { |
43 pub struct Repo { |
41 working_directory: PathBuf, |
44 working_directory: PathBuf, |
42 dot_hg: PathBuf, |
45 dot_hg: PathBuf, |
309 .read("dirstate") |
312 .read("dirstate") |
310 .io_not_found_as_none()? |
313 .io_not_found_as_none()? |
311 .unwrap_or_default()) |
314 .unwrap_or_default()) |
312 } |
315 } |
313 |
316 |
314 fn dirstate_identity(&self) -> Result<Option<u64>, HgError> { |
317 fn dirstate_identity(&self) -> Result<Option<DirstateIdentity>, HgError> { |
315 use std::os::unix::fs::MetadataExt; |
|
316 Ok(self |
318 Ok(self |
317 .hg_vfs() |
319 .hg_vfs() |
318 .symlink_metadata("dirstate") |
320 .symlink_metadata("dirstate") |
319 .io_not_found_as_none()? |
321 .io_not_found_as_none()? |
320 .map(|meta| meta.ino())) |
322 .map(DirstateIdentity::from)) |
321 } |
323 } |
322 |
324 |
323 pub fn dirstate_parents(&self) -> Result<DirstateParents, HgError> { |
325 pub fn dirstate_parents(&self) -> Result<DirstateParents, HgError> { |
324 Ok(*self |
326 Ok(*self |
325 .dirstate_parents |
327 .dirstate_parents |
353 } |
355 } |
354 |
356 |
355 /// Returns the information read from the dirstate docket necessary to |
357 /// Returns the information read from the dirstate docket necessary to |
356 /// check if the data file has been updated/deleted by another process |
358 /// check if the data file has been updated/deleted by another process |
357 /// since we last read the dirstate. |
359 /// since we last read the dirstate. |
358 /// Namely, the inode, data file uuid and the data size. |
360 /// Namely the docket file identity, data file uuid and the data size. |
359 fn get_dirstate_data_file_integrity( |
361 fn get_dirstate_data_file_integrity( |
360 &self, |
362 &self, |
361 ) -> Result<DirstateMapIdentity, HgError> { |
363 ) -> Result<DirstateV2Identity, HgError> { |
362 assert!( |
364 assert!( |
363 self.use_dirstate_v2(), |
365 self.use_dirstate_v2(), |
364 "accessing dirstate data file ID without dirstate-v2" |
366 "accessing dirstate data file ID without dirstate-v2" |
365 ); |
367 ); |
366 // Get the identity before the contents since we could have a race |
368 // Get the identity before the contents since we could have a race |