Show More
@@ -831,6 +831,7 b' dependencies = [' | |||||
831 | "env_logger", |
|
831 | "env_logger", | |
832 | "format-bytes", |
|
832 | "format-bytes", | |
833 | "hg-core", |
|
833 | "hg-core", | |
|
834 | "home", | |||
834 | "lazy_static", |
|
835 | "lazy_static", | |
835 | "log", |
|
836 | "log", | |
836 | "micro-timer", |
|
837 | "micro-timer", |
@@ -12,5 +12,5 b'' | |||||
12 | mod config; |
|
12 | mod config; | |
13 | mod layer; |
|
13 | mod layer; | |
14 | mod values; |
|
14 | mod values; | |
15 | pub use config::{Config, ConfigValueParseError}; |
|
15 | pub use config::{Config, ConfigSource, ConfigValueParseError}; | |
16 | pub use layer::{ConfigError, ConfigParseError}; |
|
16 | pub use layer::{ConfigError, ConfigParseError}; |
@@ -53,7 +53,7 b' impl Repo {' | |||||
53 | /// Having two methods would just move that `if` to almost all callers. |
|
53 | /// Having two methods would just move that `if` to almost all callers. | |
54 | pub fn find( |
|
54 | pub fn find( | |
55 | config: &Config, |
|
55 | config: &Config, | |
56 |
explicit_path: Option< |
|
56 | explicit_path: Option<PathBuf>, | |
57 | ) -> Result<Self, RepoError> { |
|
57 | ) -> Result<Self, RepoError> { | |
58 | if let Some(root) = explicit_path { |
|
58 | if let Some(root) = explicit_path { | |
59 | if root.join(".hg").is_dir() { |
|
59 | if root.join(".hg").is_dir() { |
@@ -12,6 +12,7 b' hg-core = { path = "../hg-core"}' | |||||
12 | chrono = "0.4.19" |
|
12 | chrono = "0.4.19" | |
13 | clap = "2.33.1" |
|
13 | clap = "2.33.1" | |
14 | derive_more = "0.99" |
|
14 | derive_more = "0.99" | |
|
15 | home = "0.5.3" | |||
15 | lazy_static = "1.4.0" |
|
16 | lazy_static = "1.4.0" | |
16 | log = "0.4.11" |
|
17 | log = "0.4.11" | |
17 | micro-timer = "0.3.1" |
|
18 | micro-timer = "0.3.1" |
@@ -5,7 +5,7 b' use clap::AppSettings;' | |||||
5 | use clap::Arg; |
|
5 | use clap::Arg; | |
6 | use clap::ArgMatches; |
|
6 | use clap::ArgMatches; | |
7 | use format_bytes::{format_bytes, join}; |
|
7 | use format_bytes::{format_bytes, join}; | |
8 | use hg::config::Config; |
|
8 | use hg::config::{Config, ConfigSource}; | |
9 | use hg::repo::{Repo, RepoError}; |
|
9 | use hg::repo::{Repo, RepoError}; | |
10 | use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes}; |
|
10 | use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes}; | |
11 | use hg::utils::SliceExt; |
|
11 | use hg::utils::SliceExt; | |
@@ -167,8 +167,74 b' fn main() {' | |||||
167 | ) |
|
167 | ) | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
let repo_ |
|
170 | let repo_arg = early_args.repo.unwrap_or(Vec::new()); | |
171 | let repo_result = match Repo::find(&non_repo_config, repo_path) { |
|
171 | let repo_path: Option<PathBuf> = { | |
|
172 | if repo_arg.is_empty() { | |||
|
173 | None | |||
|
174 | } else { | |||
|
175 | let local_config = { | |||
|
176 | if std::env::var_os("HGRCSKIPREPO").is_none() { | |||
|
177 | let current_dir = hg::utils::current_dir(); | |||
|
178 | // TODO: handle errors from current_dir | |||
|
179 | if let Ok(current_dir_path) = current_dir { | |||
|
180 | let config_files = vec![ | |||
|
181 | ConfigSource::AbsPath( | |||
|
182 | current_dir_path.join(".hg/hgrc"), | |||
|
183 | ), | |||
|
184 | ConfigSource::AbsPath( | |||
|
185 | current_dir_path.join(".hg/hgrc-not-shared"), | |||
|
186 | ), | |||
|
187 | ]; | |||
|
188 | // TODO: handle errors from | |||
|
189 | // `load_from_explicit_sources` | |||
|
190 | Config::load_from_explicit_sources(config_files).ok() | |||
|
191 | } else { | |||
|
192 | None | |||
|
193 | } | |||
|
194 | } else { | |||
|
195 | None | |||
|
196 | } | |||
|
197 | }; | |||
|
198 | ||||
|
199 | let non_repo_config_val = { | |||
|
200 | let non_repo_val = non_repo_config.get(b"paths", &repo_arg); | |||
|
201 | match &non_repo_val { | |||
|
202 | Some(val) if val.len() > 0 => home::home_dir() | |||
|
203 | .unwrap_or_else(|| PathBuf::from("~")) | |||
|
204 | .join(get_path_from_bytes(val)) | |||
|
205 | .canonicalize() | |||
|
206 | // TODO: handle error and make it similar to python | |||
|
207 | // implementation maybe? | |||
|
208 | .ok(), | |||
|
209 | _ => None, | |||
|
210 | } | |||
|
211 | }; | |||
|
212 | ||||
|
213 | let config_val = match &local_config { | |||
|
214 | None => non_repo_config_val, | |||
|
215 | Some(val) => { | |||
|
216 | let local_config_val = val.get(b"paths", &repo_arg); | |||
|
217 | match &local_config_val { | |||
|
218 | Some(val) if val.len() > 0 => { | |||
|
219 | // presence of a local_config assures that | |||
|
220 | // current_dir | |||
|
221 | // wont result in an Error | |||
|
222 | let canpath = hg::utils::current_dir() | |||
|
223 | .unwrap() | |||
|
224 | .join(get_path_from_bytes(val)) | |||
|
225 | .canonicalize(); | |||
|
226 | canpath.ok().or(non_repo_config_val) | |||
|
227 | } | |||
|
228 | _ => non_repo_config_val, | |||
|
229 | } | |||
|
230 | } | |||
|
231 | }; | |||
|
232 | config_val.or(Some(get_path_from_bytes(&repo_arg).to_path_buf())) | |||
|
233 | } | |||
|
234 | }; | |||
|
235 | ||||
|
236 | let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned()) | |||
|
237 | { | |||
172 | Ok(repo) => Ok(repo), |
|
238 | Ok(repo) => Ok(repo), | |
173 | Err(RepoError::NotFound { at }) if repo_path.is_none() => { |
|
239 | Err(RepoError::NotFound { at }) if repo_path.is_none() => { | |
174 | // Not finding a repo is not fatal yet, if `-R` was not given |
|
240 | // Not finding a repo is not fatal yet, if `-R` was not given |
@@ -65,8 +65,6 b' Testing -R/--repository:' | |||||
65 |
|
65 | |||
66 | -R with path aliases: |
|
66 | -R with path aliases: | |
67 |
|
67 | |||
68 | TODO: add rhg support for path aliases |
|
|||
69 | #if no-rhg |
|
|||
70 | $ cd c |
|
68 | $ cd c | |
71 | $ hg -R default identify |
|
69 | $ hg -R default identify | |
72 | 8580ff50825a tip |
|
70 | 8580ff50825a tip | |
@@ -81,7 +79,6 b' TODO: add rhg support for path aliases' | |||||
81 | $ HOME=`pwd`/../ hg -R relativetohome identify |
|
79 | $ HOME=`pwd`/../ hg -R relativetohome identify | |
82 | 8580ff50825a tip |
|
80 | 8580ff50825a tip | |
83 | $ cd .. |
|
81 | $ cd .. | |
84 | #endif |
|
|||
85 |
|
82 | |||
86 | #if no-outer-repo |
|
83 | #if no-outer-repo | |
87 |
|
84 |
General Comments 0
You need to be logged in to leave comments.
Login now