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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

marmoute (Pierre-Yves David)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.
 
  The `#if no-rhg` is still not removed completely as those two `[paths]` are read
  from `.hg/hgrc` of directory in which the command is running. That will be
  implemented in the next patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10296

AFFECTED FILES
  rust/rhg/src/main.rs
  tests/test-globalopts.t

CHANGE DETAILS

diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t
--- a/tests/test-globalopts.t
+++ b/tests/test-globalopts.t
@@ -65,19 +65,19 @@
 
 -R with path aliases:
 
+  $ cd c
 TODO: add rhg support for path aliases
 #if no-rhg
-  $ cd c
   $ hg -R default identify
   8580ff50825a tip
   $ hg -R relative identify
   8580ff50825a tip
+#endif
   $ echo '[paths]' >> $HGRCPATH
   $ echo 'relativetohome = a' >> $HGRCPATH
   $ HOME=`pwd`/../ hg -R relativetohome identify
   8580ff50825a tip
   $ cd ..
-#endif
 
 #if no-outer-repo
 
diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -167,7 +167,29 @@
             )
         }
     }
-    let repo_path = early_args.repo.as_deref().map(get_path_from_bytes);
+    let repo_arg = early_args.repo.unwrap_or(Vec::new());
+    let repo_path = {
+        if repo_arg.len() == 0 {
+            None
+        } else {
+            let config_val = non_repo_config.get_str(b"paths", &(repo_arg));
+            if config_val.is_ok() {
+                let val = config_val.unwrap();
+                if !val.is_none() {
+                    let real_val = val.unwrap();
+                    if real_val.len() > 0 {
+                        Some(get_path_from_bytes(val.unwrap().as_bytes()))
+                    } else {
+                        Some(get_path_from_bytes(&repo_arg))
+                    }
+                } else {
+                    Some(get_path_from_bytes(&repo_arg))
+                }
+            } else {
+                Some(get_path_from_bytes(&repo_arg))
+            }
+        }
+    };
     let repo_result = match Repo::find(&non_repo_config, repo_path) {
         Ok(repo) => Ok(repo),
         Err(RepoError::NotFound { at }) if repo_path.is_none() => {



To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel