martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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().

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4549

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2378,12 +2378,7 @@
 
 def instance(ui, path, create, intents=None, createopts=None):
     if create:
-        vfs = vfsmod.vfs(path, expandpath=True, realpath=True)
-
-        if vfs.exists('.hg'):
-            raise error.RepoError(_('repository %s already exists') % path)
-
-        createrepository(ui, vfs, createopts=createopts)
+        createrepository(ui, path, createopts=createopts)
 
     return localrepository(ui, util.urllocalpath(path), intents=intents)
 
@@ -2459,10 +2454,10 @@
 
     return {k: v for k, v in createopts.items() if k not in known}
 
-def createrepository(ui, wdirvfs, createopts=None):
+def createrepository(ui, path, createopts=None):
     """Create a new repository in a vfs.
 
-    ``wdirvfs`` is a vfs instance pointing at the working directory.
+    ``path`` path to the new repo's working directory.
     ``createopts`` options for the new repository.
     """
     createopts = createopts or {}
@@ -2481,10 +2476,14 @@
 
     requirements = newreporequirements(ui, createopts=createopts)
 
+    wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
     if not wdirvfs.exists():
         wdirvfs.makedirs()
 
     hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg'))
+    if hgvfs.exists('.hg'):
+        raise error.RepoError(_('repository %s already exists') % path)
+
     hgvfs.makedir(notindexed=True)
 
     if b'store' in requirements:



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to