comparison mercurial/hg.py @ 39848:4ece3cdfd907

localrepo: support shared repo creation Previously, hg.share() had its own logic for creating a new repository on the filesystem. With the recent introduction of the createopts dict for passing options to influence repository creation, it is now possible to consolidate the repo creation code for both the normal and shared use cases. This commit teaches the repo creation code in localrepo to recognize when we're creating a shared repo and to act appropriately. Meaningful behavior should be identical. However, there are a few subtle changes: * The .hg/requires file is written out in sorted order (rather than having share-related requirements appended at end). * The .hg directory is created with notindexed=True when a shared repo is being created. Differential Revision: https://phab.mercurial-scm.org/D4707
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 19 Sep 2018 17:05:59 -0700
parents c5e6c1ba1c79
children d3d4b4b5f725
comparison
equal deleted inserted replaced
39847:b504ff813c4f 39848:4ece3cdfd907
47 util, 47 util,
48 verify as verifymod, 48 verify as verifymod,
49 vfs as vfsmod, 49 vfs as vfsmod,
50 ) 50 )
51 51
52 from .utils import (
53 stringutil,
54 )
55
56 release = lock.release 52 release = lock.release
57 53
58 # shared features 54 # shared features
59 sharedbookmarks = 'bookmarks' 55 sharedbookmarks = 'bookmarks'
60 56
259 source, branches = parseurl(origsource) 255 source, branches = parseurl(origsource)
260 srcrepo = repository(ui, source) 256 srcrepo = repository(ui, source)
261 rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) 257 rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None)
262 else: 258 else:
263 srcrepo = source.local() 259 srcrepo = source.local()
264 origsource = source = srcrepo.url()
265 checkout = None 260 checkout = None
266 261
267 sharedpath = srcrepo.sharedpath # if our source is already sharing 262 r = repository(ui, dest, create=True, createopts={
268 263 'sharedrepo': srcrepo,
269 destwvfs = vfsmod.vfs(dest, realpath=True) 264 'sharedrelative': relative,
270 destvfs = vfsmod.vfs(os.path.join(destwvfs.base, '.hg'), realpath=True) 265 })
271 266
272 if destvfs.lexists():
273 raise error.Abort(_('destination already exists'))
274
275 if not destwvfs.isdir():
276 destwvfs.makedirs()
277 destvfs.makedir()
278
279 requirements = ''
280 try:
281 requirements = srcrepo.vfs.read('requires')
282 except IOError as inst:
283 if inst.errno != errno.ENOENT:
284 raise
285
286 if relative:
287 try:
288 sharedpath = os.path.relpath(sharedpath, destvfs.base)
289 requirements += 'relshared\n'
290 except (IOError, ValueError) as e:
291 # ValueError is raised on Windows if the drive letters differ on
292 # each path
293 raise error.Abort(_('cannot calculate relative path'),
294 hint=stringutil.forcebytestr(e))
295 else:
296 requirements += 'shared\n'
297
298 destvfs.write('requires', requirements)
299 destvfs.write('sharedpath', sharedpath)
300
301 r = repository(ui, destwvfs.base)
302 postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath) 267 postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath)
303 _postshareupdate(r, update, checkout=checkout) 268 _postshareupdate(r, update, checkout=checkout)
304 return r 269 return r
305 270
306 def unshare(ui, repo): 271 def unshare(ui, repo):