comparison mercurial/subrepo.py @ 12753:ef5eaf53f4f7

subrepo: abort instead of pushing/pulling to the repo itself _abssource will now abort (or return None) in the rare cases where no push/pull path can be found.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 19 Oct 2010 03:56:20 +0200
parents 18b5b6392fcf
children 614f0d8724ab
comparison
equal deleted inserted replaced
12752:18b5b6392fcf 12753:ef5eaf53f4f7
165 """return path to this subrepo as seen from outermost repo""" 165 """return path to this subrepo as seen from outermost repo"""
166 if not hasattr(sub, '_repo'): 166 if not hasattr(sub, '_repo'):
167 return sub._path 167 return sub._path
168 return reporelpath(sub._repo) 168 return reporelpath(sub._repo)
169 169
170 def _abssource(repo, push=False): 170 def _abssource(repo, push=False, abort=True):
171 """return pull/push path of repo - either based on parent repo 171 """return pull/push path of repo - either based on parent repo .hgsub info
172 .hgsub info or on the subrepos own config""" 172 or on the top repo config. Abort or return None if no source found."""
173 if hasattr(repo, '_subparent'): 173 if hasattr(repo, '_subparent'):
174 source = repo._subsource 174 source = repo._subsource
175 if source.startswith('/') or '://' in source: 175 if source.startswith('/') or '://' in source:
176 return source 176 return source
177 parent = _abssource(repo._subparent, push) 177 parent = _abssource(repo._subparent, push, abort=False)
178 if '://' in parent: 178 if parent:
179 if parent[-1] == '/': 179 if '://' in parent:
180 parent = parent[:-1] 180 if parent[-1] == '/':
181 r = urlparse.urlparse(parent + '/' + source) 181 parent = parent[:-1]
182 r = urlparse.urlunparse((r[0], r[1], 182 r = urlparse.urlparse(parent + '/' + source)
183 posixpath.normpath(r[2]), 183 r = urlparse.urlunparse((r[0], r[1],
184 r[3], r[4], r[5])) 184 posixpath.normpath(r[2]),
185 return r 185 r[3], r[4], r[5]))
186 return posixpath.normpath(os.path.join(parent, repo._subsource)) 186 return r
187 if push and repo.ui.config('paths', 'default-push'): 187 else: # plain file system path
188 return repo.ui.config('paths', 'default-push', repo.root) 188 return posixpath.normpath(os.path.join(parent, repo._subsource))
189 return repo.ui.config('paths', 'default', repo.root) 189 else: # recursion reached top repo
190 if push and repo.ui.config('paths', 'default-push'):
191 return repo.ui.config('paths', 'default-push')
192 if repo.ui.config('paths', 'default'):
193 return repo.ui.config('paths', 'default')
194 if abort:
195 raise util.Abort(_("default path for subrepository %s not found") %
196 reporelpath(repo))
190 197
191 def itersubrepos(ctx1, ctx2): 198 def itersubrepos(ctx1, ctx2):
192 """find subrepos in ctx1 or ctx2""" 199 """find subrepos in ctx1 or ctx2"""
193 # Create a (subpath, ctx) mapping where we prefer subpaths from 200 # Create a (subpath, ctx) mapping where we prefer subpaths from
194 # ctx1. The subpaths from ctx2 are important when the .hgsub file 201 # ctx1. The subpaths from ctx2 are important when the .hgsub file
312 if create: 319 if create:
313 fp = self._repo.opener("hgrc", "w", text=True) 320 fp = self._repo.opener("hgrc", "w", text=True)
314 fp.write('[paths]\n') 321 fp.write('[paths]\n')
315 322
316 def addpathconfig(key, value): 323 def addpathconfig(key, value):
317 fp.write('%s = %s\n' % (key, value)) 324 if value:
318 self._repo.ui.setconfig('paths', key, value) 325 fp.write('%s = %s\n' % (key, value))
319 326 self._repo.ui.setconfig('paths', key, value)
320 defpath = _abssource(self._repo) 327
321 defpushpath = _abssource(self._repo, True) 328 defpath = _abssource(self._repo, abort=False)
329 defpushpath = _abssource(self._repo, True, abort=False)
322 addpathconfig('default', defpath) 330 addpathconfig('default', defpath)
323 if defpath != defpushpath: 331 if defpath != defpushpath:
324 addpathconfig('default-push', defpushpath) 332 addpathconfig('default-push', defpushpath)
325 fp.close() 333 fp.close()
326 334