comparison 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
comparison
equal deleted inserted replaced
36058:81199632fa42 36059:62a428bf6359
9 from __future__ import absolute_import 9 from __future__ import absolute_import
10 10
11 from .node import hex 11 from .node import hex
12 12
13 from . import ( 13 from . import (
14 util,
14 vfs as vfsmod, 15 vfs as vfsmod,
15 ) 16 )
16 17
17 # directory name in .hg/ in which remotenames files will be present 18 # directory name in .hg/ in which remotenames files will be present
18 remotenamedir = 'logexchange' 19 remotenamedir = 'logexchange'
92 if branches: 93 if branches:
93 writeremotenamefile(repo, remotepath, branches, 'branches') 94 writeremotenamefile(repo, remotepath, branches, 'branches')
94 finally: 95 finally:
95 wlock.release() 96 wlock.release()
96 97
98 def activepath(repo, remote):
99 """returns remote path"""
100 local = None
101 # is the remote a local peer
102 local = remote.local()
103
104 # determine the remote path from the repo, if possible; else just
105 # use the string given to us
106 rpath = remote
107 if local:
108 rpath = remote._repo.root
109 elif not isinstance(remote, str):
110 rpath = remote._url
111
112 # represent the remotepath with user defined path name if exists
113 for path, url in repo.ui.configitems('paths'):
114 # remove auth info from user defined url
115 url = util.removeauth(url)
116 if url == rpath:
117 rpath = path
118 break
119
120 return rpath
121
97 def pullremotenames(localrepo, remoterepo): 122 def pullremotenames(localrepo, remoterepo):
98 """ 123 """
99 pulls bookmarks and branches information of the remote repo during a 124 pulls bookmarks and branches information of the remote repo during a
100 pull or clone operation. 125 pull or clone operation.
101 localrepo is our local repository 126 localrepo is our local repository
102 remoterepo is the peer instance 127 remoterepo is the peer instance
103 """ 128 """
104 remotepath = remoterepo.url() 129 remotepath = activepath(localrepo, remoterepo)
105 bookmarks = remoterepo.listkeys('bookmarks') 130 bookmarks = remoterepo.listkeys('bookmarks')
106 # on a push, we don't want to keep obsolete heads since 131 # on a push, we don't want to keep obsolete heads since
107 # they won't show up as heads on the next pull, so we 132 # they won't show up as heads on the next pull, so we
108 # remove them here otherwise we would require the user 133 # remove them here otherwise we would require the user
109 # to issue a pull to refresh the storage 134 # to issue a pull to refresh the storage