Show More
@@ -0,0 +1,11 | |||
|
1 | //! Progress-bar related things | |
|
2 | ||
|
3 | /// A generic determinate progress bar trait | |
|
4 | pub trait Progress: Send + Sync + 'static { | |
|
5 | /// Set the current position and optionally the total | |
|
6 | fn update(&self, pos: u64, total: Option<u64>); | |
|
7 | /// Increment the current position and optionally the total | |
|
8 | fn increment(&self, step: u64, total: Option<u64>); | |
|
9 | /// Declare that progress is over and the progress bar should be deleted | |
|
10 | fn complete(self); | |
|
11 | } |
@@ -1,144 +1,145 | |||
|
1 | 1 | // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net> |
|
2 | 2 | // and Mercurial contributors |
|
3 | 3 | // |
|
4 | 4 | // This software may be used and distributed according to the terms of the |
|
5 | 5 | // GNU General Public License version 2 or any later version. |
|
6 | 6 | |
|
7 | 7 | mod ancestors; |
|
8 | 8 | pub mod dagops; |
|
9 | 9 | pub mod errors; |
|
10 | 10 | pub mod narrow; |
|
11 | 11 | pub mod sparse; |
|
12 | 12 | pub use ancestors::{AncestorsIterator, MissingAncestors}; |
|
13 | 13 | pub mod dirstate; |
|
14 | 14 | pub mod dirstate_tree; |
|
15 | 15 | pub mod discovery; |
|
16 | 16 | pub mod exit_codes; |
|
17 | 17 | pub mod requirements; |
|
18 | 18 | pub mod testing; // unconditionally built, for use from integration tests |
|
19 | 19 | pub use dirstate::{ |
|
20 | 20 | dirs_multiset::{DirsMultiset, DirsMultisetIter}, |
|
21 | 21 | status::{ |
|
22 | 22 | BadMatch, BadType, DirstateStatus, HgPathCow, StatusError, |
|
23 | 23 | StatusOptions, |
|
24 | 24 | }, |
|
25 | 25 | DirstateEntry, DirstateParents, EntryState, |
|
26 | 26 | }; |
|
27 | 27 | pub mod copy_tracing; |
|
28 | 28 | pub mod filepatterns; |
|
29 | 29 | pub mod matchers; |
|
30 | 30 | pub mod repo; |
|
31 | 31 | pub mod revlog; |
|
32 | 32 | pub use revlog::*; |
|
33 | 33 | pub mod checkexec; |
|
34 | 34 | pub mod config; |
|
35 | 35 | pub mod lock; |
|
36 | 36 | pub mod logging; |
|
37 | 37 | pub mod operations; |
|
38 | pub mod progress; | |
|
38 | 39 | pub mod revset; |
|
39 | 40 | pub mod utils; |
|
40 | 41 | pub mod vfs; |
|
41 | 42 | |
|
42 | 43 | use crate::utils::hg_path::{HgPathBuf, HgPathError}; |
|
43 | 44 | pub use filepatterns::{ |
|
44 | 45 | parse_pattern_syntax_kind, read_pattern_file, IgnorePattern, |
|
45 | 46 | PatternFileWarning, PatternSyntax, |
|
46 | 47 | }; |
|
47 | 48 | use std::collections::HashMap; |
|
48 | 49 | use std::fmt; |
|
49 | 50 | use twox_hash::RandomXxHashBuilder64; |
|
50 | 51 | |
|
51 | 52 | pub type LineNumber = usize; |
|
52 | 53 | |
|
53 | 54 | /// Rust's default hasher is too slow because it tries to prevent collision |
|
54 | 55 | /// attacks. We are not concerned about those: if an ill-minded person has |
|
55 | 56 | /// write access to your repository, you have other issues. |
|
56 | 57 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; |
|
57 | 58 | |
|
58 | 59 | // TODO: should this be the default `FastHashMap` for all of hg-core, not just |
|
59 | 60 | // dirstate_tree? How does XxHash compare with AHash, hashbrown’s default? |
|
60 | 61 | pub type FastHashbrownMap<K, V> = |
|
61 | 62 | hashbrown::HashMap<K, V, RandomXxHashBuilder64>; |
|
62 | 63 | |
|
63 | 64 | #[derive(Debug, PartialEq)] |
|
64 | 65 | pub enum DirstateMapError { |
|
65 | 66 | PathNotFound(HgPathBuf), |
|
66 | 67 | InvalidPath(HgPathError), |
|
67 | 68 | } |
|
68 | 69 | |
|
69 | 70 | impl From<HgPathError> for DirstateMapError { |
|
70 | 71 | fn from(error: HgPathError) -> Self { |
|
71 | 72 | Self::InvalidPath(error) |
|
72 | 73 | } |
|
73 | 74 | } |
|
74 | 75 | |
|
75 | 76 | impl fmt::Display for DirstateMapError { |
|
76 | 77 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
77 | 78 | match self { |
|
78 | 79 | DirstateMapError::PathNotFound(_) => { |
|
79 | 80 | f.write_str("expected a value, found none") |
|
80 | 81 | } |
|
81 | 82 | DirstateMapError::InvalidPath(path_error) => path_error.fmt(f), |
|
82 | 83 | } |
|
83 | 84 | } |
|
84 | 85 | } |
|
85 | 86 | |
|
86 | 87 | #[derive(Debug, derive_more::From)] |
|
87 | 88 | pub enum DirstateError { |
|
88 | 89 | Map(DirstateMapError), |
|
89 | 90 | Common(errors::HgError), |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | impl From<HgPathError> for DirstateError { |
|
93 | 94 | fn from(error: HgPathError) -> Self { |
|
94 | 95 | Self::Map(DirstateMapError::InvalidPath(error)) |
|
95 | 96 | } |
|
96 | 97 | } |
|
97 | 98 | |
|
98 | 99 | impl fmt::Display for DirstateError { |
|
99 | 100 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
100 | 101 | match self { |
|
101 | 102 | DirstateError::Map(error) => error.fmt(f), |
|
102 | 103 | DirstateError::Common(error) => error.fmt(f), |
|
103 | 104 | } |
|
104 | 105 | } |
|
105 | 106 | } |
|
106 | 107 | |
|
107 | 108 | #[derive(Debug, derive_more::From)] |
|
108 | 109 | pub enum PatternError { |
|
109 | 110 | #[from] |
|
110 | 111 | Path(HgPathError), |
|
111 | 112 | UnsupportedSyntax(String), |
|
112 | 113 | UnsupportedSyntaxInFile(String, String, usize), |
|
113 | 114 | TooLong(usize), |
|
114 | 115 | #[from] |
|
115 | 116 | IO(std::io::Error), |
|
116 | 117 | /// Needed a pattern that can be turned into a regex but got one that |
|
117 | 118 | /// can't. This should only happen through programmer error. |
|
118 | 119 | NonRegexPattern(IgnorePattern), |
|
119 | 120 | } |
|
120 | 121 | |
|
121 | 122 | impl fmt::Display for PatternError { |
|
122 | 123 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
123 | 124 | match self { |
|
124 | 125 | PatternError::UnsupportedSyntax(syntax) => { |
|
125 | 126 | write!(f, "Unsupported syntax {}", syntax) |
|
126 | 127 | } |
|
127 | 128 | PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => { |
|
128 | 129 | write!( |
|
129 | 130 | f, |
|
130 | 131 | "{}:{}: unsupported syntax {}", |
|
131 | 132 | file_path, line, syntax |
|
132 | 133 | ) |
|
133 | 134 | } |
|
134 | 135 | PatternError::TooLong(size) => { |
|
135 | 136 | write!(f, "matcher pattern is too long ({} bytes)", size) |
|
136 | 137 | } |
|
137 | 138 | PatternError::IO(error) => error.fmt(f), |
|
138 | 139 | PatternError::Path(error) => error.fmt(f), |
|
139 | 140 | PatternError::NonRegexPattern(pattern) => { |
|
140 | 141 | write!(f, "'{:?}' cannot be turned into a regex", pattern) |
|
141 | 142 | } |
|
142 | 143 | } |
|
143 | 144 | } |
|
144 | 145 | } |
General Comments 0
You need to be logged in to leave comments.
Login now