Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 39707:2f067e365532
localrepo: check for .hg/ directory in makelocalrepository()
As part of this, we move the check to before .hg/hgrc is loaded,
as it makes sense to check for the directory before attempting to
open a file in it.
Differential Revision: https://phab.mercurial-scm.org/D4567
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 12 Sep 2018 12:36:07 -0700 |
parents | e0c5017124b3 |
children | 6a3162ed881d |
comparison
equal
deleted
inserted
replaced
39706:e0c5017124b3 | 39707:2f067e365532 |
---|---|
395 | 395 |
396 # Main VFS for .hg/ directory. | 396 # Main VFS for .hg/ directory. |
397 hgpath = wdirvfs.join(b'.hg') | 397 hgpath = wdirvfs.join(b'.hg') |
398 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) | 398 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) |
399 | 399 |
400 # The .hg/ path should exist and should be a directory. All other | |
401 # cases are errors. | |
402 if not hgvfs.isdir(): | |
403 try: | |
404 hgvfs.stat() | |
405 except OSError as e: | |
406 if e.errno != errno.ENOENT: | |
407 raise | |
408 | |
409 raise error.RepoError(_(b'repository %s not found') % path) | |
410 | |
400 # The .hg/hgrc file may load extensions or contain config options | 411 # The .hg/hgrc file may load extensions or contain config options |
401 # that influence repository construction. Attempt to load it and | 412 # that influence repository construction. Attempt to load it and |
402 # process any new extensions that it may have pulled in. | 413 # process any new extensions that it may have pulled in. |
403 try: | 414 try: |
404 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | 415 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
501 self.root = wdirvfs.base | 512 self.root = wdirvfs.base |
502 # vfs rooted at .hg/. Used to access most non-store paths. | 513 # vfs rooted at .hg/. Used to access most non-store paths. |
503 self.vfs = hgvfs | 514 self.vfs = hgvfs |
504 self.path = hgvfs.base | 515 self.path = hgvfs.base |
505 | 516 |
506 self.requirements = set() | |
507 self.filtername = None | 517 self.filtername = None |
508 # svfs: usually rooted at .hg/store, used to access repository history | 518 # svfs: usually rooted at .hg/store, used to access repository history |
509 # If this is a shared repository, this vfs may point to another | 519 # If this is a shared repository, this vfs may point to another |
510 # repository's .hg/store directory. | 520 # repository's .hg/store directory. |
511 self.svfs = None | 521 self.svfs = None |
533 for name in util.compengines: | 543 for name in util.compengines: |
534 engine = util.compengines[name] | 544 engine = util.compengines[name] |
535 if engine.revlogheader(): | 545 if engine.revlogheader(): |
536 self.supported.add('exp-compression-%s' % name) | 546 self.supported.add('exp-compression-%s' % name) |
537 | 547 |
538 if not self.vfs.isdir(): | 548 try: |
539 try: | 549 self.requirements = scmutil.readrequires(self.vfs, self.supported) |
540 self.vfs.stat() | 550 except IOError as inst: |
541 except OSError as inst: | 551 if inst.errno != errno.ENOENT: |
542 if inst.errno != errno.ENOENT: | 552 raise |
543 raise | 553 self.requirements = set() |
544 raise error.RepoError(_("repository %s not found") % origroot) | |
545 else: | |
546 try: | |
547 self.requirements = scmutil.readrequires( | |
548 self.vfs, self.supported) | |
549 except IOError as inst: | |
550 if inst.errno != errno.ENOENT: | |
551 raise | |
552 | 554 |
553 cachepath = self.vfs.join('cache') | 555 cachepath = self.vfs.join('cache') |
554 self.sharedpath = self.path | 556 self.sharedpath = self.path |
555 try: | 557 try: |
556 sharedpath = self.vfs.read("sharedpath").rstrip('\n') | 558 sharedpath = self.vfs.read("sharedpath").rstrip('\n') |