comparison mercurial/hg.py @ 30041:1779dde4c9ef

hg: set default path correctly when doing a clone+share (issue5378) Before, if performing a clone+share from a repo that was itself using shared storage, the share code would copy paths.default from the underlying repo being shared, not from the source given by the user. This patch teaches hg.clonewithshare to resolve paths.default and pass it to share so it can be written to the hgrc accordingly.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 02 Oct 2016 22:34:40 -0700
parents a77d48219edd
children 940c05b25b07
comparison
equal deleted inserted replaced
30040:3e3f2201bbdf 30041:1779dde4c9ef
193 path = util.url(source).path 193 path = util.url(source).path
194 if not path: 194 if not path:
195 return '' 195 return ''
196 return os.path.basename(os.path.normpath(path)) 196 return os.path.basename(os.path.normpath(path))
197 197
198 def share(ui, source, dest=None, update=True, bookmarks=True): 198 def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None):
199 '''create a shared repository''' 199 '''create a shared repository'''
200 200
201 if not islocal(source): 201 if not islocal(source):
202 raise error.Abort(_('can only share local repositories')) 202 raise error.Abort(_('can only share local repositories'))
203 203
238 requirements += 'shared\n' 238 requirements += 'shared\n'
239 destvfs.write('requires', requirements) 239 destvfs.write('requires', requirements)
240 destvfs.write('sharedpath', sharedpath) 240 destvfs.write('sharedpath', sharedpath)
241 241
242 r = repository(ui, destwvfs.base) 242 r = repository(ui, destwvfs.base)
243 postshare(srcrepo, r, bookmarks=bookmarks) 243 postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath)
244 _postshareupdate(r, update, checkout=checkout) 244 _postshareupdate(r, update, checkout=checkout)
245 245
246 def postshare(sourcerepo, destrepo, bookmarks=True): 246 def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None):
247 """Called after a new shared repo is created. 247 """Called after a new shared repo is created.
248 248
249 The new repo only has a requirements file and pointer to the source. 249 The new repo only has a requirements file and pointer to the source.
250 This function configures additional shared data. 250 This function configures additional shared data.
251 251
252 Extensions can wrap this function and write additional entries to 252 Extensions can wrap this function and write additional entries to
253 destrepo/.hg/shared to indicate additional pieces of data to be shared. 253 destrepo/.hg/shared to indicate additional pieces of data to be shared.
254 """ 254 """
255 default = sourcerepo.ui.config('paths', 'default') 255 default = defaultpath or sourcerepo.ui.config('paths', 'default')
256 if default: 256 if default:
257 fp = destrepo.vfs("hgrc", "w", text=True) 257 fp = destrepo.vfs("hgrc", "w", text=True)
258 fp.write("[paths]\n") 258 fp.write("[paths]\n")
259 fp.write("default = %s\n" % default) 259 fp.write("default = %s\n" % default)
260 fp.close() 260 fp.close()
372 # well. Never update because working copies aren't necessary in 372 # well. Never update because working copies aren't necessary in
373 # share mode. 373 # share mode.
374 clone(ui, peeropts, source, dest=sharepath, pull=True, 374 clone(ui, peeropts, source, dest=sharepath, pull=True,
375 rev=rev, update=False, stream=stream) 375 rev=rev, update=False, stream=stream)
376 376
377 # Resolve the value to put in [paths] section for the source.
378 if islocal(source):
379 defaultpath = os.path.abspath(util.urllocalpath(source))
380 else:
381 defaultpath = source
382
377 sharerepo = repository(ui, path=sharepath) 383 sharerepo = repository(ui, path=sharepath)
378 share(ui, sharerepo, dest=dest, update=False, bookmarks=False) 384 share(ui, sharerepo, dest=dest, update=False, bookmarks=False,
385 defaultpath=defaultpath)
379 386
380 # We need to perform a pull against the dest repo to fetch bookmarks 387 # We need to perform a pull against the dest repo to fetch bookmarks
381 # and other non-store data that isn't shared by default. In the case of 388 # and other non-store data that isn't shared by default. In the case of
382 # non-existing shared repo, this means we pull from the remote twice. This 389 # non-existing shared repo, this means we pull from the remote twice. This
383 # is a bit weird. But at the time it was implemented, there wasn't an easy 390 # is a bit weird. But at the time it was implemented, there wasn't an easy