##// END OF EJS Templates
hg: move share._getsrcrepo into core...
Gregory Szorc -
r36177:0fe7e39d default
parent child Browse files
Show More
@@ -36,8 +36,6 b' from mercurial import ('
36 36 util,
37 37 )
38 38
39 from . import share
40
41 39 cmdtable = {}
42 40 command = registrar.command(cmdtable)
43 41
@@ -169,7 +167,7 b' def unsharejournal(orig, ui, repo, repop'
169 167 """Copy shared journal entries into this repo when unsharing"""
170 168 if (repo.path == repopath and repo.shared() and
171 169 util.safehasattr(repo, 'journal')):
172 sharedrepo = share._getsrcrepo(repo)
170 sharedrepo = hg.sharedreposource(repo)
173 171 sharedfeatures = _readsharedfeatures(repo)
174 172 if sharedrepo and sharedfeatures > {'journal'}:
175 173 # there is a shared repository and there are shared journal entries
@@ -258,7 +256,7 b' class journalstorage(object):'
258 256 self.sharedfeatures = self.sharedvfs = None
259 257 if repo.shared():
260 258 features = _readsharedfeatures(repo)
261 sharedrepo = share._getsrcrepo(repo)
259 sharedrepo = hg.sharedreposource(repo)
262 260 if sharedrepo is not None and 'journal' in features:
263 261 self.sharedvfs = sharedrepo.vfs
264 262 self.sharedfeatures = features
@@ -9,15 +9,12 b' from __future__ import absolute_import'
9 9
10 10 from mercurial import (
11 11 bundlerepo,
12 hg,
12 13 localrepo,
13 14 match as matchmod,
14 15 scmutil,
15 16 )
16 17
17 from .. import (
18 share,
19 )
20
21 18 from . import (
22 19 narrowrevlog,
23 20 narrowspec,
@@ -37,7 +34,7 b' def wrappostshare(orig, sourcerepo, dest'
37 34 def unsharenarrowspec(orig, ui, repo, repopath):
38 35 if (REQUIREMENT in repo.requirements
39 36 and repo.path == repopath and repo.shared()):
40 srcrepo = share._getsrcrepo(repo)
37 srcrepo = hg.sharedreposource(repo)
41 38 with srcrepo.vfs(narrowspec.FILENAME) as f:
42 39 spec = f.read()
43 40 with repo.vfs(narrowspec.FILENAME, 'w') as f:
@@ -12,14 +12,11 b' import errno'
12 12 from mercurial.i18n import _
13 13 from mercurial import (
14 14 error,
15 hg,
15 16 match as matchmod,
16 17 util,
17 18 )
18 19
19 from .. import (
20 share,
21 )
22
23 20 FILENAME = 'narrowspec'
24 21
25 22 def _parsestoredpatterns(text):
@@ -133,7 +130,7 b' def needsexpansion(includes):'
133 130
134 131 def load(repo):
135 132 if repo.shared():
136 repo = share._getsrcrepo(repo)
133 repo = hg.sharedreposource(repo)
137 134 try:
138 135 spec = repo.vfs.read(FILENAME)
139 136 except IOError as e:
@@ -150,7 +147,7 b' def load(repo):'
150 147 def save(repo, includepats, excludepats):
151 148 spec = format(includepats, excludepats)
152 149 if repo.shared():
153 repo = share._getsrcrepo(repo)
150 repo = hg.sharedreposource(repo)
154 151 repo.vfs.write(FILENAME, spec)
155 152
156 153 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
@@ -52,9 +52,6 b' from mercurial import ('
52 52 util,
53 53 )
54 54
55 repository = hg.repository
56 parseurl = hg.parseurl
57
58 55 cmdtable = {}
59 56 command = registrar.command(cmdtable)
60 57 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -135,27 +132,9 b' def _hassharedbookmarks(repo):'
135 132 return False
136 133 return hg.sharedbookmarks in shared
137 134
138 def _getsrcrepo(repo):
139 """
140 Returns the source repository object for a given shared repository.
141 If repo is not a shared repository, return None.
142 """
143 if repo.sharedpath == repo.path:
144 return None
145
146 if util.safehasattr(repo, 'srcrepo') and repo.srcrepo:
147 return repo.srcrepo
148
149 # the sharedpath always ends in the .hg; we want the path to the repo
150 source = repo.vfs.split(repo.sharedpath)[0]
151 srcurl, branches = parseurl(source)
152 srcrepo = repository(repo.ui, srcurl)
153 repo.srcrepo = srcrepo
154 return srcrepo
155
156 135 def getbkfile(orig, repo):
157 136 if _hassharedbookmarks(repo):
158 srcrepo = _getsrcrepo(repo)
137 srcrepo = hg.sharedreposource(repo)
159 138 if srcrepo is not None:
160 139 # just orig(srcrepo) doesn't work as expected, because
161 140 # HG_PENDING refers repo.root.
@@ -186,7 +165,7 b' def recordchange(orig, self, tr):'
186 165 orig(self, tr)
187 166
188 167 if _hassharedbookmarks(self._repo):
189 srcrepo = _getsrcrepo(self._repo)
168 srcrepo = hg.sharedreposource(self._repo)
190 169 if srcrepo is not None:
191 170 category = 'share-bookmarks'
192 171 tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
@@ -196,6 +175,6 b' def writerepo(orig, self, repo):'
196 175 orig(self, repo)
197 176
198 177 if _hassharedbookmarks(self._repo):
199 srcrepo = _getsrcrepo(self._repo)
178 srcrepo = hg.sharedreposource(self._repo)
200 179 if srcrepo is not None:
201 180 orig(self, srcrepo)
@@ -202,6 +202,24 b' def defaultdest(source):'
202 202 return ''
203 203 return os.path.basename(os.path.normpath(path))
204 204
205 def sharedreposource(repo):
206 """Returns repository object for source repository of a shared repo.
207
208 If repo is not a shared repository, returns None.
209 """
210 if repo.sharedpath == repo.path:
211 return None
212
213 if util.safehasattr(repo, 'srcrepo') and repo.srcrepo:
214 return repo.srcrepo
215
216 # the sharedpath always ends in the .hg; we want the path to the repo
217 source = repo.vfs.split(repo.sharedpath)[0]
218 srcurl, branches = parseurl(source)
219 srcrepo = repository(repo.ui, srcurl)
220 repo.srcrepo = srcrepo
221 return srcrepo
222
205 223 def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None,
206 224 relative=False):
207 225 '''create a shared repository'''
General Comments 0
You need to be logged in to leave comments. Login now