Show More
@@ -47,15 +47,34 b' impl Repo {' | |||||
47 | /// To be called after checking that `.hg` is a sub-directory |
|
47 | /// To be called after checking that `.hg` is a sub-directory | |
48 | fn new_at_path(working_directory: PathBuf) -> Result<Self, HgError> { |
|
48 | fn new_at_path(working_directory: PathBuf) -> Result<Self, HgError> { | |
49 | let dot_hg = working_directory.join(".hg"); |
|
49 | let dot_hg = working_directory.join(".hg"); | |
|
50 | ||||
50 | let hg_vfs = Vfs { base: &dot_hg }; |
|
51 | let hg_vfs = Vfs { base: &dot_hg }; | |
51 | let reqs = requirements::load_if_exists(hg_vfs)?; |
|
52 | let mut reqs = requirements::load_if_exists(hg_vfs)?; | |
52 | let relative = |
|
53 | let relative = | |
53 | reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT); |
|
54 | reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT); | |
54 | let shared = |
|
55 | let shared = | |
55 | reqs.contains(requirements::SHARED_REQUIREMENT) || relative; |
|
56 | reqs.contains(requirements::SHARED_REQUIREMENT) || relative; | |
|
57 | ||||
|
58 | // From `mercurial/localrepo.py`: | |||
|
59 | // | |||
|
60 | // if .hg/requires contains the sharesafe requirement, it means | |||
|
61 | // there exists a `.hg/store/requires` too and we should read it | |||
|
62 | // NOTE: presence of SHARESAFE_REQUIREMENT imply that store requirement | |||
|
63 | // is present. We never write SHARESAFE_REQUIREMENT for a repo if store | |||
|
64 | // is not present, refer checkrequirementscompat() for that | |||
|
65 | // | |||
|
66 | // However, if SHARESAFE_REQUIREMENT is not present, it means that the | |||
|
67 | // repository was shared the old way. We check the share source | |||
|
68 | // .hg/requires for SHARESAFE_REQUIREMENT to detect whether the | |||
|
69 | // current repository needs to be reshared | |||
|
70 | let share_safe = reqs.contains(requirements::SHARESAFE_REQUIREMENT); | |||
|
71 | ||||
56 | let store_path; |
|
72 | let store_path; | |
57 | if !shared { |
|
73 | if !shared { | |
58 | store_path = dot_hg.join("store"); |
|
74 | store_path = dot_hg.join("store"); | |
|
75 | if share_safe { | |||
|
76 | reqs.extend(requirements::load(Vfs { base: &store_path })?); | |||
|
77 | } | |||
59 | } else { |
|
78 | } else { | |
60 | let bytes = hg_vfs.read("sharedpath")?; |
|
79 | let bytes = hg_vfs.read("sharedpath")?; | |
61 | let mut shared_path = get_path_from_bytes(&bytes).to_owned(); |
|
80 | let mut shared_path = get_path_from_bytes(&bytes).to_owned(); | |
@@ -70,6 +89,17 b' impl Repo {' | |||||
70 | } |
|
89 | } | |
71 |
|
90 | |||
72 | store_path = shared_path.join("store"); |
|
91 | store_path = shared_path.join("store"); | |
|
92 | ||||
|
93 | let source_is_share_safe = | |||
|
94 | requirements::load(Vfs { base: &shared_path })? | |||
|
95 | .contains(requirements::SHARESAFE_REQUIREMENT); | |||
|
96 | ||||
|
97 | // TODO: support for `share.safe-mismatch.*` config | |||
|
98 | if share_safe && !source_is_share_safe { | |||
|
99 | return Err(HgError::unsupported("share-safe downgrade")); | |||
|
100 | } else if source_is_share_safe && !share_safe { | |||
|
101 | return Err(HgError::unsupported("share-safe upgrade")); | |||
|
102 | } | |||
73 | } |
|
103 | } | |
74 |
|
104 | |||
75 | let repo = Self { |
|
105 | let repo = Self { |
@@ -22,6 +22,10 b' fn parse(bytes: &[u8]) -> Result<HashSet' | |||||
22 | .collect() |
|
22 | .collect() | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
|
25 | pub(crate) fn load(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> { | |||
|
26 | parse(&hg_vfs.read("requires")?) | |||
|
27 | } | |||
|
28 | ||||
25 | pub(crate) fn load_if_exists(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> { |
|
29 | pub(crate) fn load_if_exists(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> { | |
26 | if let Some(bytes) = hg_vfs.read("requires").io_not_found_as_none()? { |
|
30 | if let Some(bytes) = hg_vfs.read("requires").io_not_found_as_none()? { | |
27 | parse(&bytes) |
|
31 | parse(&bytes) | |
@@ -58,6 +62,7 b' const SUPPORTED: &[&str] = &[' | |||||
58 | "generaldelta", |
|
62 | "generaldelta", | |
59 | "revlogv1", |
|
63 | "revlogv1", | |
60 | SHARED_REQUIREMENT, |
|
64 | SHARED_REQUIREMENT, | |
|
65 | SHARESAFE_REQUIREMENT, | |||
61 | SPARSEREVLOG_REQUIREMENT, |
|
66 | SPARSEREVLOG_REQUIREMENT, | |
62 | RELATIVE_SHARED_REQUIREMENT, |
|
67 | RELATIVE_SHARED_REQUIREMENT, | |
63 | "store", |
|
68 | "store", | |
@@ -130,4 +135,4 b' pub(crate) const RELATIVE_SHARED_REQUIRE' | |||||
130 | /// store and working copy requirements i.e. both `.hg/requires` and |
|
135 | /// store and working copy requirements i.e. both `.hg/requires` and | |
131 | /// `.hg/store/requires` are present. |
|
136 | /// `.hg/store/requires` are present. | |
132 | #[allow(unused)] |
|
137 | #[allow(unused)] | |
133 |
pub(crate) const SHARESAFE_REQUIREMENT: &str = " |
|
138 | pub(crate) const SHARESAFE_REQUIREMENT: &str = "share-safe"; |
General Comments 0
You need to be logged in to leave comments.
Login now