annotate rust/hg-core/src/lib.rs @ 46505:a25033eb43b5

rhg: add limited support for the `config` sub-command Only with one argument and no flag. This is mostly for testing. Differential Revision: https://phab.mercurial-scm.org/D9972
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Feb 2021 23:41:58 +0100
parents 6c778d20c8c2
children 1f55cd5b292f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44003
cb2e2b095dc9 rust-core: updated copyright notice
Georges Racinet <georges.racinet@octobus.net>
parents: 43916
diff changeset
1 // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net>
cb2e2b095dc9 rust-core: updated copyright notice
Georges Racinet <georges.racinet@octobus.net>
parents: 43916
diff changeset
2 // and Mercurial contributors
40271
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
3 //
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
4 // This software may be used and distributed according to the terms of the
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
5 // GNU General Public License version 2 or any later version.
46443
43d63979a75e rust: use HgError in RevlogError and Vfs
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
6
40271
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
7 mod ancestors;
41242
47881d2a9d99 rust: dagop.headrevs() Rust counterparts
Georges Racinet on ishtar.racinet.fr <georges@racinet.fr>
parents: 41241
diff changeset
8 pub mod dagops;
46438
39e9407820ac rust: Introduce an `HgError` enum for common error cases
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
9 pub mod errors;
41054
ef54bd33b476 rust: core implementation for lazyancestors
Georges Racinet <gracinet@anybox.fr>
parents: 40959
diff changeset
10 pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors};
42303
e240bec26626 rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents: 42302
diff changeset
11 mod dirstate;
42178
10b465d61556 rust-discovery: starting core implementation
Georges Racinet <georges.racinet@octobus.net>
parents: 41717
diff changeset
12 pub mod discovery;
45924
a2eda1ff22aa requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents: 45364
diff changeset
13 pub mod requirements;
42303
e240bec26626 rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents: 42302
diff changeset
14 pub mod testing; // unconditionally built, for use from integration tests
e240bec26626 rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents: 42302
diff changeset
15 pub use dirstate::{
42885
a03a29462c0a rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents: 42802
diff changeset
16 dirs_multiset::{DirsMultiset, DirsMultisetIter},
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents: 42749
diff changeset
17 dirstate_map::DirstateMap,
42748
7cae6bc29ff9 rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents: 42610
diff changeset
18 parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
44528
c8891bca40fb rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents: 44525
diff changeset
19 status::{
c8891bca40fb rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents: 44525
diff changeset
20 status, BadMatch, BadType, DirstateStatus, StatusError, StatusOptions,
c8891bca40fb rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents: 44525
diff changeset
21 },
42886
7083ac37314f rust-dirstate: provide CopyMapIter and StateMapIter types
Yuya Nishihara <yuya@tcha.org>
parents: 42885
diff changeset
22 CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
7083ac37314f rust-dirstate: provide CopyMapIter and StateMapIter types
Yuya Nishihara <yuya@tcha.org>
parents: 42885
diff changeset
23 StateMap, StateMapIter,
42303
e240bec26626 rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents: 42302
diff changeset
24 };
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45924
diff changeset
25 pub mod copy_tracing;
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
26 mod filepatterns;
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents: 43271
diff changeset
27 pub mod matchers;
46167
8a4914397d02 rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents: 45944
diff changeset
28 pub mod repo;
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents: 44003
diff changeset
29 pub mod revlog;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents: 44003
diff changeset
30 pub use revlog::*;
46187
95d6f31e88db hg-core: add basic config module
Raphaël Gomès <rgomes@octobus.net>
parents: 46167
diff changeset
31 pub mod config;
44974
a46e36b82461 hg-core: add Operation interface for high-level hg operations
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44870
diff changeset
32 pub mod operations;
46433
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46369
diff changeset
33 pub mod revset;
42610
5672bb73f61e rust-utils: add docstrings and doctests for utils.rs
Raphaël Gomès <rgomes@octobus.net>
parents: 42609
diff changeset
34 pub mod utils;
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
35
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
36 use crate::utils::hg_path::{HgPathBuf, HgPathError};
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
37 pub use filepatterns::{
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
38 parse_pattern_syntax, read_pattern_file, IgnorePattern,
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
39 PatternFileWarning, PatternSyntax,
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
40 };
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
41 use std::collections::HashMap;
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
42 use std::fmt;
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
43 use twox_hash::RandomXxHashBuilder64;
40271
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
44
44541
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
45 /// This is a contract between the `micro-timer` crate and us, to expose
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
46 /// the `log` crate as `crate::log`.
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
47 use log;
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
48
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
49 pub type LineNumber = usize;
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
50
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
51 /// Rust's default hasher is too slow because it tries to prevent collision
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
52 /// attacks. We are not concerned about those: if an ill-minded person has
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
53 /// write access to your repository, you have other issues.
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
54 pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>;
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
55
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
56 #[derive(Debug, PartialEq)]
42536
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
57 pub enum DirstateMapError {
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42886
diff changeset
58 PathNotFound(HgPathBuf),
42536
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
59 EmptyPath,
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
60 InvalidPath(HgPathError),
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
61 }
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
62
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
63 impl fmt::Display for DirstateMapError {
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
64 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
65 match self {
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
66 DirstateMapError::PathNotFound(_) => {
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
67 f.write_str("expected a value, found none")
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
68 }
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
69 DirstateMapError::EmptyPath => {
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
70 f.write_str("Overflow in dirstate.")
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
71 }
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
72 DirstateMapError::InvalidPath(path_error) => path_error.fmt(f),
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
73 }
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
74 }
42536
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
75 }
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
76
46435
2e2033081274 rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46433
diff changeset
77 #[derive(Debug, derive_more::From)]
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
78 pub enum DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
79 Map(DirstateMapError),
46439
68a15b5a7e58 rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents: 46438
diff changeset
80 Common(errors::HgError),
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
81 }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
82
46435
2e2033081274 rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46433
diff changeset
83 #[derive(Debug, derive_more::From)]
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
84 pub enum PatternError {
46435
2e2033081274 rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46433
diff changeset
85 #[from]
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
86 Path(HgPathError),
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
87 UnsupportedSyntax(String),
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
88 UnsupportedSyntaxInFile(String, String, usize),
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
89 TooLong(usize),
46435
2e2033081274 rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46433
diff changeset
90 #[from]
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
91 IO(std::io::Error),
44304
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
92 /// Needed a pattern that can be turned into a regex but got one that
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
93 /// can't. This should only happen through programmer error.
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
94 NonRegexPattern(IgnorePattern),
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
95 }
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
96
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
97 impl fmt::Display for PatternError {
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
98 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
99 match self {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
100 PatternError::UnsupportedSyntax(syntax) => {
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
101 write!(f, "Unsupported syntax {}", syntax)
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
102 }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
103 PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
104 write!(
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
105 f,
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
106 "{}:{}: unsupported syntax {}",
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
107 file_path, line, syntax
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
108 )
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
109 }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
110 PatternError::TooLong(size) => {
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
111 write!(f, "matcher pattern is too long ({} bytes)", size)
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
112 }
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
113 PatternError::IO(error) => error.fmt(f),
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
114 PatternError::Path(error) => error.fmt(f),
44304
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
115 PatternError::NonRegexPattern(pattern) => {
46444
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
116 write!(f, "'{:?}' cannot be turned into a regex", pattern)
44304
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
117 }
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
118 }
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
119 }
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
120 }