Patchwork D11971: subrepo: make -S work again on Windows for incoming/outgoing to remote repos

login
register
mail settings
Submitter phabricator
Date Jan. 11, 2022, 4:51 a.m.
Message ID <differential-rev-PHID-DREV-jrd6uy44hlapeazhmcro-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50297/
State New
Headers show

Comments

phabricator - Jan. 11, 2022, 4:51 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  While it worked fine for the top level repo, the remote path for the subrepo got
  mangled to something like "https://server/prefix\repo\subrepo", which I've seen
  result in both a 400 and a 404, depending on the server.  We need to `normpath`
  at least the `subpath` because of "http://user:***@localhost:$HGPORT/main/../sub"
  in `test-subrepo-relative-path.t`.  Keep the `os.path` flavor for handling
  filesystem based remote repos, since this string is also displayed.
  
  This is one case where the automatic substitution of '\' for '/' and rematching
  done by the test runner is unfortunate- I don't see how to write a test to catch
  this.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/hg.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -10,6 +10,7 @@ 
 
 import errno
 import os
+import posixpath
 import shutil
 import stat
 import weakref
@@ -1292,7 +1293,11 @@ 
             source = bytes(subpath)
         else:
             p = urlutil.url(source)
-            p.path = os.path.normpath(b'%s/%s' % (p.path, subpath))
+            if p.islocal():
+                normpath = os.path.normpath
+            else:
+                normpath = posixpath.normpath
+            p.path = normpath(b'%s/%s' % (p.path, subpath))
             source = bytes(p)
     other = peer(repo, opts, source)
     cleanupfn = other.close
@@ -1363,7 +1368,11 @@ 
                 dest = bytes(subpath)
             else:
                 p = urlutil.url(dest)
-                p.path = os.path.normpath(b'%s/%s' % (p.path, subpath))
+                if p.islocal():
+                    normpath = os.path.normpath
+                else:
+                    normpath = posixpath.normpath
+                p.path = normpath(b'%s/%s' % (p.path, subpath))
                 dest = bytes(p)
         branches = path.branch, opts.get(b'branch') or []