annotate rust/hg-core/src/lib.rs @ 48750:94e36b230990

status: prefer relative paths in Rust code ? when the repository root is under the current directory, so the kernel needs to traverse fewer directory in every call to `read_dir` or `symlink_metadata`. Better yet would be to use libc functions like `openat` and `fstatat` to remove such repeated traversals entirely, but the standard library does not provide APIs based on those. Maybe with a crate like https://crates.io/crates/openat instead? Benchmarks of `rhg status` show that this patch is neutral in some configurations, and makes the command up to ~20% faster in others. Below is semi-arbitrary subset of results. The four numeric columns are: time (in seconds) with this changeset?s parent, time with this changeset, time difference (negative is better), time ratio (less than 1?is better). ``` mercurial-dirstate-v1 | default-plain-clean.no-iu.pbr | 0.0061 -> 0.0059: -0.0002 (0.97) mercurial-dirstate-v2 | default-plain-clean.no-iu.pbr | 0.0029 -> 0.0028: -0.0001 (0.97) mozilla-dirstate-v1 | default-plain-clean.no-iu.pbr | 0.2110 -> 0.2102: -0.0007 (1.00) mozilla-dirstate-v2 | default-copies-clean.ignored.pbr | 0.0489 -> 0.0401: -0.0088 (0.82) mozilla-dirstate-v2 | default-copies-clean.no-iu.pbr | 0.0479 -> 0.0393: -0.0085 (0.82) mozilla-dirstate-v2 | default-copies-large.all.pbr | 0.1262 -> 0.1210: -0.0051 (0.96) mozilla-dirstate-v2 | default-copies-small.ignored-unknown.pbr | 0.1262 -> 0.1200: -0.0062 (0.95) mozilla-dirstate-v2 | default-copies-small.ignored.pbr | 0.0536 -> 0.0417: -0.0119 (0.78) mozilla-dirstate-v2 | default-copies-small.no-iu.pbr | 0.0482 -> 0.0393: -0.0089 (0.81) mozilla-dirstate-v2 | default-plain-clean.ignored.pbr | 0.0518 -> 0.0402: -0.0116 (0.78) mozilla-dirstate-v2 | default-plain-clean.no-iu.pbr | 0.0481 -> 0.0392: -0.0088 (0.82) mozilla-dirstate-v2 | default-plain-large.all.pbr | 0.1271 -> 0.1218: -0.0052 (0.96) mozilla-dirstate-v2 | default-plain-small.ignored-unknown.pbr | 0.1225 -> 0.1202: -0.0022 (0.98) mozilla-dirstate-v2 | default-plain-small.ignored.pbr | 0.0510 -> 0.0418: -0.0092 (0.82) mozilla-dirstate-v2 | default-plain-small.no-iu.pbr | 0.0480 -> 0.0394: -0.0086 (0.82) netbeans-dirstate-v1 | default-plain-clean.no-iu.pbr | 0.1442 -> 0.1422: -0.0020 (0.99) netbeans-dirstate-v2 | default-plain-clean.no-iu.pbr | 0.0325 -> 0.0282: -0.0043 (0.87) ``` Differential Revision: https://phab.mercurial-scm.org/D12175
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 21 Jan 2022 17:54:03 +0100
parents 791f5d5f7a96
children 11c0411bf4e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44006
cb2e2b095dc9 rust-core: updated copyright notice
Georges Racinet <georges.racinet@octobus.net>
parents: 43922
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: 43922
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.
46511
43d63979a75e rust: use HgError in RevlogError and Vfs
Simon Sapin <simon.sapin@octobus.net>
parents: 46508
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;
46506
39e9407820ac rust: Introduce an `HgError` enum for common error cases
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
9 pub mod errors;
48557
791f5d5f7a96 hg-core: dedup LazyAncestors Iterator impl
pacien <pacien.trangirard@pacien.net>
parents: 48463
diff changeset
10 pub use ancestors::{AncestorsIterator, MissingAncestors};
47115
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47107
diff changeset
11 pub mod dirstate;
47107
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46799
diff changeset
12 pub mod dirstate_tree;
42216
10b465d61556 rust-discovery: starting core implementation
Georges Racinet <georges.racinet@octobus.net>
parents: 41728
diff changeset
13 pub mod discovery;
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47343
diff changeset
14 pub mod exit_codes;
45939
a2eda1ff22aa requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents: 45384
diff changeset
15 pub mod requirements;
42330
e240bec26626 rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42329
diff changeset
16 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: 42329
diff changeset
17 pub use dirstate::{
42891
a03a29462c0a rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents: 42818
diff changeset
18 dirs_multiset::{DirsMultiset, DirsMultisetIter},
44538
c8891bca40fb rust-status: add bare `hg status` support in hg-core
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44535
diff changeset
19 status::{
48083
bf8837e3d7ce dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents: 47980
diff changeset
20 BadMatch, BadType, DirstateStatus, HgPathCow, StatusError,
46799
bcdcb4423ae3 rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents: 46638
diff changeset
21 StatusOptions,
44538
c8891bca40fb rust-status: add bare `hg status` support in hg-core
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44535
diff changeset
22 },
48083
bf8837e3d7ce dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents: 47980
diff changeset
23 DirstateEntry, DirstateParents, EntryState,
42330
e240bec26626 rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42329
diff changeset
24 };
45959
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45939
diff changeset
25 pub mod copy_tracing;
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
26 mod filepatterns;
43490
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: 45959
diff changeset
28 pub mod repo;
44008
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents: 44006
diff changeset
29 pub mod revlog;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents: 44006
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;
48463
5734b03ecf3e rhg: Initial repository locking
Simon Sapin <simon.sapin@octobus.net>
parents: 48083
diff changeset
32 pub mod lock;
46638
1f55cd5b292f rust: Add a log file rotation utility
Simon Sapin <simon.sapin@octobus.net>
parents: 46512
diff changeset
33 pub mod logging;
44999
a46e36b82461 hg-core: add Operation interface for high-level hg operations
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44929
diff changeset
34 pub mod operations;
46501
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46441
diff changeset
35 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
36 pub mod utils;
47980
9cd35c8c6044 rust: Move VFS code to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47413
diff changeset
37 pub mod vfs;
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
38
44329
934a79697c36 rust-dirs-multiset: improve temporary error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44008
diff changeset
39 use crate::utils::hg_path::{HgPathBuf, HgPathError};
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
40 pub use filepatterns::{
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
41 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: 44329
diff changeset
42 PatternFileWarning, PatternSyntax,
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
43 };
43844
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43808
diff changeset
44 use std::collections::HashMap;
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
45 use std::fmt;
43844
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43808
diff changeset
46 use twox_hash::RandomXxHashBuilder64;
40271
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
47
44551
d880805d5442 hg-core: add function timing information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44538
diff changeset
48 /// 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: 44538
diff changeset
49 /// the `log` crate as `crate::log`.
d880805d5442 hg-core: add function timing information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44538
diff changeset
50 use log;
d880805d5442 hg-core: add function timing information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44538
diff changeset
51
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
52 pub type LineNumber = usize;
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
53
43844
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43808
diff changeset
54 /// 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: 43808
diff changeset
55 /// 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: 43808
diff changeset
56 /// 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: 43808
diff changeset
57 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: 43808
diff changeset
58
42329
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42216
diff changeset
59 #[derive(Debug, PartialEq)]
42543
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42453
diff changeset
60 pub enum DirstateMapError {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42892
diff changeset
61 PathNotFound(HgPathBuf),
42543
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42453
diff changeset
62 EmptyPath,
44329
934a79697c36 rust-dirs-multiset: improve temporary error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44008
diff changeset
63 InvalidPath(HgPathError),
43808
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43490
diff changeset
64 }
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43490
diff changeset
65
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
66 impl fmt::Display for DirstateMapError {
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
67 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43808
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43490
diff changeset
68 match self {
44329
934a79697c36 rust-dirs-multiset: improve temporary error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44008
diff changeset
69 DirstateMapError::PathNotFound(_) => {
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
70 f.write_str("expected a value, found none")
43808
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43490
diff changeset
71 }
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
72 DirstateMapError::EmptyPath => {
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
73 f.write_str("Overflow in dirstate.")
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
74 }
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
75 DirstateMapError::InvalidPath(path_error) => path_error.fmt(f),
43808
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43490
diff changeset
76 }
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43490
diff changeset
77 }
42543
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42453
diff changeset
78 }
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42453
diff changeset
79
46503
2e2033081274 rust: replace trivial `impl From ?` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46501
diff changeset
80 #[derive(Debug, derive_more::From)]
42765
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42764
diff changeset
81 pub enum DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42764
diff changeset
82 Map(DirstateMapError),
46507
68a15b5a7e58 rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents: 46506
diff changeset
83 Common(errors::HgError),
42765
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42764
diff changeset
84 }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42764
diff changeset
85
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
86 impl fmt::Display for DirstateError {
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
87 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: 47115
diff changeset
88 match self {
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
89 DirstateError::Map(error) => error.fmt(f),
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
90 DirstateError::Common(error) => error.fmt(f),
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
91 }
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
92 }
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
93 }
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
94
46503
2e2033081274 rust: replace trivial `impl From ?` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46501
diff changeset
95 #[derive(Debug, derive_more::From)]
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
96 pub enum PatternError {
46503
2e2033081274 rust: replace trivial `impl From ?` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46501
diff changeset
97 #[from]
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
98 Path(HgPathError),
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
99 UnsupportedSyntax(String),
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
100 UnsupportedSyntaxInFile(String, String, usize),
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
101 TooLong(usize),
46503
2e2033081274 rust: replace trivial `impl From ?` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents: 46501
diff changeset
102 #[from]
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
103 IO(std::io::Error),
44347
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44346
diff changeset
104 /// 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: 44346
diff changeset
105 /// 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: 44346
diff changeset
106 NonRegexPattern(IgnorePattern),
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
107 }
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
108
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
109 impl fmt::Display for PatternError {
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
110 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
111 match self {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
112 PatternError::UnsupportedSyntax(syntax) => {
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
113 write!(f, "Unsupported syntax {}", syntax)
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
114 }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
115 PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
116 write!(
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
117 f,
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
118 "{}:{}: unsupported syntax {}",
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
119 file_path, line, syntax
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
120 )
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
121 }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
122 PatternError::TooLong(size) => {
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
123 write!(f, "matcher pattern is too long ({} bytes)", size)
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
124 }
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
125 PatternError::IO(error) => error.fmt(f),
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
126 PatternError::Path(error) => error.fmt(f),
44347
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44346
diff changeset
127 PatternError::NonRegexPattern(pattern) => {
46512
6c778d20c8c2 rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents: 46511
diff changeset
128 write!(f, "'{:?}' cannot be turned into a regex", pattern)
44347
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44346
diff changeset
129 }
44346
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44329
diff changeset
130 }
42349
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
131 }
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42330
diff changeset
132 }