Patchwork [2,of,5,STABLE,RFC] dispatch: convert non-list option parsed by _earlygetopt() to string

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 15, 2017, 12:54 p.m.
Message ID <d0f8a7dc0ed66fd66f6d.1510750461@mimosa>
Download mbox | patch
Permalink /patch/25579/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 15, 2017, 12:54 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1510390515 -32400
#      Sat Nov 11 17:55:15 2017 +0900
# Branch stable
# Node ID d0f8a7dc0ed66fd66f6df49a8ac6820dbc17c0ef
# Parent  169d9434332be406ab1ba83af4a5f9a29cca3823
dispatch: convert non-list option parsed by _earlygetopt() to string

So we can easily compare it with the corresponding getopt() result.

There's a minor behavior change. Before, "hg --cwd ''" failed with ENOENT.
But with this patch, an empty cwd is silently ignored. "hg -R ''" has always
worked as such, so -R has no BC.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -235,6 +235,7 @@  def _loadnewui(srcui, args):
     cwds = dispatch._earlygetopt(['--cwd'], args)
     cwd = cwds and os.path.realpath(cwds[-1]) or None
     rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args)
+    rpath = rpath and rpath[-1] or ''
     path, newlui = dispatch._getlocal(newui, rpath, wd=cwd)
 
     return (newui, newlui)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -787,8 +787,8 @@  def _getlocal(ui, rpath, wd=None):
         lui = ui.copy()
         lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
 
-    if rpath and rpath[-1]:
-        path = lui.expandpath(rpath[-1])
+    if rpath:
+        path = lui.expandpath(rpath)
         lui = ui.copy()
         lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
 
@@ -829,10 +829,12 @@  def _dispatch(req):
 
     # check for cwd
     cwd = _earlygetopt(['--cwd'], args)
+    cwd = cwd and cwd[-1] or ''
     if cwd:
-        os.chdir(cwd[-1])
+        os.chdir(cwd)
 
     rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
+    rpath = rpath and rpath[-1] or ''
     path, lui = _getlocal(ui, rpath)
 
     uis = {ui, lui}
@@ -971,7 +973,7 @@  def _dispatch(req):
                 except error.RequirementError:
                     raise
                 except error.RepoError:
-                    if rpath and rpath[-1]: # invalid -R path
+                    if rpath: # invalid -R path
                         raise
                     if not func.optionalrepo:
                         if func.inferrepo and args and not path: