Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/repo.rs @ 51864:db7dbe6f7bb2
rust: add Vfs trait
This will allow for the use of multiple vfs like in the Python implementation,
as well as hiding the details of the upcoming Python vfs wrapper to hg-core.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 19 Jun 2024 14:49:35 +0200 |
parents | 69b804c8e09e |
children | 88aa21d654e5 |
comparison
equal
deleted
inserted
replaced
51863:69b804c8e09e | 51864:db7dbe6f7bb2 |
---|---|
16 use crate::revlog::RevlogError; | 16 use crate::revlog::RevlogError; |
17 use crate::utils::debug::debug_wait_for_file_or_print; | 17 use crate::utils::debug::debug_wait_for_file_or_print; |
18 use crate::utils::files::get_path_from_bytes; | 18 use crate::utils::files::get_path_from_bytes; |
19 use crate::utils::hg_path::HgPath; | 19 use crate::utils::hg_path::HgPath; |
20 use crate::utils::SliceExt; | 20 use crate::utils::SliceExt; |
21 use crate::vfs::{is_dir, is_file, Vfs}; | 21 use crate::vfs::{is_dir, is_file, VfsImpl}; |
22 use crate::{ | 22 use crate::{ |
23 requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig, | 23 requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig, |
24 RevlogFeatureConfig, RevlogType, RevlogVersionOptions, UncheckedRevision, | 24 RevlogFeatureConfig, RevlogType, RevlogVersionOptions, UncheckedRevision, |
25 }; | 25 }; |
26 use crate::{DirstateError, RevlogOpenOptions}; | 26 use crate::{DirstateError, RevlogOpenOptions}; |
119 let dot_hg = working_directory.join(".hg"); | 119 let dot_hg = working_directory.join(".hg"); |
120 | 120 |
121 let mut repo_config_files = | 121 let mut repo_config_files = |
122 vec![dot_hg.join("hgrc"), dot_hg.join("hgrc-not-shared")]; | 122 vec![dot_hg.join("hgrc"), dot_hg.join("hgrc-not-shared")]; |
123 | 123 |
124 let hg_vfs = Vfs { base: &dot_hg }; | 124 let hg_vfs = VfsImpl { |
125 let mut reqs = requirements::load_if_exists(hg_vfs)?; | 125 base: dot_hg.to_owned(), |
126 }; | |
127 let mut reqs = requirements::load_if_exists(&hg_vfs)?; | |
126 let relative = | 128 let relative = |
127 reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT); | 129 reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT); |
128 let shared = | 130 let shared = |
129 reqs.contains(requirements::SHARED_REQUIREMENT) || relative; | 131 reqs.contains(requirements::SHARED_REQUIREMENT) || relative; |
130 | 132 |
161 .into()); | 163 .into()); |
162 } | 164 } |
163 | 165 |
164 store_path = shared_path.join("store"); | 166 store_path = shared_path.join("store"); |
165 | 167 |
166 let source_is_share_safe = | 168 let source_is_share_safe = requirements::load(VfsImpl { |
167 requirements::load(Vfs { base: &shared_path })? | 169 base: shared_path.to_owned(), |
168 .contains(requirements::SHARESAFE_REQUIREMENT); | 170 })? |
171 .contains(requirements::SHARESAFE_REQUIREMENT); | |
169 | 172 |
170 if share_safe != source_is_share_safe { | 173 if share_safe != source_is_share_safe { |
171 return Err(HgError::unsupported("share-safe mismatch").into()); | 174 return Err(HgError::unsupported("share-safe mismatch").into()); |
172 } | 175 } |
173 | 176 |
174 if share_safe { | 177 if share_safe { |
175 repo_config_files.insert(0, shared_path.join("hgrc")) | 178 repo_config_files.insert(0, shared_path.join("hgrc")) |
176 } | 179 } |
177 } | 180 } |
178 if share_safe { | 181 if share_safe { |
179 reqs.extend(requirements::load(Vfs { base: &store_path })?); | 182 reqs.extend(requirements::load(VfsImpl { |
183 base: store_path.to_owned(), | |
184 })?); | |
180 } | 185 } |
181 | 186 |
182 let repo_config = if std::env::var_os("HGRCSKIPREPO").is_none() { | 187 let repo_config = if std::env::var_os("HGRCSKIPREPO").is_none() { |
183 config.combine_with_repo(&repo_config_files)? | 188 config.combine_with_repo(&repo_config_files)? |
184 } else { | 189 } else { |
214 &self.config | 219 &self.config |
215 } | 220 } |
216 | 221 |
217 /// For accessing repository files (in `.hg`), except for the store | 222 /// For accessing repository files (in `.hg`), except for the store |
218 /// (`.hg/store`). | 223 /// (`.hg/store`). |
219 pub fn hg_vfs(&self) -> Vfs<'_> { | 224 pub fn hg_vfs(&self) -> VfsImpl { |
220 Vfs { base: &self.dot_hg } | 225 VfsImpl { |
226 base: self.dot_hg.to_owned(), | |
227 } | |
221 } | 228 } |
222 | 229 |
223 /// For accessing repository store files (in `.hg/store`) | 230 /// For accessing repository store files (in `.hg/store`) |
224 pub fn store_vfs(&self) -> Vfs<'_> { | 231 pub fn store_vfs(&self) -> VfsImpl { |
225 Vfs { base: &self.store } | 232 VfsImpl { |
233 base: self.store.to_owned(), | |
234 } | |
226 } | 235 } |
227 | 236 |
228 /// For accessing the working copy | 237 /// For accessing the working copy |
229 pub fn working_directory_vfs(&self) -> Vfs<'_> { | 238 pub fn working_directory_vfs(&self) -> VfsImpl { |
230 Vfs { | 239 VfsImpl { |
231 base: &self.working_directory, | 240 base: self.working_directory.to_owned(), |
232 } | 241 } |
233 } | 242 } |
234 | 243 |
235 pub fn try_with_wlock_no_wait<R>( | 244 pub fn try_with_wlock_no_wait<R>( |
236 &self, | 245 &self, |
237 f: impl FnOnce() -> R, | 246 f: impl FnOnce() -> R, |
238 ) -> Result<R, LockError> { | 247 ) -> Result<R, LockError> { |
239 try_with_lock_no_wait(self.hg_vfs(), "wlock", f) | 248 try_with_lock_no_wait(&self.hg_vfs(), "wlock", f) |
240 } | 249 } |
241 | 250 |
242 /// Whether this repo should use dirstate-v2. | 251 /// Whether this repo should use dirstate-v2. |
243 /// The presence of `dirstate-v2` in the requirements does not mean that | 252 /// The presence of `dirstate-v2` in the requirements does not mean that |
244 /// the on-disk dirstate is necessarily in version 2. In most cases, | 253 /// the on-disk dirstate is necessarily in version 2. In most cases, |