Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 39606:e471cb2852ea
localrepo: move check for existing repo into createrepository()
For symmetry with the check for existence of a repo in
localrepository.__init__, we should check for the non-existence in
createrepository(). We could alternatively move both checks into
instance().
Differential Revision: https://phab.mercurial-scm.org/D4549
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 12 Sep 2018 08:41:00 -0700 |
parents | a64a965b3610 |
children | 76b58f240821 |
comparison
equal
deleted
inserted
replaced
39605:4eb0f2452ad7 | 39606:e471cb2852ea |
---|---|
2376 assert name.startswith('journal') | 2376 assert name.startswith('journal') |
2377 return os.path.join(base, name.replace('journal', 'undo', 1)) | 2377 return os.path.join(base, name.replace('journal', 'undo', 1)) |
2378 | 2378 |
2379 def instance(ui, path, create, intents=None, createopts=None): | 2379 def instance(ui, path, create, intents=None, createopts=None): |
2380 if create: | 2380 if create: |
2381 vfs = vfsmod.vfs(path, expandpath=True, realpath=True) | 2381 createrepository(ui, path, createopts=createopts) |
2382 | |
2383 if vfs.exists('.hg'): | |
2384 raise error.RepoError(_('repository %s already exists') % path) | |
2385 | |
2386 createrepository(ui, vfs, createopts=createopts) | |
2387 | 2382 |
2388 return localrepository(ui, util.urllocalpath(path), intents=intents) | 2383 return localrepository(ui, util.urllocalpath(path), intents=intents) |
2389 | 2384 |
2390 def islocal(path): | 2385 def islocal(path): |
2391 return True | 2386 return True |
2457 """ | 2452 """ |
2458 known = {'narrowfiles'} | 2453 known = {'narrowfiles'} |
2459 | 2454 |
2460 return {k: v for k, v in createopts.items() if k not in known} | 2455 return {k: v for k, v in createopts.items() if k not in known} |
2461 | 2456 |
2462 def createrepository(ui, wdirvfs, createopts=None): | 2457 def createrepository(ui, path, createopts=None): |
2463 """Create a new repository in a vfs. | 2458 """Create a new repository in a vfs. |
2464 | 2459 |
2465 ``wdirvfs`` is a vfs instance pointing at the working directory. | 2460 ``path`` path to the new repo's working directory. |
2466 ``createopts`` options for the new repository. | 2461 ``createopts`` options for the new repository. |
2467 """ | 2462 """ |
2468 createopts = createopts or {} | 2463 createopts = createopts or {} |
2469 | 2464 |
2470 unknownopts = filterknowncreateopts(ui, createopts) | 2465 unknownopts = filterknowncreateopts(ui, createopts) |
2479 ', '.sorted(unknownopts), | 2474 ', '.sorted(unknownopts), |
2480 hint=_('is a required extension not loaded?')) | 2475 hint=_('is a required extension not loaded?')) |
2481 | 2476 |
2482 requirements = newreporequirements(ui, createopts=createopts) | 2477 requirements = newreporequirements(ui, createopts=createopts) |
2483 | 2478 |
2479 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
2484 if not wdirvfs.exists(): | 2480 if not wdirvfs.exists(): |
2485 wdirvfs.makedirs() | 2481 wdirvfs.makedirs() |
2486 | 2482 |
2487 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) | 2483 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
2484 if hgvfs.exists(): | |
2485 raise error.RepoError(_('repository %s already exists') % path) | |
2486 | |
2488 hgvfs.makedir(notindexed=True) | 2487 hgvfs.makedir(notindexed=True) |
2489 | 2488 |
2490 if b'store' in requirements: | 2489 if b'store' in requirements: |
2491 hgvfs.mkdir(b'store') | 2490 hgvfs.mkdir(b'store') |
2492 | 2491 |