D4567: localrepo: check for .hg/ directory in makelocalrepository()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Sep 18 17:59:56 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2f067e365532: localrepo: check for .hg/ directory in makelocalrepository() (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4567?vs=11005&id=11165

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

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
@@ -397,6 +397,17 @@
     hgpath = wdirvfs.join(b'.hg')
     hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
 
+    # The .hg/ path should exist and should be a directory. All other
+    # cases are errors.
+    if not hgvfs.isdir():
+        try:
+            hgvfs.stat()
+        except OSError as e:
+            if e.errno != errno.ENOENT:
+                raise
+
+        raise error.RepoError(_(b'repository %s not found') % path)
+
     # The .hg/hgrc file may load extensions or contain config options
     # that influence repository construction. Attempt to load it and
     # process any new extensions that it may have pulled in.
@@ -503,7 +514,6 @@
         self.vfs = hgvfs
         self.path = hgvfs.base
 
-        self.requirements = set()
         self.filtername = None
         # svfs: usually rooted at .hg/store, used to access repository history
         # If this is a shared repository, this vfs may point to another
@@ -535,20 +545,12 @@
             if engine.revlogheader():
                 self.supported.add('exp-compression-%s' % name)
 
-        if not self.vfs.isdir():
-            try:
-                self.vfs.stat()
-            except OSError as inst:
-                if inst.errno != errno.ENOENT:
-                    raise
-            raise error.RepoError(_("repository %s not found") % origroot)
-        else:
-            try:
-                self.requirements = scmutil.readrequires(
-                        self.vfs, self.supported)
-            except IOError as inst:
-                if inst.errno != errno.ENOENT:
-                    raise
+        try:
+            self.requirements = scmutil.readrequires(self.vfs, self.supported)
+        except IOError as inst:
+            if inst.errno != errno.ENOENT:
+                raise
+            self.requirements = set()
 
         cachepath = self.vfs.join('cache')
         self.sharedpath = self.path



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list