rust/hg-core/src/lib.rs
author Yuya Nishihara <yuya@tcha.org>
Fri, 20 Mar 2020 17:18:14 +0900
changeset 44577 f8427841c8fc
parent 44562 ece43c79333e
parent 44476 df5dfee8cfb4
child 44870 9f96beb9bafe
permissions -rw-r--r--
merge with stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
     6
mod ancestors;
41242
47881d2a9d99 rust: dagop.headrevs() Rust counterparts
Georges Racinet on ishtar.racinet.fr <georges@racinet.fr>
parents: 41241
diff changeset
     7
pub mod dagops;
41054
ef54bd33b476 rust: core implementation for lazyancestors
Georges Racinet <gracinet@anybox.fr>
parents: 40959
diff changeset
     8
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
     9
mod dirstate;
42178
10b465d61556 rust-discovery: starting core implementation
Georges Racinet <georges.racinet@octobus.net>
parents: 41717
diff changeset
    10
pub mod discovery;
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
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
    12
pub use dirstate::{
42885
a03a29462c0a rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents: 42802
diff changeset
    13
    dirs_multiset::{DirsMultiset, DirsMultisetIter},
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents: 42749
diff changeset
    14
    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
    15
    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
    16
    status::{
c8891bca40fb rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents: 44525
diff changeset
    17
        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
    18
    },
42886
7083ac37314f rust-dirstate: provide CopyMapIter and StateMapIter types
Yuya Nishihara <yuya@tcha.org>
parents: 42885
diff changeset
    19
    CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
7083ac37314f rust-dirstate: provide CopyMapIter and StateMapIter types
Yuya Nishihara <yuya@tcha.org>
parents: 42885
diff changeset
    20
    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
    21
};
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
    22
mod filepatterns;
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents: 43271
diff changeset
    23
pub mod matchers;
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents: 44003
diff changeset
    24
pub mod revlog;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents: 44003
diff changeset
    25
pub use revlog::*;
44305
d8d4fa9a7f18 rust-re2: add wrapper for calling Re2 from Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 44304
diff changeset
    26
#[cfg(feature = "with-re2")]
d8d4fa9a7f18 rust-re2: add wrapper for calling Re2 from Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 44304
diff changeset
    27
pub mod re2;
42610
5672bb73f61e rust-utils: add docstrings and doctests for utils.rs
Raphaël Gomès <rgomes@octobus.net>
parents: 42609
diff changeset
    28
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
    29
44476
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    30
// Remove this to see (potential) non-artificial compile failures. MacOS
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    31
// *should* compile, but fail to compile tests for example as of 2020-03-06
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    32
#[cfg(not(target_os = "linux"))]
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    33
compile_error!(
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    34
    "`hg-core` has only been tested on Linux and will most \
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    35
     likely not behave correctly on other platforms."
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    36
);
df5dfee8cfb4 hg-core: add a compilation error if trying to compile outside of Linux
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    37
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    38
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
    39
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
    40
    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
    41
    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
    42
};
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
    43
use std::collections::HashMap;
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
    44
use twox_hash::RandomXxHashBuilder64;
40271
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    45
44541
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
    46
/// 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
    47
/// the `log` crate as `crate::log`.
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
    48
use log;
d880805d5442 hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents: 44528
diff changeset
    49
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
    50
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
    51
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
    52
/// 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
    53
/// 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
    54
/// 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
    55
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
    56
40271
dbc28c91f7ff rust: pure Rust lazyancestors iterator
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    57
#[derive(Clone, Debug, PartialEq)]
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    58
pub enum DirstateParseError {
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    59
    TooLittleData,
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    60
    Overflow,
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    61
    CorruptedEntry(String),
42748
7cae6bc29ff9 rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents: 42610
diff changeset
    62
    Damaged,
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    63
}
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    64
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    65
impl From<std::io::Error> for DirstateParseError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    66
    fn from(e: std::io::Error) -> Self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    67
        DirstateParseError::CorruptedEntry(e.to_string())
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    68
    }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    69
}
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    70
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    71
impl ToString for DirstateParseError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    72
    fn to_string(&self) -> String {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    73
        use crate::DirstateParseError::*;
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    74
        match self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    75
            TooLittleData => "Too little data for dirstate.".to_string(),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    76
            Overflow => "Overflow in dirstate.".to_string(),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    77
            CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    78
            Damaged => "Dirstate appears to be damaged.".to_string(),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    79
        }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    80
    }
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
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    83
#[derive(Debug, PartialEq)]
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    84
pub enum DirstatePackError {
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    85
    CorruptedEntry(String),
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    86
    CorruptedParent,
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    87
    BadSize(usize, usize),
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    88
}
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
    89
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    90
impl From<std::io::Error> for DirstatePackError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    91
    fn from(e: std::io::Error) -> Self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    92
        DirstatePackError::CorruptedEntry(e.to_string())
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    93
    }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
    94
}
42536
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
    95
#[derive(Debug, PartialEq)]
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
    96
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
    97
    PathNotFound(HgPathBuf),
42536
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
    98
    EmptyPath,
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
    99
    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
   100
}
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
   101
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
   102
impl ToString for DirstateMapError {
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
   103
    fn to_string(&self) -> String {
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
   104
        match self {
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
   105
            DirstateMapError::PathNotFound(_) => {
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
   106
                "expected a value, found none".to_string()
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
   107
            }
44283
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
   108
            DirstateMapError::EmptyPath => "Overflow in dirstate.".to_string(),
934a79697c36 rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents: 44005
diff changeset
   109
            DirstateMapError::InvalidPath(e) => e.to_string(),
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
   110
        }
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43438
diff changeset
   111
    }
42536
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
   112
}
2dcee6497b0b rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents: 42437
diff changeset
   113
44562
ece43c79333e rust-core: add missing `Debug` traits
Raphaël Gomès <rgomes@octobus.net>
parents: 44541
diff changeset
   114
#[derive(Debug)]
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   115
pub enum DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   116
    Parse(DirstateParseError),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   117
    Pack(DirstatePackError),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   118
    Map(DirstateMapError),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   119
    IO(std::io::Error),
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   120
}
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   121
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   122
impl From<DirstateParseError> for DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   123
    fn from(e: DirstateParseError) -> Self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   124
        DirstateError::Parse(e)
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
   125
    }
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
   126
}
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
   127
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   128
impl From<DirstatePackError> for DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   129
    fn from(e: DirstatePackError) -> Self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   130
        DirstateError::Pack(e)
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
   131
    }
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents: 42178
diff changeset
   132
}
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   133
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   134
#[derive(Debug)]
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   135
pub enum PatternError {
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   136
    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
   137
    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
   138
    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
   139
    TooLong(usize),
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   140
    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
   141
    /// 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
   142
    /// 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
   143
    NonRegexPattern(IgnorePattern),
44519
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   144
    /// This is temporary, see `re2/mod.rs`.
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   145
    /// This will cause a fallback to Python.
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   146
    Re2NotInstalled,
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   147
}
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   148
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   149
impl ToString for PatternError {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   150
    fn to_string(&self) -> String {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   151
        match self {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   152
            PatternError::UnsupportedSyntax(syntax) => {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   153
                format!("Unsupported syntax {}", syntax)
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   154
            }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   155
            PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   156
                format!(
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   157
                    "{}:{}: unsupported syntax {}",
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   158
                    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
   159
                )
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   160
            }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   161
            PatternError::TooLong(size) => {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   162
                format!("matcher pattern is too long ({} bytes)", size)
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   163
            }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   164
            PatternError::IO(e) => e.to_string(),
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   165
            PatternError::Path(e) => e.to_string(),
44304
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
   166
            PatternError::NonRegexPattern(pattern) => {
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
   167
                format!("'{:?}' cannot be turned into a regex", pattern)
2fe89bec8011 rust-filepatterns: add support for `include` and `subinclude` patterns
Raphaël Gomès <rgomes@octobus.net>
parents: 44303
diff changeset
   168
            }
44519
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   169
            PatternError::Re2NotInstalled => {
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   170
                "Re2 is not installed, cannot use regex functionality."
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   171
                    .to_string()
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents: 44305
diff changeset
   172
            }
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   173
        }
42327
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   174
    }
e8f3740cc067 rust-filepatterns: add a Rust implementation of pattern-related utils
Raphaël Gomès <rgomes@octobus.net>
parents: 42303
diff changeset
   175
}
42749
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   176
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   177
impl From<DirstateMapError> for DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   178
    fn from(e: DirstateMapError) -> Self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   179
        DirstateError::Map(e)
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   180
    }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   181
}
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   182
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   183
impl From<std::io::Error> for DirstateError {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   184
    fn from(e: std::io::Error) -> Self {
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   185
        DirstateError::IO(e)
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   186
    }
7ceded4419a3 rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents: 42748
diff changeset
   187
}
44303
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   188
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   189
impl From<std::io::Error> for PatternError {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   190
    fn from(e: std::io::Error) -> Self {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   191
        PatternError::IO(e)
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   192
    }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   193
}
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   194
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   195
impl From<HgPathError> for PatternError {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   196
    fn from(e: HgPathError) -> Self {
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   197
        PatternError::Path(e)
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   198
    }
d42eea9a0494 rust-filepatterns: improve API and robustness for pattern files parsing
Raphaël Gomès <rgomes@octobus.net>
parents: 44283
diff changeset
   199
}