mercurial/localrepo.py
changeset 42325 526750cdd02d
parent 42300 278dcb24e535
child 42339 c0e1ea0c4cee
equal deleted inserted replaced
42319:b162229ebe0d 42325:526750cdd02d
   120             _cachedfiles.add((path, ''))
   120             _cachedfiles.add((path, ''))
   121 
   121 
   122     def join(self, obj, fname):
   122     def join(self, obj, fname):
   123         return obj.sjoin(fname)
   123         return obj.sjoin(fname)
   124 
   124 
       
   125 class mixedrepostorecache(_basefilecache):
       
   126     """filecache for a mix files in .hg/store and outside"""
       
   127     def __init__(self, *pathsandlocations):
       
   128         # scmutil.filecache only uses the path for passing back into our
       
   129         # join(), so we can safely pass a list of paths and locations
       
   130         super(mixedrepostorecache, self).__init__(*pathsandlocations)
       
   131         for path, location in pathsandlocations:
       
   132             _cachedfiles.update(pathsandlocations)
       
   133 
       
   134     def join(self, obj, fnameandlocation):
       
   135         fname, location = fnameandlocation
       
   136         if location == '':
       
   137             return obj.vfs.join(fname)
       
   138         else:
       
   139             if location != 'store':
       
   140                 raise error.ProgrammingError('unexpected location: %s' %
       
   141                                              location)
       
   142             return obj.sjoin(fname)
       
   143 
   125 def isfilecached(repo, name):
   144 def isfilecached(repo, name):
   126     """check if a repo has already cached "name" filecache-ed property
   145     """check if a repo has already cached "name" filecache-ed property
   127 
   146 
   128     This returns (cachedobj-or-None, iscached) tuple.
   147     This returns (cachedobj-or-None, iscached) tuple.
   129     """
   148     """
   889         'revlogv1',
   908         'revlogv1',
   890         'generaldelta',
   909         'generaldelta',
   891         'treemanifest',
   910         'treemanifest',
   892         REVLOGV2_REQUIREMENT,
   911         REVLOGV2_REQUIREMENT,
   893         SPARSEREVLOG_REQUIREMENT,
   912         SPARSEREVLOG_REQUIREMENT,
       
   913         bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT,
   894     }
   914     }
   895     _basesupported = supportedformats | {
   915     _basesupported = supportedformats | {
   896         'store',
   916         'store',
   897         'fncache',
   917         'fncache',
   898         'shared',
   918         'shared',
  1203             name = name + '%'  + self._extrafilterid
  1223             name = name + '%'  + self._extrafilterid
  1204 
  1224 
  1205         cls = repoview.newtype(self.unfiltered().__class__)
  1225         cls = repoview.newtype(self.unfiltered().__class__)
  1206         return cls(self, name, visibilityexceptions)
  1226         return cls(self, name, visibilityexceptions)
  1207 
  1227 
  1208     @repofilecache('bookmarks', 'bookmarks.current')
  1228     @mixedrepostorecache(('bookmarks', ''), ('bookmarks.current', ''),
       
  1229                          ('bookmarks', 'store'))
  1209     def _bookmarks(self):
  1230     def _bookmarks(self):
  1210         return bookmarks.bmstore(self)
  1231         return bookmarks.bmstore(self)
  1211 
  1232 
  1212     @property
  1233     @property
  1213     def _activebookmark(self):
  1234     def _activebookmark(self):
  1960                 (self.svfs, 'journal.narrowspec'),
  1981                 (self.svfs, 'journal.narrowspec'),
  1961                 (self.vfs, 'journal.narrowspec.dirstate'),
  1982                 (self.vfs, 'journal.narrowspec.dirstate'),
  1962                 (self.vfs, 'journal.dirstate'),
  1983                 (self.vfs, 'journal.dirstate'),
  1963                 (self.vfs, 'journal.branch'),
  1984                 (self.vfs, 'journal.branch'),
  1964                 (self.vfs, 'journal.desc'),
  1985                 (self.vfs, 'journal.desc'),
  1965                 (self.vfs, 'journal.bookmarks'),
  1986                 (bookmarks.bookmarksvfs(self), 'journal.bookmarks'),
  1966                 (self.svfs, 'journal.phaseroots'))
  1987                 (self.svfs, 'journal.phaseroots'))
  1967 
  1988 
  1968     def undofiles(self):
  1989     def undofiles(self):
  1969         return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
  1990         return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
  1970 
  1991 
  1975         narrowspec.savebackup(self, 'journal.narrowspec')
  1996         narrowspec.savebackup(self, 'journal.narrowspec')
  1976         self.vfs.write("journal.branch",
  1997         self.vfs.write("journal.branch",
  1977                           encoding.fromlocal(self.dirstate.branch()))
  1998                           encoding.fromlocal(self.dirstate.branch()))
  1978         self.vfs.write("journal.desc",
  1999         self.vfs.write("journal.desc",
  1979                           "%d\n%s\n" % (len(self), desc))
  2000                           "%d\n%s\n" % (len(self), desc))
  1980         self.vfs.write("journal.bookmarks",
  2001         bookmarksvfs = bookmarks.bookmarksvfs(self)
  1981                           self.vfs.tryread("bookmarks"))
  2002         bookmarksvfs.write("journal.bookmarks",
       
  2003                            bookmarksvfs.tryread("bookmarks"))
  1982         self.svfs.write("journal.phaseroots",
  2004         self.svfs.write("journal.phaseroots",
  1983                            self.svfs.tryread("phaseroots"))
  2005                            self.svfs.tryread("phaseroots"))
  1984 
  2006 
  1985     def recover(self):
  2007     def recover(self):
  1986         with self.lock():
  2008         with self.lock():
  2046         parents = self.dirstate.parents()
  2068         parents = self.dirstate.parents()
  2047         self.destroying()
  2069         self.destroying()
  2048         vfsmap = {'plain': self.vfs, '': self.svfs}
  2070         vfsmap = {'plain': self.vfs, '': self.svfs}
  2049         transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
  2071         transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
  2050                              checkambigfiles=_cachedfiles)
  2072                              checkambigfiles=_cachedfiles)
  2051         if self.vfs.exists('undo.bookmarks'):
  2073         bookmarksvfs = bookmarks.bookmarksvfs(self)
  2052             self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
  2074         if bookmarksvfs.exists('undo.bookmarks'):
       
  2075             bookmarksvfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
  2053         if self.svfs.exists('undo.phaseroots'):
  2076         if self.svfs.exists('undo.phaseroots'):
  2054             self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
  2077             self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
  2055         self.invalidate()
  2078         self.invalidate()
  2056 
  2079 
  2057         parentgone = any(p not in self.changelog.nodemap for p in parents)
  2080         parentgone = any(p not in self.changelog.nodemap for p in parents)
  3001         requirements.add(repository.NARROW_REQUIREMENT)
  3024         requirements.add(repository.NARROW_REQUIREMENT)
  3002 
  3025 
  3003     if createopts.get('lfs'):
  3026     if createopts.get('lfs'):
  3004         requirements.add('lfs')
  3027         requirements.add('lfs')
  3005 
  3028 
       
  3029     if ui.configbool('format', 'bookmarks-in-store'):
       
  3030         requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT)
       
  3031 
  3006     return requirements
  3032     return requirements
  3007 
  3033 
  3008 def filterknowncreateopts(ui, createopts):
  3034 def filterknowncreateopts(ui, createopts):
  3009     """Filters a dict of repo creation options against options that are known.
  3035     """Filters a dict of repo creation options against options that are known.
  3010 
  3036