logexchange: introduce helper function to get remote path name
This patch moves chunk of activepath function from hgremotenames extension
(https://bitbucket.org/seanfarley/hgremotenames/) to core. Before moving
rest of the part, there needs to be some refactoring done to schemes which
will be done as a separate series.
Differential Revision: https://phab.mercurial-scm.org/D1755
--- a/mercurial/logexchange.py Mon Feb 12 10:36:59 2018 -0500
+++ b/mercurial/logexchange.py Sat Dec 23 20:27:41 2017 +0530
@@ -11,6 +11,7 @@
from .node import hex
from . import (
+ util,
vfs as vfsmod,
)
@@ -94,6 +95,30 @@
finally:
wlock.release()
+def activepath(repo, remote):
+ """returns remote path"""
+ local = None
+ # is the remote a local peer
+ local = remote.local()
+
+ # determine the remote path from the repo, if possible; else just
+ # use the string given to us
+ rpath = remote
+ if local:
+ rpath = remote._repo.root
+ elif not isinstance(remote, str):
+ rpath = remote._url
+
+ # represent the remotepath with user defined path name if exists
+ for path, url in repo.ui.configitems('paths'):
+ # remove auth info from user defined url
+ url = util.removeauth(url)
+ if url == rpath:
+ rpath = path
+ break
+
+ return rpath
+
def pullremotenames(localrepo, remoterepo):
"""
pulls bookmarks and branches information of the remote repo during a
@@ -101,7 +126,7 @@
localrepo is our local repository
remoterepo is the peer instance
"""
- remotepath = remoterepo.url()
+ remotepath = activepath(localrepo, remoterepo)
bookmarks = remoterepo.listkeys('bookmarks')
# on a push, we don't want to keep obsolete heads since
# they won't show up as heads on the next pull, so we
--- a/tests/test-logexchange.t Mon Feb 12 10:36:59 2018 -0500
+++ b/tests/test-logexchange.t Sat Dec 23 20:27:41 2017 +0530
@@ -57,14 +57,14 @@
$ cat .hg/logexchange/bookmarks
0
- 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc)
- 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc)
+ 87d6d66763085b629e6d7ed56778c79827273022\x00default\x00bar (esc)
+ 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00default\x00foo (esc)
$ cat .hg/logexchange/branches
0
- ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc)
- 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc)
+ ec2426147f0e39dbc9cef599b066be6035ce691d\x00default\x00default (esc)
+ 3e1487808078543b0af6d10dadf5d46943578db0\x00default\x00wat (esc)
Making a new server
-------------------
@@ -94,15 +94,15 @@
$ cat .hg/logexchange/bookmarks
0
- 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc)
- 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc)
- 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server2\x00bar (esc)
- 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server2\x00foo (esc)
+ 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00default\x00foo (esc)
+ 87d6d66763085b629e6d7ed56778c79827273022\x00default\x00bar (esc)
+ 87d6d66763085b629e6d7ed56778c79827273022\x00$TESTTMP/server2\x00bar (esc)
+ 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00$TESTTMP/server2\x00foo (esc)
$ cat .hg/logexchange/branches
0
- 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc)
- ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc)
- ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server2\x00default (esc)
- 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server2\x00wat (esc)
+ 3e1487808078543b0af6d10dadf5d46943578db0\x00default\x00wat (esc)
+ ec2426147f0e39dbc9cef599b066be6035ce691d\x00default\x00default (esc)
+ ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server2\x00default (esc)
+ 3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server2\x00wat (esc)