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