mercurial/revlog.py
changeset 47240 4f38ada3fc26
parent 47239 682f09857d69
child 47241 2219853a1503
equal deleted inserted replaced
47239:682f09857d69 47240:4f38ada3fc26
   291     def __init__(
   291     def __init__(
   292         self,
   292         self,
   293         opener,
   293         opener,
   294         target,
   294         target,
   295         radix,
   295         radix,
   296         postfix=None,
   296         postfix=None,  # only exist for `tmpcensored` now
   297         checkambig=False,
   297         checkambig=False,
   298         mmaplargeindex=False,
   298         mmaplargeindex=False,
   299         censorable=False,
   299         censorable=False,
   300         upperboundcomp=None,
   300         upperboundcomp=None,
   301         persistentnodemap=False,
   301         persistentnodemap=False,
   302         concurrencychecker=None,
   302         concurrencychecker=None,
       
   303         trypending=False,
   303     ):
   304     ):
   304         """
   305         """
   305         create a revlog object
   306         create a revlog object
   306 
   307 
   307         opener is a function that abstracts the file opening operation
   308         opener is a function that abstracts the file opening operation
   321         self._docket_file = None
   322         self._docket_file = None
   322         self._indexfile = None
   323         self._indexfile = None
   323         self._datafile = None
   324         self._datafile = None
   324         self._nodemap_file = None
   325         self._nodemap_file = None
   325         self.postfix = postfix
   326         self.postfix = postfix
       
   327         self._trypending = trypending
   326         self.opener = opener
   328         self.opener = opener
   327         if persistentnodemap:
   329         if persistentnodemap:
   328             self._nodemap_file = nodemaputil.get_nodemap_file(self)
   330             self._nodemap_file = nodemaputil.get_nodemap_file(self)
   329 
   331 
   330         assert target[0] in ALL_KINDS
   332         assert target[0] in ALL_KINDS
   482 
   484 
   483     def _loadindex(self):
   485     def _loadindex(self):
   484 
   486 
   485         new_header, mmapindexthreshold, force_nodemap = self._init_opts()
   487         new_header, mmapindexthreshold, force_nodemap = self._init_opts()
   486 
   488 
   487         if self.postfix is None:
   489         if self.postfix is not None:
       
   490             entry_point = b'%s.i.%s' % (self.radix, self.postfix)
       
   491         elif self._trypending and self.opener.exists(b'%s.i.a' % self.radix):
       
   492             entry_point = b'%s.i.a' % self.radix
       
   493         else:
   488             entry_point = b'%s.i' % self.radix
   494             entry_point = b'%s.i' % self.radix
   489         else:
       
   490             entry_point = b'%s.i.%s' % (self.radix, self.postfix)
       
   491 
   495 
   492         entry_data = b''
   496         entry_data = b''
   493         self._initempty = True
   497         self._initempty = True
   494         entry_data = self._get_data(entry_point, mmapindexthreshold)
   498         entry_data = self._get_data(entry_point, mmapindexthreshold)
   495         if len(entry_data) > 0:
   499         if len(entry_data) > 0:
   543             self._generaldelta = True
   547             self._generaldelta = True
   544             # the logic for persistent nodemap will be dealt with within the
   548             # the logic for persistent nodemap will be dealt with within the
   545             # main docket, so disable it for now.
   549             # main docket, so disable it for now.
   546             self._nodemap_file = None
   550             self._nodemap_file = None
   547 
   551 
   548         if self.postfix is None or self.postfix == b'a':
   552         if self.postfix is None:
   549             self._datafile = b'%s.d' % self.radix
   553             self._datafile = b'%s.d' % self.radix
   550         else:
   554         else:
   551             self._datafile = b'%s.d.%s' % (self.radix, self.postfix)
   555             self._datafile = b'%s.d.%s' % (self.radix, self.postfix)
   552 
   556 
   553         self.nodeconstants = sha1nodeconstants
   557         self.nodeconstants = sha1nodeconstants
  2065     def _nodeduplicatecallback(self, transaction, node):
  2069     def _nodeduplicatecallback(self, transaction, node):
  2066         """called when trying to add a node already stored."""
  2070         """called when trying to add a node already stored."""
  2067 
  2071 
  2068     @contextlib.contextmanager
  2072     @contextlib.contextmanager
  2069     def _writing(self, transaction):
  2073     def _writing(self, transaction):
       
  2074         if self._trypending:
       
  2075             msg = b'try to write in a `trypending` revlog: %s'
       
  2076             msg %= self.display_id
       
  2077             raise error.ProgrammingError(msg)
  2070         if self._writinghandles is not None:
  2078         if self._writinghandles is not None:
  2071             yield
  2079             yield
  2072         else:
  2080         else:
  2073             r = len(self)
  2081             r = len(self)
  2074             dsize = 0
  2082             dsize = 0