##// END OF EJS Templates
rhg: make rhg recognise it supports zstd compression for revlogs...
marmoute -
r47632:3c470706 default draft
parent child Browse files
Show More
@@ -1,153 +1,158 b''
1 use crate::errors::{HgError, HgResultExt};
1 use crate::errors::{HgError, HgResultExt};
2 use crate::repo::{Repo, Vfs};
2 use crate::repo::{Repo, Vfs};
3 use crate::utils::join_display;
3 use crate::utils::join_display;
4 use std::collections::HashSet;
4 use std::collections::HashSet;
5
5
6 fn parse(bytes: &[u8]) -> Result<HashSet<String>, HgError> {
6 fn parse(bytes: &[u8]) -> Result<HashSet<String>, HgError> {
7 // The Python code reading this file uses `str.splitlines`
7 // The Python code reading this file uses `str.splitlines`
8 // which looks for a number of line separators (even including a couple of
8 // which looks for a number of line separators (even including a couple of
9 // non-ASCII ones), but Python code writing it always uses `\n`.
9 // non-ASCII ones), but Python code writing it always uses `\n`.
10 let lines = bytes.split(|&byte| byte == b'\n');
10 let lines = bytes.split(|&byte| byte == b'\n');
11
11
12 lines
12 lines
13 .filter(|line| !line.is_empty())
13 .filter(|line| !line.is_empty())
14 .map(|line| {
14 .map(|line| {
15 // Python uses Unicode `str.isalnum` but feature names are all
15 // Python uses Unicode `str.isalnum` but feature names are all
16 // ASCII
16 // ASCII
17 if line[0].is_ascii_alphanumeric() && line.is_ascii() {
17 if line[0].is_ascii_alphanumeric() && line.is_ascii() {
18 Ok(String::from_utf8(line.into()).unwrap())
18 Ok(String::from_utf8(line.into()).unwrap())
19 } else {
19 } else {
20 Err(HgError::corrupted("parse error in 'requires' file"))
20 Err(HgError::corrupted("parse error in 'requires' file"))
21 }
21 }
22 })
22 })
23 .collect()
23 .collect()
24 }
24 }
25
25
26 pub(crate) fn load(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> {
26 pub(crate) fn load(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> {
27 parse(&hg_vfs.read("requires")?)
27 parse(&hg_vfs.read("requires")?)
28 }
28 }
29
29
30 pub(crate) fn load_if_exists(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> {
30 pub(crate) fn load_if_exists(hg_vfs: Vfs) -> Result<HashSet<String>, HgError> {
31 if let Some(bytes) = hg_vfs.read("requires").io_not_found_as_none()? {
31 if let Some(bytes) = hg_vfs.read("requires").io_not_found_as_none()? {
32 parse(&bytes)
32 parse(&bytes)
33 } else {
33 } else {
34 // Treat a missing file the same as an empty file.
34 // Treat a missing file the same as an empty file.
35 // From `mercurial/localrepo.py`:
35 // From `mercurial/localrepo.py`:
36 // > requires file contains a newline-delimited list of
36 // > requires file contains a newline-delimited list of
37 // > features/capabilities the opener (us) must have in order to use
37 // > features/capabilities the opener (us) must have in order to use
38 // > the repository. This file was introduced in Mercurial 0.9.2,
38 // > the repository. This file was introduced in Mercurial 0.9.2,
39 // > which means very old repositories may not have one. We assume
39 // > which means very old repositories may not have one. We assume
40 // > a missing file translates to no requirements.
40 // > a missing file translates to no requirements.
41 Ok(HashSet::new())
41 Ok(HashSet::new())
42 }
42 }
43 }
43 }
44
44
45 pub(crate) fn check(repo: &Repo) -> Result<(), HgError> {
45 pub(crate) fn check(repo: &Repo) -> Result<(), HgError> {
46 let unknown: Vec<_> = repo
46 let unknown: Vec<_> = repo
47 .requirements()
47 .requirements()
48 .iter()
48 .iter()
49 .map(String::as_str)
49 .map(String::as_str)
50 // .filter(|feature| !ALL_SUPPORTED.contains(feature.as_str()))
50 // .filter(|feature| !ALL_SUPPORTED.contains(feature.as_str()))
51 .filter(|feature| {
51 .filter(|feature| {
52 !REQUIRED.contains(feature) && !SUPPORTED.contains(feature)
52 !REQUIRED.contains(feature) && !SUPPORTED.contains(feature)
53 })
53 })
54 .collect();
54 .collect();
55 if !unknown.is_empty() {
55 if !unknown.is_empty() {
56 return Err(HgError::unsupported(format!(
56 return Err(HgError::unsupported(format!(
57 "repository requires feature unknown to this Mercurial: {}",
57 "repository requires feature unknown to this Mercurial: {}",
58 join_display(&unknown, ", ")
58 join_display(&unknown, ", ")
59 )));
59 )));
60 }
60 }
61 let missing: Vec<_> = REQUIRED
61 let missing: Vec<_> = REQUIRED
62 .iter()
62 .iter()
63 .filter(|&&feature| !repo.requirements().contains(feature))
63 .filter(|&&feature| !repo.requirements().contains(feature))
64 .collect();
64 .collect();
65 if !missing.is_empty() {
65 if !missing.is_empty() {
66 return Err(HgError::unsupported(format!(
66 return Err(HgError::unsupported(format!(
67 "repository is missing feature required by this Mercurial: {}",
67 "repository is missing feature required by this Mercurial: {}",
68 join_display(&missing, ", ")
68 join_display(&missing, ", ")
69 )));
69 )));
70 }
70 }
71 Ok(())
71 Ok(())
72 }
72 }
73
73
74 /// rhg does not support repositories that are *missing* any of these features
74 /// rhg does not support repositories that are *missing* any of these features
75 const REQUIRED: &[&str] = &["revlogv1", "store", "fncache", "dotencode"];
75 const REQUIRED: &[&str] = &["revlogv1", "store", "fncache", "dotencode"];
76
76
77 /// rhg supports repository with or without these
77 /// rhg supports repository with or without these
78 const SUPPORTED: &[&str] = &[
78 const SUPPORTED: &[&str] = &[
79 "generaldelta",
79 "generaldelta",
80 SHARED_REQUIREMENT,
80 SHARED_REQUIREMENT,
81 SHARESAFE_REQUIREMENT,
81 SHARESAFE_REQUIREMENT,
82 SPARSEREVLOG_REQUIREMENT,
82 SPARSEREVLOG_REQUIREMENT,
83 RELATIVE_SHARED_REQUIREMENT,
83 RELATIVE_SHARED_REQUIREMENT,
84 REVLOG_COMPRESSION_ZSTD,
84 // As of this writing everything rhg does is read-only.
85 // As of this writing everything rhg does is read-only.
85 // When it starts writing to the repository, it’ll need to either keep the
86 // When it starts writing to the repository, it’ll need to either keep the
86 // persistent nodemap up to date or remove this entry:
87 // persistent nodemap up to date or remove this entry:
87 NODEMAP_REQUIREMENT,
88 NODEMAP_REQUIREMENT,
88 ];
89 ];
89
90
90 // Copied from mercurial/requirements.py:
91 // Copied from mercurial/requirements.py:
91
92
92 /// When narrowing is finalized and no longer subject to format changes,
93 /// When narrowing is finalized and no longer subject to format changes,
93 /// we should move this to just "narrow" or similar.
94 /// we should move this to just "narrow" or similar.
94 #[allow(unused)]
95 #[allow(unused)]
95 pub(crate) const NARROW_REQUIREMENT: &str = "narrowhg-experimental";
96 pub(crate) const NARROW_REQUIREMENT: &str = "narrowhg-experimental";
96
97
97 /// Enables sparse working directory usage
98 /// Enables sparse working directory usage
98 #[allow(unused)]
99 #[allow(unused)]
99 pub(crate) const SPARSE_REQUIREMENT: &str = "exp-sparse";
100 pub(crate) const SPARSE_REQUIREMENT: &str = "exp-sparse";
100
101
101 /// Enables the internal phase which is used to hide changesets instead
102 /// Enables the internal phase which is used to hide changesets instead
102 /// of stripping them
103 /// of stripping them
103 #[allow(unused)]
104 #[allow(unused)]
104 pub(crate) const INTERNAL_PHASE_REQUIREMENT: &str = "internal-phase";
105 pub(crate) const INTERNAL_PHASE_REQUIREMENT: &str = "internal-phase";
105
106
106 /// Stores manifest in Tree structure
107 /// Stores manifest in Tree structure
107 #[allow(unused)]
108 #[allow(unused)]
108 pub(crate) const TREEMANIFEST_REQUIREMENT: &str = "treemanifest";
109 pub(crate) const TREEMANIFEST_REQUIREMENT: &str = "treemanifest";
109
110
110 /// Increment the sub-version when the revlog v2 format changes to lock out old
111 /// Increment the sub-version when the revlog v2 format changes to lock out old
111 /// clients.
112 /// clients.
112 #[allow(unused)]
113 #[allow(unused)]
113 pub(crate) const REVLOGV2_REQUIREMENT: &str = "exp-revlogv2.1";
114 pub(crate) const REVLOGV2_REQUIREMENT: &str = "exp-revlogv2.1";
114
115
115 /// A repository with the sparserevlog feature will have delta chains that
116 /// A repository with the sparserevlog feature will have delta chains that
116 /// can spread over a larger span. Sparse reading cuts these large spans into
117 /// can spread over a larger span. Sparse reading cuts these large spans into
117 /// pieces, so that each piece isn't too big.
118 /// pieces, so that each piece isn't too big.
118 /// Without the sparserevlog capability, reading from the repository could use
119 /// Without the sparserevlog capability, reading from the repository could use
119 /// huge amounts of memory, because the whole span would be read at once,
120 /// huge amounts of memory, because the whole span would be read at once,
120 /// including all the intermediate revisions that aren't pertinent for the
121 /// including all the intermediate revisions that aren't pertinent for the
121 /// chain. This is why once a repository has enabled sparse-read, it becomes
122 /// chain. This is why once a repository has enabled sparse-read, it becomes
122 /// required.
123 /// required.
123 #[allow(unused)]
124 #[allow(unused)]
124 pub(crate) const SPARSEREVLOG_REQUIREMENT: &str = "sparserevlog";
125 pub(crate) const SPARSEREVLOG_REQUIREMENT: &str = "sparserevlog";
125
126
126 /// A repository with the sidedataflag requirement will allow to store extra
127 /// A repository with the sidedataflag requirement will allow to store extra
127 /// information for revision without altering their original hashes.
128 /// information for revision without altering their original hashes.
128 #[allow(unused)]
129 #[allow(unused)]
129 pub(crate) const SIDEDATA_REQUIREMENT: &str = "exp-sidedata-flag";
130 pub(crate) const SIDEDATA_REQUIREMENT: &str = "exp-sidedata-flag";
130
131
131 /// A repository with the the copies-sidedata-changeset requirement will store
132 /// A repository with the the copies-sidedata-changeset requirement will store
132 /// copies related information in changeset's sidedata.
133 /// copies related information in changeset's sidedata.
133 #[allow(unused)]
134 #[allow(unused)]
134 pub(crate) const COPIESSDC_REQUIREMENT: &str = "exp-copies-sidedata-changeset";
135 pub(crate) const COPIESSDC_REQUIREMENT: &str = "exp-copies-sidedata-changeset";
135
136
136 /// The repository use persistent nodemap for the changelog and the manifest.
137 /// The repository use persistent nodemap for the changelog and the manifest.
137 #[allow(unused)]
138 #[allow(unused)]
138 pub(crate) const NODEMAP_REQUIREMENT: &str = "persistent-nodemap";
139 pub(crate) const NODEMAP_REQUIREMENT: &str = "persistent-nodemap";
139
140
140 /// Denotes that the current repository is a share
141 /// Denotes that the current repository is a share
141 #[allow(unused)]
142 #[allow(unused)]
142 pub(crate) const SHARED_REQUIREMENT: &str = "shared";
143 pub(crate) const SHARED_REQUIREMENT: &str = "shared";
143
144
144 /// Denotes that current repository is a share and the shared source path is
145 /// Denotes that current repository is a share and the shared source path is
145 /// relative to the current repository root path
146 /// relative to the current repository root path
146 #[allow(unused)]
147 #[allow(unused)]
147 pub(crate) const RELATIVE_SHARED_REQUIREMENT: &str = "relshared";
148 pub(crate) const RELATIVE_SHARED_REQUIREMENT: &str = "relshared";
148
149
149 /// A repository with share implemented safely. The repository has different
150 /// A repository with share implemented safely. The repository has different
150 /// store and working copy requirements i.e. both `.hg/requires` and
151 /// store and working copy requirements i.e. both `.hg/requires` and
151 /// `.hg/store/requires` are present.
152 /// `.hg/store/requires` are present.
152 #[allow(unused)]
153 #[allow(unused)]
153 pub(crate) const SHARESAFE_REQUIREMENT: &str = "share-safe";
154 pub(crate) const SHARESAFE_REQUIREMENT: &str = "share-safe";
155
156 /// A repository that use zstd compression inside its revlog
157 #[allow(unused)]
158 pub(crate) const REVLOG_COMPRESSION_ZSTD: &str = "revlog-compression-zstd";
General Comments 0
You need to be logged in to leave comments. Login now