Commit 5205c799 authored by Pulkit Goyal's avatar Pulkit Goyal
Browse files

rhg: read [paths] for `--repository` value

hg parses -R and --repository CLI arguments "early" in order to know which
local repository to load config from. (Config can then affect whether or how to
fall back.)

The value of of those arguments can be not only a filesystem path, but also an
alias configured in the [paths] section. This part was missing in rhg and this
patch implements that.

Differential Revision: https://phab.mercurial-scm.org/D10296
parent 651e6df2b0a4
Pipeline #20469 passed with stages
in 26 minutes and 50 seconds
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "0.2.3"
......@@ -846,6 +848,7 @@ dependencies = [
"env_logger",
"format-bytes",
"hg-core",
"home",
"lazy_static",
"log",
"micro-timer",
......
......@@ -12,5 +12,5 @@
mod config;
mod layer;
mod values;
pub use config::{Config, ConfigValueParseError};
pub use config::{Config, ConfigSource, ConfigValueParseError};
pub use layer::{ConfigError, ConfigParseError};
......@@ -53,7 +53,7 @@ impl Repo {
/// Having two methods would just move that `if` to almost all callers.
pub fn find(
config: &Config,
explicit_path: Option<&Path>,
explicit_path: Option<PathBuf>,
) -> Result<Self, RepoError> {
if let Some(root) = explicit_path {
if root.join(".hg").is_dir() {
......
......@@ -12,6 +12,7 @@ hg-core = { path = "../hg-core"}
chrono = "0.4.19"
clap = "2.33.1"
derive_more = "0.99"
home = "0.5.3"
lazy_static = "1.4.0"
log = "0.4.11"
micro-timer = "0.3.1"
......
......@@ -5,7 +5,7 @@ use clap::AppSettings;
use clap::Arg;
use clap::ArgMatches;
use format_bytes::{format_bytes, join};
use hg::config::Config;
use hg::config::{Config, ConfigSource};
use hg::repo::{Repo, RepoError};
use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes};
use hg::utils::SliceExt;
......@@ -167,8 +167,81 @@ fn main() {
)
}
}
let repo_path = early_args.repo.as_deref().map(get_path_from_bytes);
let repo_result = match Repo::find(&non_repo_config, repo_path) {
let repo_arg = early_args.repo.unwrap_or(Vec::new());
let repo_path: Option<PathBuf> = {
if repo_arg.len() == 0 {
None
} else {
let local_config = {
if std::env::var_os("HGRCSKIPREPO").is_none() {
let current_dir = hg::utils::current_dir();
if !current_dir.is_ok() {
None
} else {
let current_dir_path = current_dir.unwrap();
let config_files = vec![
ConfigSource::AbsPath(
current_dir_path.join(".hg/hgrc"),
),
ConfigSource::AbsPath(
current_dir_path.join(".hg/hgrc-not-shared"),
),
];
let config =
Config::load_from_explicit_sources(config_files);
if config.is_ok() {
Some(config.unwrap())
} else {
None
}
}
} else {
None
}
};
let non_repo_config_val = {
let non_repo_val = non_repo_config.get(b"paths", &repo_arg);
match &non_repo_val {
Some(val) if val.len() > 0 => Some(
home::home_dir()
.unwrap_or_else(|| PathBuf::from("~"))
.join(get_path_from_bytes(val))
.canonicalize()
.unwrap(),
),
_ => None,
}
};
let config_val = match &local_config {
None => non_repo_config_val,
Some(val) => {
let local_config_val = val.get(b"paths", &repo_arg);
match &local_config_val {
Some(val) if val.len() > 0 => Some(
// presence of a local_config assures that
// current_dir
// wont result in an Error
hg::utils::current_dir()
.unwrap()
.join(get_path_from_bytes(val))
.canonicalize()
.unwrap(),
),
_ => non_repo_config_val,
}
}
};
match config_val {
None => Some(get_path_from_bytes(&repo_arg).to_path_buf()),
Some(val) => Some(val),
}
}
};
let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned())
{
Ok(repo) => Ok(repo),
Err(RepoError::NotFound { at }) if repo_path.is_none() => {
// Not finding a repo is not fatal yet, if `-R` was not given
......
......@@ -65,8 +65,6 @@ Testing -R/--repository:
-R with path aliases:
TODO: add rhg support for path aliases
#if no-rhg
$ cd c
$ hg -R default identify
8580ff50825a tip
......@@ -77,7 +75,6 @@ TODO: add rhg support for path aliases
$ HOME=`pwd`/../ hg -R relativetohome identify
8580ff50825a tip
$ cd ..
#endif
#if no-outer-repo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment