Mercurial > hg
comparison rust/hg-core/src/requirements.rs @ 46462:d03b0601e0eb
rhg: initial support for shared repositories
Differential Revision: https://phab.mercurial-scm.org/D9941
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 14 Jan 2021 13:04:12 +0100 |
parents | 43d63979a75e |
children | 95b276283b67 |
comparison
equal
deleted
inserted
replaced
46461:f3f4d1b7dc97 | 46462:d03b0601e0eb |
---|---|
1 use crate::errors::{HgError, HgResultExt}; | 1 use crate::errors::{HgError, HgResultExt}; |
2 use crate::repo::Repo; | 2 use crate::repo::{Repo, Vfs}; |
3 use std::collections::HashSet; | |
3 | 4 |
4 fn parse(bytes: &[u8]) -> Result<Vec<String>, HgError> { | 5 fn parse(bytes: &[u8]) -> Result<HashSet<String>, HgError> { |
5 // The Python code reading this file uses `str.splitlines` | 6 // The Python code reading this file uses `str.splitlines` |
6 // which looks for a number of line separators (even including a couple of | 7 // which looks for a number of line separators (even including a couple of |
7 // non-ASCII ones), but Python code writing it always uses `\n`. | 8 // non-ASCII ones), but Python code writing it always uses `\n`. |
8 let lines = bytes.split(|&byte| byte == b'\n'); | 9 let lines = bytes.split(|&byte| byte == b'\n'); |
9 | 10 |
19 } | 20 } |
20 }) | 21 }) |
21 .collect() | 22 .collect() |
22 } | 23 } |
23 | 24 |
24 pub fn load(repo: &Repo) -> Result<Vec<String>, HgError> { | 25 pub(crate) fn load_if_exists(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> { |
25 if let Some(bytes) = | 26 if let Some(bytes) = hg_vfs.read("requires").io_not_found_as_none()? { |
26 repo.hg_vfs().read("requires").io_not_found_as_none()? | |
27 { | |
28 parse(&bytes) | 27 parse(&bytes) |
29 } else { | 28 } else { |
30 // Treat a missing file the same as an empty file. | 29 // Treat a missing file the same as an empty file. |
31 // From `mercurial/localrepo.py`: | 30 // From `mercurial/localrepo.py`: |
32 // > requires file contains a newline-delimited list of | 31 // > requires file contains a newline-delimited list of |
33 // > features/capabilities the opener (us) must have in order to use | 32 // > features/capabilities the opener (us) must have in order to use |
34 // > the repository. This file was introduced in Mercurial 0.9.2, | 33 // > the repository. This file was introduced in Mercurial 0.9.2, |
35 // > which means very old repositories may not have one. We assume | 34 // > which means very old repositories may not have one. We assume |
36 // > a missing file translates to no requirements. | 35 // > a missing file translates to no requirements. |
37 Ok(Vec::new()) | 36 Ok(HashSet::new()) |
38 } | 37 } |
39 } | 38 } |
40 | 39 |
41 pub fn check(repo: &Repo) -> Result<(), HgError> { | 40 pub(crate) fn check(repo: &Repo) -> Result<(), HgError> { |
42 for feature in load(repo)? { | 41 for feature in repo.requirements() { |
43 if !SUPPORTED.contains(&&*feature) { | 42 if !SUPPORTED.contains(&feature.as_str()) { |
44 // TODO: collect and all unknown features and include them in the | 43 // TODO: collect and all unknown features and include them in the |
45 // error message? | 44 // error message? |
46 return Err(HgError::UnsupportedFeature(format!( | 45 return Err(HgError::UnsupportedFeature(format!( |
47 "repository requires feature unknown to this Mercurial: {}", | 46 "repository requires feature unknown to this Mercurial: {}", |
48 feature | 47 feature |
56 const SUPPORTED: &[&str] = &[ | 55 const SUPPORTED: &[&str] = &[ |
57 "dotencode", | 56 "dotencode", |
58 "fncache", | 57 "fncache", |
59 "generaldelta", | 58 "generaldelta", |
60 "revlogv1", | 59 "revlogv1", |
61 "sparserevlog", | 60 SHARED_REQUIREMENT, |
61 SPARSEREVLOG_REQUIREMENT, | |
62 RELATIVE_SHARED_REQUIREMENT, | |
62 "store", | 63 "store", |
63 // As of this writing everything rhg does is read-only. | 64 // As of this writing everything rhg does is read-only. |
64 // When it starts writing to the repository, it’ll need to either keep the | 65 // When it starts writing to the repository, it’ll need to either keep the |
65 // persistent nodemap up to date or remove this entry: | 66 // persistent nodemap up to date or remove this entry: |
66 "persistent-nodemap", | 67 "persistent-nodemap", |
67 ]; | 68 ]; |
69 | |
70 // Copied from mercurial/requirements.py: | |
71 | |
72 /// When narrowing is finalized and no longer subject to format changes, | |
73 /// we should move this to just "narrow" or similar. | |
74 #[allow(unused)] | |
75 pub(crate) const NARROW_REQUIREMENT: &str = "narrowhg-experimental"; | |
76 | |
77 /// Enables sparse working directory usage | |
78 #[allow(unused)] | |
79 pub(crate) const SPARSE_REQUIREMENT: &str = "exp-sparse"; | |
80 | |
81 /// Enables the internal phase which is used to hide changesets instead | |
82 /// of stripping them | |
83 #[allow(unused)] | |
84 pub(crate) const INTERNAL_PHASE_REQUIREMENT: &str = "internal-phase"; | |
85 | |
86 /// Stores manifest in Tree structure | |
87 #[allow(unused)] | |
88 pub(crate) const TREEMANIFEST_REQUIREMENT: &str = "treemanifest"; | |
89 | |
90 /// Increment the sub-version when the revlog v2 format changes to lock out old | |
91 /// clients. | |
92 #[allow(unused)] | |
93 pub(crate) const REVLOGV2_REQUIREMENT: &str = "exp-revlogv2.1"; | |
94 | |
95 /// A repository with the sparserevlog feature will have delta chains that | |
96 /// can spread over a larger span. Sparse reading cuts these large spans into | |
97 /// pieces, so that each piece isn't too big. | |
98 /// Without the sparserevlog capability, reading from the repository could use | |
99 /// huge amounts of memory, because the whole span would be read at once, | |
100 /// including all the intermediate revisions that aren't pertinent for the | |
101 /// chain. This is why once a repository has enabled sparse-read, it becomes | |
102 /// required. | |
103 #[allow(unused)] | |
104 pub(crate) const SPARSEREVLOG_REQUIREMENT: &str = "sparserevlog"; | |
105 | |
106 /// A repository with the sidedataflag requirement will allow to store extra | |
107 /// information for revision without altering their original hashes. | |
108 #[allow(unused)] | |
109 pub(crate) const SIDEDATA_REQUIREMENT: &str = "exp-sidedata-flag"; | |
110 | |
111 /// A repository with the the copies-sidedata-changeset requirement will store | |
112 /// copies related information in changeset's sidedata. | |
113 #[allow(unused)] | |
114 pub(crate) const COPIESSDC_REQUIREMENT: &str = "exp-copies-sidedata-changeset"; | |
115 | |
116 /// The repository use persistent nodemap for the changelog and the manifest. | |
117 #[allow(unused)] | |
118 pub(crate) const NODEMAP_REQUIREMENT: &str = "persistent-nodemap"; | |
119 | |
120 /// Denotes that the current repository is a share | |
121 #[allow(unused)] | |
122 pub(crate) const SHARED_REQUIREMENT: &str = "shared"; | |
123 | |
124 /// Denotes that current repository is a share and the shared source path is | |
125 /// relative to the current repository root path | |
126 #[allow(unused)] | |
127 pub(crate) const RELATIVE_SHARED_REQUIREMENT: &str = "relshared"; | |
128 | |
129 /// A repository with share implemented safely. The repository has different | |
130 /// store and working copy requirements i.e. both `.hg/requires` and | |
131 /// `.hg/store/requires` are present. | |
132 #[allow(unused)] | |
133 pub(crate) const SHARESAFE_REQUIREMENT: &str = "exp-sharesafe"; |