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