mercurial/revlog.py
changeset 39775 974592474dee
parent 39774 4a2466b2a434
child 39778 a6b3c4c1019f
equal deleted inserted replaced
39774:4a2466b2a434 39775:974592474dee
   102 
   102 
   103 # max size of revlog with inline data
   103 # max size of revlog with inline data
   104 _maxinline = 131072
   104 _maxinline = 131072
   105 _chunksize = 1048576
   105 _chunksize = 1048576
   106 
   106 
   107 LookupError = error.LookupError
       
   108 
       
   109 # Store flag processors (cf. 'addflagprocessor()' to register)
   107 # Store flag processors (cf. 'addflagprocessor()' to register)
   110 _flagprocessors = {
   108 _flagprocessors = {
   111     REVIDX_ISCENSORED: None,
   109     REVIDX_ISCENSORED: None,
   112 }
   110 }
   113 
   111 
   617             raise
   615             raise
   618         except error.RevlogError:
   616         except error.RevlogError:
   619             # parsers.c radix tree lookup failed
   617             # parsers.c radix tree lookup failed
   620             if node == wdirid or node in wdirfilenodeids:
   618             if node == wdirid or node in wdirfilenodeids:
   621                 raise error.WdirUnsupported
   619                 raise error.WdirUnsupported
   622             raise LookupError(node, self.indexfile, _('no node'))
   620             raise error.LookupError(node, self.indexfile, _('no node'))
   623         except KeyError:
   621         except KeyError:
   624             # pure python cache lookup failed
   622             # pure python cache lookup failed
   625             n = self._nodecache
   623             n = self._nodecache
   626             i = self.index
   624             i = self.index
   627             p = self._nodepos
   625             p = self._nodepos
   635                 if v == node:
   633                 if v == node:
   636                     self._nodepos = r - 1
   634                     self._nodepos = r - 1
   637                     return r
   635                     return r
   638             if node == wdirid or node in wdirfilenodeids:
   636             if node == wdirid or node in wdirfilenodeids:
   639                 raise error.WdirUnsupported
   637                 raise error.WdirUnsupported
   640             raise LookupError(node, self.indexfile, _('no node'))
   638             raise error.LookupError(node, self.indexfile, _('no node'))
   641 
   639 
   642     # Accessors for index entries.
   640     # Accessors for index entries.
   643 
   641 
   644     # First tuple entry is 8 bytes. First 6 bytes are offset. Last 2 bytes
   642     # First tuple entry is 8 bytes. First 6 bytes are offset. Last 2 bytes
   645     # are flags.
   643     # are flags.
  1233             # odds of a binary node being all hex in ASCII are 1 in 10**25
  1231             # odds of a binary node being all hex in ASCII are 1 in 10**25
  1234             try:
  1232             try:
  1235                 node = id
  1233                 node = id
  1236                 self.rev(node) # quick search the index
  1234                 self.rev(node) # quick search the index
  1237                 return node
  1235                 return node
  1238             except LookupError:
  1236             except error.LookupError:
  1239                 pass # may be partial hex id
  1237                 pass # may be partial hex id
  1240         try:
  1238         try:
  1241             # str(rev)
  1239             # str(rev)
  1242             rev = int(id)
  1240             rev = int(id)
  1243             if "%d" % rev != id:
  1241             if "%d" % rev != id:
  1253             try:
  1251             try:
  1254                 # a full hex nodeid?
  1252                 # a full hex nodeid?
  1255                 node = bin(id)
  1253                 node = bin(id)
  1256                 self.rev(node)
  1254                 self.rev(node)
  1257                 return node
  1255                 return node
  1258             except (TypeError, LookupError):
  1256             except (TypeError, error.LookupError):
  1259                 pass
  1257                 pass
  1260 
  1258 
  1261     def _partialmatch(self, id):
  1259     def _partialmatch(self, id):
  1262         # we don't care wdirfilenodeids as they should be always full hash
  1260         # we don't care wdirfilenodeids as they should be always full hash
  1263         maybewdir = wdirhex.startswith(id)
  1261         maybewdir = wdirhex.startswith(id)
  1318             return n
  1316             return n
  1319         n = self._partialmatch(id)
  1317         n = self._partialmatch(id)
  1320         if n:
  1318         if n:
  1321             return n
  1319             return n
  1322 
  1320 
  1323         raise LookupError(id, self.indexfile, _('no match found'))
  1321         raise error.LookupError(id, self.indexfile, _('no match found'))
  1324 
  1322 
  1325     def shortest(self, node, minlength=1):
  1323     def shortest(self, node, minlength=1):
  1326         """Find the shortest unambiguous prefix that matches node."""
  1324         """Find the shortest unambiguous prefix that matches node."""
  1327         def isvalid(prefix):
  1325         def isvalid(prefix):
  1328             try:
  1326             try:
  1331                 return False
  1329                 return False
  1332             except error.WdirUnsupported:
  1330             except error.WdirUnsupported:
  1333                 # single 'ff...' match
  1331                 # single 'ff...' match
  1334                 return True
  1332                 return True
  1335             if node is None:
  1333             if node is None:
  1336                 raise LookupError(node, self.indexfile, _('no node'))
  1334                 raise error.LookupError(node, self.indexfile, _('no node'))
  1337             return True
  1335             return True
  1338 
  1336 
  1339         def maybewdir(prefix):
  1337         def maybewdir(prefix):
  1340             return all(c == 'f' for c in prefix)
  1338             return all(c == 'f' for c in prefix)
  1341 
  1339 
  1352             try:
  1350             try:
  1353                 length = max(self.index.shortest(node), minlength)
  1351                 length = max(self.index.shortest(node), minlength)
  1354                 return disambiguate(hexnode, length)
  1352                 return disambiguate(hexnode, length)
  1355             except error.RevlogError:
  1353             except error.RevlogError:
  1356                 if node != wdirid:
  1354                 if node != wdirid:
  1357                     raise LookupError(node, self.indexfile, _('no node'))
  1355                     raise error.LookupError(node, self.indexfile, _('no node'))
  1358             except AttributeError:
  1356             except AttributeError:
  1359                 # Fall through to pure code
  1357                 # Fall through to pure code
  1360                 pass
  1358                 pass
  1361 
  1359 
  1362         if node == wdirid:
  1360         if node == wdirid:
  2083                     # this can happen if two branches make the same change
  2081                     # this can happen if two branches make the same change
  2084                     continue
  2082                     continue
  2085 
  2083 
  2086                 for p in (p1, p2):
  2084                 for p in (p1, p2):
  2087                     if p not in self.nodemap:
  2085                     if p not in self.nodemap:
  2088                         raise LookupError(p, self.indexfile,
  2086                         raise error.LookupError(p, self.indexfile,
  2089                                           _('unknown parent'))
  2087                                                 _('unknown parent'))
  2090 
  2088 
  2091                 if deltabase not in self.nodemap:
  2089                 if deltabase not in self.nodemap:
  2092                     raise LookupError(deltabase, self.indexfile,
  2090                     raise error.LookupError(deltabase, self.indexfile,
  2093                                       _('unknown delta base'))
  2091                                             _('unknown delta base'))
  2094 
  2092 
  2095                 baserev = self.rev(deltabase)
  2093                 baserev = self.rev(deltabase)
  2096 
  2094 
  2097                 if baserev != nullrev and self.iscensored(baserev):
  2095                 if baserev != nullrev and self.iscensored(baserev):
  2098                     # if base is censored, delta must be full replacement in a
  2096                     # if base is censored, delta must be full replacement in a