Mercurial > hg
annotate rust/hg-core/src/lib.rs @ 52255:65d516db7309
branching: merge stable into default
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 14 Nov 2024 16:45:23 +0100 |
parents | bd8081e9fd62 96b113d22b34 |
children | db065b33fa56 |
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; |
49489
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
10 pub mod narrow; |
49485
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
48950
diff
changeset
|
11 pub mod sparse; |
48520
791f5d5f7a96
hg-core: dedup LazyAncestors Iterator impl
pacien <pacien.trangirard@pacien.net>
parents:
48417
diff
changeset
|
12 pub use ancestors::{AncestorsIterator, MissingAncestors}; |
47101
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
13 pub mod dirstate; |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46797
diff
changeset
|
14 pub mod dirstate_tree; |
42178
10b465d61556
rust-discovery: starting core implementation
Georges Racinet <georges.racinet@octobus.net>
parents:
41717
diff
changeset
|
15 pub mod discovery; |
47407
6e49769b7f97
rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47335
diff
changeset
|
16 pub mod exit_codes; |
52170
1a8466fd904a
hg-core: add fncache module
Raphaël Gomès <rgomes@octobus.net>
parents:
52164
diff
changeset
|
17 pub mod fncache; |
45924
a2eda1ff22aa
requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents:
45364
diff
changeset
|
18 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
|
19 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
|
20 pub use dirstate::{ |
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
21 dirs_multiset::{DirsMultiset, DirsMultisetIter}, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
22 status::{ |
48068
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
47952
diff
changeset
|
23 BadMatch, BadType, DirstateStatus, HgPathCow, StatusError, |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46599
diff
changeset
|
24 StatusOptions, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
25 }, |
48068
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
47952
diff
changeset
|
26 DirstateEntry, DirstateParents, EntryState, |
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
|
27 }; |
45944
595979dc924e
copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45924
diff
changeset
|
28 pub mod copy_tracing; |
50866
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
50860
diff
changeset
|
29 pub mod filepatterns; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43271
diff
changeset
|
30 pub mod matchers; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
45944
diff
changeset
|
31 pub mod repo; |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
32 pub mod revlog; |
52182
bd8081e9fd62
rust: don't star export from the `revlog` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52170
diff
changeset
|
33 // Export very common types to make discovery easier |
bd8081e9fd62
rust: don't star export from the `revlog` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52170
diff
changeset
|
34 pub use revlog::{ |
bd8081e9fd62
rust: don't star export from the `revlog` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52170
diff
changeset
|
35 BaseRevision, Graph, GraphError, Node, NodePrefix, Revision, |
bd8081e9fd62
rust: don't star export from the `revlog` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52170
diff
changeset
|
36 UncheckedRevision, NULL_NODE, NULL_NODE_ID, NULL_REVISION, |
bd8081e9fd62
rust: don't star export from the `revlog` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52170
diff
changeset
|
37 WORKING_DIRECTORY_HEX, WORKING_DIRECTORY_REVISION, |
bd8081e9fd62
rust: don't star export from the `revlog` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52170
diff
changeset
|
38 }; |
49894
678588b01af1
rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
39 pub mod checkexec; |
46187
95d6f31e88db
hg-core: add basic config module
Raphaël Gomès <rgomes@octobus.net>
parents:
46167
diff
changeset
|
40 pub mod config; |
48417
5734b03ecf3e
rhg: Initial repository locking
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
41 pub mod lock; |
46599
1f55cd5b292f
rust: Add a log file rotation utility
Simon Sapin <simon.sapin@octobus.net>
parents:
46444
diff
changeset
|
42 pub mod logging; |
44974
a46e36b82461
hg-core: add Operation interface for high-level hg operations
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44870
diff
changeset
|
43 pub mod operations; |
52041
3ae7c43ad8aa
rust: add `Progress` trait for progress bars
Raphaël Gomès <rgomes@octobus.net>
parents:
51605
diff
changeset
|
44 pub mod progress; |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46369
diff
changeset
|
45 pub mod revset; |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
46 pub mod transaction; |
52060
8b7123c8947b
update: add a Rust fast-path when updating from null (and clean)
Raphaël Gomès <rgomes@octobus.net>
parents:
52041
diff
changeset
|
47 pub mod update; |
42610
5672bb73f61e
rust-utils: add docstrings and doctests for utils.rs
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
48 pub mod utils; |
47952
9cd35c8c6044
rust: Move VFS code to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
47407
diff
changeset
|
49 pub mod vfs; |
42327
e8f3740cc067
rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents:
42303
diff
changeset
|
50 |
44283
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44005
diff
changeset
|
51 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
|
52 pub use filepatterns::{ |
51605
e4b9f8a74d5f
match: simplify the rust-side file pattern kind parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50866
diff
changeset
|
53 parse_pattern_syntax_kind, read_pattern_file, IgnorePattern, |
44303
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
54 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
|
55 }; |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
56 use std::fmt; |
52217
96b113d22b34
rust-update: handle SIGINT from long-running update threads
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
57 use std::{collections::HashMap, sync::atomic::AtomicBool}; |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
58 use twox_hash::RandomXxHashBuilder64; |
40271
dbc28c91f7ff
rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
59 |
52217
96b113d22b34
rust-update: handle SIGINT from long-running update threads
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
60 /// Used to communicate with threads spawned from code within this crate that |
96b113d22b34
rust-update: handle SIGINT from long-running update threads
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
61 /// they should stop their work (SIGINT was received). |
96b113d22b34
rust-update: handle SIGINT from long-running update threads
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
62 pub static INTERRUPT_RECEIVED: AtomicBool = AtomicBool::new(false); |
96b113d22b34
rust-update: handle SIGINT from long-running update threads
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
63 |
42327
e8f3740cc067
rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents:
42303
diff
changeset
|
64 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
|
65 |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
66 /// 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
|
67 /// 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
|
68 /// 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
|
69 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
|
70 |
48950
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48520
diff
changeset
|
71 // TODO: should this be the default `FastHashMap` for all of hg-core, not just |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48520
diff
changeset
|
72 // dirstate_tree? How does XxHash compare with AHash, hashbrown’s default? |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48520
diff
changeset
|
73 pub type FastHashbrownMap<K, V> = |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48520
diff
changeset
|
74 hashbrown::HashMap<K, V, RandomXxHashBuilder64>; |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48520
diff
changeset
|
75 |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
42178
diff
changeset
|
76 #[derive(Debug, PartialEq)] |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42437
diff
changeset
|
77 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
|
78 PathNotFound(HgPathBuf), |
44283
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44005
diff
changeset
|
79 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
|
80 } |
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
81 |
50860
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
82 impl From<HgPathError> for DirstateMapError { |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
83 fn from(error: HgPathError) -> Self { |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
84 Self::InvalidPath(error) |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
85 } |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
86 } |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
87 |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
88 impl fmt::Display for DirstateMapError { |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
89 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
|
90 match self { |
44283
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44005
diff
changeset
|
91 DirstateMapError::PathNotFound(_) => { |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
92 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
|
93 } |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
94 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
|
95 } |
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
96 } |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42437
diff
changeset
|
97 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42437
diff
changeset
|
98 |
46435
2e2033081274
rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
99 #[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
|
100 pub enum DirstateError { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
101 Map(DirstateMapError), |
46439
68a15b5a7e58
rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents:
46438
diff
changeset
|
102 Common(errors::HgError), |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
103 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
104 |
50860
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
105 impl From<HgPathError> for DirstateError { |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
106 fn from(error: HgPathError) -> Self { |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
107 Self::Map(DirstateMapError::InvalidPath(error)) |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
108 } |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
109 } |
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50535
diff
changeset
|
110 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
111 impl fmt::Display for DirstateError { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
112 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
113 match self { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
114 DirstateError::Map(error) => error.fmt(f), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
115 DirstateError::Common(error) => error.fmt(f), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
116 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
117 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
118 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
119 |
46435
2e2033081274
rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
120 #[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
|
121 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
|
122 #[from] |
44303
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 TooLong(usize), |
46435
2e2033081274
rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
127 #[from] |
44303
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
128 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
|
129 /// 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
|
130 /// 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
|
131 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
|
132 } |
e8f3740cc067
rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents:
42303
diff
changeset
|
133 |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
134 impl fmt::Display for PatternError { |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
135 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
|
136 match self { |
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
137 PatternError::UnsupportedSyntax(syntax) => { |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
138 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
|
139 } |
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
140 PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => { |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
141 write!( |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
142 f, |
44303
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
143 "{}:{}: unsupported syntax {}", |
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
144 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
|
145 ) |
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
146 } |
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
147 PatternError::TooLong(size) => { |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
148 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
|
149 } |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
150 PatternError::IO(error) => error.fmt(f), |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
151 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
|
152 PatternError::NonRegexPattern(pattern) => { |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
153 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
|
154 } |
44303
d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
155 } |
42327
e8f3740cc067
rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents:
42303
diff
changeset
|
156 } |
e8f3740cc067
rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents:
42303
diff
changeset
|
157 } |