diff mercurial/logexchange.py @ 36059:62a428bf6359

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
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 23 Dec 2017 20:27:41 +0530
parents a29fe459fc49
children 1ccd75027abb
line wrap: on
line diff
--- 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