##// END OF EJS Templates
rust: run `cargo clippy`...
Raphaël Gomès -
r50809:58074252 default
parent child Browse files
Show More
@@ -55,12 +55,7 b' fn bench(index: &Index, nm: &NodeTree, q'
55 let len = index.len() as u32;
55 let len = index.len() as u32;
56 let mut rng = rand::thread_rng();
56 let mut rng = rand::thread_rng();
57 let nodes: Vec<Node> = (0..queries)
57 let nodes: Vec<Node> = (0..queries)
58 .map(|_| {
58 .map(|_| *index.node((rng.gen::<u32>() % len) as Revision).unwrap())
59 index
60 .node((rng.gen::<u32>() % len) as Revision)
61 .unwrap()
62 .clone()
63 })
64 .collect();
59 .collect();
65 if queries < 10 {
60 if queries < 10 {
66 let nodes_hex: Vec<String> =
61 let nodes_hex: Vec<String> =
@@ -125,7 +120,7 b' fn main() {'
125 nm_path.display(),
120 nm_path.display(),
126 repo.display()
121 repo.display()
127 );
122 );
128 create(&index, &Path::new(nm_path)).unwrap();
123 create(&index, Path::new(nm_path)).unwrap();
129 }
124 }
130 Command::Bench { queries } => {
125 Command::Bench { queries } => {
131 println!(
126 println!(
@@ -48,7 +48,7 b" impl Vfs<'_> {"
48 match self.read(relative_path) {
48 match self.read(relative_path) {
49 Err(e) => match &e {
49 Err(e) => match &e {
50 HgError::IoError { error, .. } => match error.kind() {
50 HgError::IoError { error, .. } => match error.kind() {
51 ErrorKind::NotFound => return Ok(None),
51 ErrorKind::NotFound => Ok(None),
52 _ => Err(e),
52 _ => Err(e),
53 },
53 },
54 _ => Err(e),
54 _ => Err(e),
@@ -38,7 +38,7 b' fn build_random_graph('
38 // p2 is a random revision lower than i and different from p1
38 // p2 is a random revision lower than i and different from p1
39 let mut p2 = rng.gen_range(0..i - 1) as Revision;
39 let mut p2 = rng.gen_range(0..i - 1) as Revision;
40 if p2 >= p1 {
40 if p2 >= p1 {
41 p2 = p2 + 1;
41 p2 += 1;
42 }
42 }
43 vg.push([p1, p2]);
43 vg.push([p1, p2]);
44 } else if rng.gen_bool(prevprob) {
44 } else if rng.gen_bool(prevprob) {
@@ -95,9 +95,9 b" impl<'a> NaiveMissingAncestors<'a> {"
95 random_seed: &str,
95 random_seed: &str,
96 ) -> Self {
96 ) -> Self {
97 Self {
97 Self {
98 ancestors_sets: ancestors_sets,
98 ancestors_sets,
99 bases: bases.clone(),
99 bases: bases.clone(),
100 graph: graph,
100 graph,
101 history: vec![MissingAncestorsAction::InitialBases(bases.clone())],
101 history: vec![MissingAncestorsAction::InitialBases(bases.clone())],
102 random_seed: random_seed.into(),
102 random_seed: random_seed.into(),
103 }
103 }
@@ -116,7 +116,7 b" impl<'a> NaiveMissingAncestors<'a> {"
116 for base in self.bases.iter().cloned() {
116 for base in self.bases.iter().cloned() {
117 if base != NULL_REVISION {
117 if base != NULL_REVISION {
118 for rev in &self.ancestors_sets[base as usize] {
118 for rev in &self.ancestors_sets[base as usize] {
119 revs.remove(&rev);
119 revs.remove(rev);
120 }
120 }
121 }
121 }
122 }
122 }
@@ -140,12 +140,12 b" impl<'a> NaiveMissingAncestors<'a> {"
140 for base in self.bases.iter().cloned() {
140 for base in self.bases.iter().cloned() {
141 if base != NULL_REVISION {
141 if base != NULL_REVISION {
142 for rev in &self.ancestors_sets[base as usize] {
142 for rev in &self.ancestors_sets[base as usize] {
143 missing.remove(&rev);
143 missing.remove(rev);
144 }
144 }
145 }
145 }
146 }
146 }
147 let mut res: Vec<Revision> = missing.iter().cloned().collect();
147 let mut res: Vec<Revision> = missing.iter().cloned().collect();
148 res.sort();
148 res.sort_unstable();
149 res
149 res
150 }
150 }
151
151
@@ -196,7 +196,7 b' fn sample_revs<R: RngCore>('
196 let nb = min(maxrev as usize, log_normal.sample(rng).floor() as usize);
196 let nb = min(maxrev as usize, log_normal.sample(rng).floor() as usize);
197
197
198 let dist = Uniform::from(NULL_REVISION..maxrev);
198 let dist = Uniform::from(NULL_REVISION..maxrev);
199 return rng.sample_iter(&dist).take(nb).collect();
199 rng.sample_iter(&dist).take(nb).collect()
200 }
200 }
201
201
202 /// Produces the hexadecimal representation of a slice of bytes
202 /// Produces the hexadecimal representation of a slice of bytes
@@ -98,7 +98,7 b' py_class!(pub class Dirs |py| {'
98
98
99 def __contains__(&self, item: PyObject) -> PyResult<bool> {
99 def __contains__(&self, item: PyObject) -> PyResult<bool> {
100 Ok(self.inner(py).borrow().contains(HgPath::new(
100 Ok(self.inner(py).borrow().contains(HgPath::new(
101 item.extract::<PyBytes>(py)?.data(py).as_ref(),
101 item.extract::<PyBytes>(py)?.data(py),
102 )))
102 )))
103 }
103 }
104 });
104 });
@@ -104,9 +104,7 b' py_class!(pub class DirstateMap |py| {'
104 let bytes = f.extract::<PyBytes>(py)?;
104 let bytes = f.extract::<PyBytes>(py)?;
105 let path = HgPath::new(bytes.data(py));
105 let path = HgPath::new(bytes.data(py));
106 let res = self.inner(py).borrow_mut().set_tracked(path);
106 let res = self.inner(py).borrow_mut().set_tracked(path);
107 let was_tracked = res.or_else(|_| {
107 let was_tracked = res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?;
108 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
109 })?;
110 Ok(was_tracked.to_py_object(py))
108 Ok(was_tracked.to_py_object(py))
111 }
109 }
112
110
@@ -114,9 +112,7 b' py_class!(pub class DirstateMap |py| {'
114 let bytes = f.extract::<PyBytes>(py)?;
112 let bytes = f.extract::<PyBytes>(py)?;
115 let path = HgPath::new(bytes.data(py));
113 let path = HgPath::new(bytes.data(py));
116 let res = self.inner(py).borrow_mut().set_untracked(path);
114 let res = self.inner(py).borrow_mut().set_untracked(path);
117 let was_tracked = res.or_else(|_| {
115 let was_tracked = res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?;
118 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
119 })?;
120 Ok(was_tracked.to_py_object(py))
116 Ok(was_tracked.to_py_object(py))
121 }
117 }
122
118
@@ -136,9 +132,7 b' py_class!(pub class DirstateMap |py| {'
136 let res = self.inner(py).borrow_mut().set_clean(
132 let res = self.inner(py).borrow_mut().set_clean(
137 path, mode, size, timestamp,
133 path, mode, size, timestamp,
138 );
134 );
139 res.or_else(|_| {
135 res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?;
140 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
141 })?;
142 Ok(PyNone)
136 Ok(PyNone)
143 }
137 }
144
138
@@ -146,9 +140,7 b' py_class!(pub class DirstateMap |py| {'
146 let bytes = f.extract::<PyBytes>(py)?;
140 let bytes = f.extract::<PyBytes>(py)?;
147 let path = HgPath::new(bytes.data(py));
141 let path = HgPath::new(bytes.data(py));
148 let res = self.inner(py).borrow_mut().set_possibly_dirty(path);
142 let res = self.inner(py).borrow_mut().set_possibly_dirty(path);
149 res.or_else(|_| {
143 res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?;
150 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
151 })?;
152 Ok(PyNone)
144 Ok(PyNone)
153 }
145 }
154
146
@@ -195,9 +187,7 b' py_class!(pub class DirstateMap |py| {'
195 has_meaningful_mtime,
187 has_meaningful_mtime,
196 parent_file_data,
188 parent_file_data,
197 );
189 );
198 res.or_else(|_| {
190 res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?;
199 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
200 })?;
201 Ok(PyNone)
191 Ok(PyNone)
202 }
192 }
203
193
@@ -40,7 +40,7 b' py_class!(pub class DirstateItem |py| {'
40 }
40 }
41 }
41 }
42 let entry = DirstateEntry::from_v2_data(DirstateV2Data {
42 let entry = DirstateEntry::from_v2_data(DirstateV2Data {
43 wc_tracked: wc_tracked,
43 wc_tracked,
44 p1_tracked,
44 p1_tracked,
45 p2_info,
45 p2_info,
46 mode_size: mode_size_opt,
46 mode_size: mode_size_opt,
@@ -72,12 +72,11 b' fn collect_bad_matches('
72 for (path, bad_match) in collection.iter() {
72 for (path, bad_match) in collection.iter() {
73 let message = match bad_match {
73 let message = match bad_match {
74 BadMatch::OsError(code) => get_error_message(*code)?,
74 BadMatch::OsError(code) => get_error_message(*code)?,
75 BadMatch::BadType(bad_type) => format!(
75 BadMatch::BadType(bad_type) => {
76 "unsupported file type (type is {})",
76 format!("unsupported file type (type is {})", bad_type)
77 bad_type.to_string()
77 .to_py_object(py)
78 )
78 .into_object()
79 .to_py_object(py)
79 }
80 .into_object(),
81 };
80 };
82 list.append(
81 list.append(
83 py,
82 py,
@@ -144,9 +144,9 b' py_class!(pub class MixedIndex |py| {'
144 // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]`
144 // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]`
145 self.cindex(py).borrow().inner().del_item(py, key)?;
145 self.cindex(py).borrow().inner().del_item(py, key)?;
146 let mut opt = self.get_nodetree(py)?.borrow_mut();
146 let mut opt = self.get_nodetree(py)?.borrow_mut();
147 let mut nt = opt.as_mut().unwrap();
147 let nt = opt.as_mut().unwrap();
148 nt.invalidate_all();
148 nt.invalidate_all();
149 self.fill_nodemap(py, &mut nt)?;
149 self.fill_nodemap(py, nt)?;
150 Ok(())
150 Ok(())
151 }
151 }
152
152
@@ -245,11 +245,8 b' pub struct ColorConfig {'
245 impl ColorConfig {
245 impl ColorConfig {
246 // Similar to _modesetup in mercurial/color.py
246 // Similar to _modesetup in mercurial/color.py
247 pub fn new(config: &Config) -> Result<Option<Self>, HgError> {
247 pub fn new(config: &Config) -> Result<Option<Self>, HgError> {
248 Ok(match ColorMode::get(config)? {
248 Ok(ColorMode::get(config)?.map(|ColorMode::Ansi| ColorConfig {
249 None => None,
249 styles: effects_from_config(config),
250 Some(ColorMode::Ansi) => Some(ColorConfig {
250 }))
251 styles: effects_from_config(config),
252 }),
253 })
254 }
251 }
255 }
252 }
@@ -95,7 +95,7 b' pub fn run(invocation: &crate::CliInvoca'
95 None => format!("{:x}", repo.dirstate_parents()?.p1),
95 None => format!("{:x}", repo.dirstate_parents()?.p1),
96 };
96 };
97
97
98 let output = cat(&repo, &rev, files).map_err(|e| (e, rev.as_str()))?;
98 let output = cat(repo, &rev, files).map_err(|e| (e, rev.as_str()))?;
99 for (_file, contents) in output.results {
99 for (_file, contents) in output.results {
100 invocation.ui.write_stdout(&contents)?;
100 invocation.ui.write_stdout(&contents)?;
101 }
101 }
@@ -23,10 +23,10 b' pub fn run(invocation: &crate::CliInvoca'
23
23
24 let (ignore_matcher, warnings) = get_ignore_matcher(
24 let (ignore_matcher, warnings) = get_ignore_matcher(
25 vec![ignore_file],
25 vec![ignore_file],
26 &repo.working_directory_path().to_owned(),
26 repo.working_directory_path(),
27 &mut |_source, _pattern_bytes| (),
27 &mut |_source, _pattern_bytes| (),
28 )
28 )
29 .map_err(|e| StatusError::from(e))?;
29 .map_err(StatusError::from)?;
30
30
31 if !warnings.is_empty() {
31 if !warnings.is_empty() {
32 warn!("Pattern warnings: {:?}", &warnings);
32 warn!("Pattern warnings: {:?}", &warnings);
@@ -24,7 +24,7 b' pub fn args() -> clap::Command {'
24 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
24 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
25 let repo = invocation.repo?;
25 let repo = invocation.repo?;
26
26
27 let (matcher, _warnings) = hg::sparse::matcher(&repo).unwrap();
27 let (matcher, _warnings) = hg::sparse::matcher(repo).unwrap();
28 let files = invocation.subcommand_args.get_many::<OsString>("files");
28 let files = invocation.subcommand_args.get_many::<OsString>("files");
29 if let Some(files) = files {
29 if let Some(files) = files {
30 let files: Vec<&OsStr> = files
30 let files: Vec<&OsStr> = files
@@ -169,7 +169,7 b' impl DisplayStates {'
169 }
169 }
170
170
171 fn has_unfinished_merge(repo: &Repo) -> Result<bool, CommandError> {
171 fn has_unfinished_merge(repo: &Repo) -> Result<bool, CommandError> {
172 return Ok(repo.dirstate_parents()?.is_merge());
172 Ok(repo.dirstate_parents()?.is_merge())
173 }
173 }
174
174
175 fn has_unfinished_state(repo: &Repo) -> Result<bool, CommandError> {
175 fn has_unfinished_state(repo: &Repo) -> Result<bool, CommandError> {
@@ -192,7 +192,7 b' fn has_unfinished_state(repo: &Repo) -> '
192 return Ok(true);
192 return Ok(true);
193 }
193 }
194 }
194 }
195 return Ok(false);
195 Ok(false)
196 }
196 }
197
197
198 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
198 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
@@ -244,12 +244,10 b' pub fn run(invocation: &crate::CliInvoca'
244
244
245 let repo = invocation.repo?;
245 let repo = invocation.repo?;
246
246
247 if verbose {
247 if verbose && has_unfinished_state(repo)? {
248 if has_unfinished_state(repo)? {
248 return Err(CommandError::unsupported(
249 return Err(CommandError::unsupported(
249 "verbose status output is not supported by rhg (and is needed because we're in an unfinished operation)",
250 "verbose status output is not supported by rhg (and is needed because we're in an unfinished operation)",
250 ));
251 ));
252 };
253 }
251 }
254
252
255 let mut dmap = repo.dirstate_map_mut()?;
253 let mut dmap = repo.dirstate_map_mut()?;
@@ -271,7 +269,7 b' pub fn run(invocation: &crate::CliInvoca'
271 let after_status = |res: StatusResult| -> Result<_, CommandError> {
269 let after_status = |res: StatusResult| -> Result<_, CommandError> {
272 let (mut ds_status, pattern_warnings) = res?;
270 let (mut ds_status, pattern_warnings) = res?;
273 for warning in pattern_warnings {
271 for warning in pattern_warnings {
274 ui.write_stderr(&print_pattern_file_warning(&warning, &repo))?;
272 ui.write_stderr(&print_pattern_file_warning(&warning, repo))?;
275 }
273 }
276
274
277 for (path, error) in ds_status.bad {
275 for (path, error) in ds_status.bad {
@@ -408,7 +406,7 b' pub fn run(invocation: &crate::CliInvoca'
408 ui.write_stderr(&msg)?;
406 ui.write_stderr(&msg)?;
409 }
407 }
410 sparse::SparseWarning::Pattern(e) => {
408 sparse::SparseWarning::Pattern(e) => {
411 ui.write_stderr(&print_pattern_file_warning(e, &repo))?;
409 ui.write_stderr(&print_pattern_file_warning(e, repo))?;
412 }
410 }
413 }
411 }
414 }
412 }
@@ -50,7 +50,7 b' impl CommandError {'
50 // of error messages to handle non-UTF-8 filenames etc:
50 // of error messages to handle non-UTF-8 filenames etc:
51 // https://www.mercurial-scm.org/wiki/EncodingStrategy#Mixing_output
51 // https://www.mercurial-scm.org/wiki/EncodingStrategy#Mixing_output
52 message: utf8_to_local(message.as_ref()).into(),
52 message: utf8_to_local(message.as_ref()).into(),
53 detailed_exit_code: detailed_exit_code,
53 detailed_exit_code,
54 hint: None,
54 hint: None,
55 }
55 }
56 }
56 }
@@ -69,7 +69,7 b' fn main_with_result('
69 .version("0.0.1");
69 .version("0.0.1");
70 let app = add_subcommand_args(app);
70 let app = add_subcommand_args(app);
71
71
72 let matches = app.clone().try_get_matches_from(argv.iter())?;
72 let matches = app.try_get_matches_from(argv.iter())?;
73
73
74 let (subcommand_name, subcommand_args) =
74 let (subcommand_name, subcommand_args) =
75 matches.subcommand().expect("subcommand required");
75 matches.subcommand().expect("subcommand required");
@@ -203,7 +203,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
203 // Same as `_matchscheme` in `mercurial/util.py`
203 // Same as `_matchscheme` in `mercurial/util.py`
204 regex::bytes::Regex::new("^[a-zA-Z0-9+.\\-]+:").unwrap();
204 regex::bytes::Regex::new("^[a-zA-Z0-9+.\\-]+:").unwrap();
205 }
205 }
206 if SCHEME_RE.is_match(&repo_path_bytes) {
206 if SCHEME_RE.is_match(repo_path_bytes) {
207 exit(
207 exit(
208 &argv,
208 &argv,
209 &initial_current_dir,
209 &initial_current_dir,
@@ -223,7 +223,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
223 )
223 )
224 }
224 }
225 }
225 }
226 let repo_arg = early_args.repo.unwrap_or(Vec::new());
226 let repo_arg = early_args.repo.unwrap_or_default();
227 let repo_path: Option<PathBuf> = {
227 let repo_path: Option<PathBuf> = {
228 if repo_arg.is_empty() {
228 if repo_arg.is_empty() {
229 None
229 None
@@ -254,7 +254,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
254 let non_repo_config_val = {
254 let non_repo_config_val = {
255 let non_repo_val = non_repo_config.get(b"paths", &repo_arg);
255 let non_repo_val = non_repo_config.get(b"paths", &repo_arg);
256 match &non_repo_val {
256 match &non_repo_val {
257 Some(val) if val.len() > 0 => home::home_dir()
257 Some(val) if !val.is_empty() => home::home_dir()
258 .unwrap_or_else(|| PathBuf::from("~"))
258 .unwrap_or_else(|| PathBuf::from("~"))
259 .join(get_path_from_bytes(val))
259 .join(get_path_from_bytes(val))
260 .canonicalize()
260 .canonicalize()
@@ -270,7 +270,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
270 Some(val) => {
270 Some(val) => {
271 let local_config_val = val.get(b"paths", &repo_arg);
271 let local_config_val = val.get(b"paths", &repo_arg);
272 match &local_config_val {
272 match &local_config_val {
273 Some(val) if val.len() > 0 => {
273 Some(val) if !val.is_empty() => {
274 // presence of a local_config assures that
274 // presence of a local_config assures that
275 // current_dir
275 // current_dir
276 // wont result in an Error
276 // wont result in an Error
@@ -304,7 +304,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
304 )
304 )
305 };
305 };
306 let early_exit = |config: &Config, error: CommandError| -> ! {
306 let early_exit = |config: &Config, error: CommandError| -> ! {
307 simple_exit(&Ui::new_infallible(config), &config, Err(error))
307 simple_exit(&Ui::new_infallible(config), config, Err(error))
308 };
308 };
309 let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned())
309 let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned())
310 {
310 {
@@ -328,13 +328,13 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
328 && config_cow
328 && config_cow
329 .as_ref()
329 .as_ref()
330 .get_bool(b"ui", b"tweakdefaults")
330 .get_bool(b"ui", b"tweakdefaults")
331 .unwrap_or_else(|error| early_exit(&config, error.into()))
331 .unwrap_or_else(|error| early_exit(config, error.into()))
332 {
332 {
333 config_cow.to_mut().tweakdefaults()
333 config_cow.to_mut().tweakdefaults()
334 };
334 };
335 let config = config_cow.as_ref();
335 let config = config_cow.as_ref();
336 let ui = Ui::new(&config)
336 let ui = Ui::new(config)
337 .unwrap_or_else(|error| early_exit(&config, error.into()));
337 .unwrap_or_else(|error| early_exit(config, error.into()));
338
338
339 if let Ok(true) = config.get_bool(b"rhg", b"fallback-immediately") {
339 if let Ok(true) = config.get_bool(b"rhg", b"fallback-immediately") {
340 exit(
340 exit(
@@ -360,7 +360,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {'
360 repo_result.as_ref(),
360 repo_result.as_ref(),
361 config,
361 config,
362 );
362 );
363 simple_exit(&ui, &config, result)
363 simple_exit(&ui, config, result)
364 }
364 }
365
365
366 fn main() -> ! {
366 fn main() -> ! {
@@ -422,7 +422,7 b" fn exit<'a>("
422 }
422 }
423 Some(executable) => executable,
423 Some(executable) => executable,
424 };
424 };
425 let executable_path = get_path_from_bytes(&executable);
425 let executable_path = get_path_from_bytes(executable);
426 let this_executable = args.next().expect("exepcted argv[0] to exist");
426 let this_executable = args.next().expect("exepcted argv[0] to exist");
427 if executable_path == &PathBuf::from(this_executable) {
427 if executable_path == &PathBuf::from(this_executable) {
428 // Avoid spawning infinitely many processes until resource
428 // Avoid spawning infinitely many processes until resource
@@ -23,7 +23,7 b' impl RelativizePaths {'
23 let repo_root = repo.working_directory_path();
23 let repo_root = repo.working_directory_path();
24 let repo_root = cwd.join(repo_root); // Make it absolute
24 let repo_root = cwd.join(repo_root); // Make it absolute
25 let repo_root_hgpath =
25 let repo_root_hgpath =
26 HgPathBuf::from(get_bytes_from_path(repo_root.to_owned()));
26 HgPathBuf::from(get_bytes_from_path(&repo_root));
27
27
28 if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(&repo_root) {
28 if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(&repo_root) {
29 // The current directory is inside the repo, so we can work with
29 // The current directory is inside the repo, so we can work with
General Comments 0
You need to be logged in to leave comments. Login now