##// END OF EJS Templates
rhg: add support for share-safe...
Simon Sapin -
r47191:95b27628 default
parent child Browse files
Show More
@@ -47,15 +47,34 b' impl Repo {'
47 47 /// To be called after checking that `.hg` is a sub-directory
48 48 fn new_at_path(working_directory: PathBuf) -> Result<Self, HgError> {
49 49 let dot_hg = working_directory.join(".hg");
50
50 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 53 let relative =
53 54 reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT);
54 55 let shared =
55 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 72 let store_path;
57 73 if !shared {
58 74 store_path = dot_hg.join("store");
75 if share_safe {
76 reqs.extend(requirements::load(Vfs { base: &store_path })?);
77 }
59 78 } else {
60 79 let bytes = hg_vfs.read("sharedpath")?;
61 80 let mut shared_path = get_path_from_bytes(&bytes).to_owned();
@@ -70,6 +89,17 b' impl Repo {'
70 89 }
71 90
72 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 105 let repo = Self {
@@ -22,6 +22,10 b' fn parse(bytes: &[u8]) -> Result<HashSet'
22 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 29 pub(crate) fn load_if_exists(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> {
26 30 if let Some(bytes) = hg_vfs.read("requires").io_not_found_as_none()? {
27 31 parse(&bytes)
@@ -58,6 +62,7 b' const SUPPORTED: &[&str] = &['
58 62 "generaldelta",
59 63 "revlogv1",
60 64 SHARED_REQUIREMENT,
65 SHARESAFE_REQUIREMENT,
61 66 SPARSEREVLOG_REQUIREMENT,
62 67 RELATIVE_SHARED_REQUIREMENT,
63 68 "store",
@@ -130,4 +135,4 b' pub(crate) const RELATIVE_SHARED_REQUIRE'
130 135 /// store and working copy requirements i.e. both `.hg/requires` and
131 136 /// `.hg/store/requires` are present.
132 137 #[allow(unused)]
133 pub(crate) const SHARESAFE_REQUIREMENT: &str = "exp-sharesafe";
138 pub(crate) const SHARESAFE_REQUIREMENT: &str = "share-safe";
@@ -256,7 +256,7 b' And check that basic rhg commands work w'
256 256
257 257 $ cd repo5
258 258 $ rhg files
259 [252]
259 a
260 260 $ rhg cat -r 0 a
261 [252]
261 a
262 262
General Comments 0
You need to be logged in to leave comments. Login now