mercurial/revlog.py
changeset 51169 77b86226dde2
parent 51134 d8f65fc72e7b
parent 51163 849745d7da89
equal deleted inserted replaced
51160:b8f9911c8dca 51169:77b86226dde2
   781             atomictemp=True,
   781             atomictemp=True,
   782         )
   782         )
   783 
   783 
   784     def split_inline(self, tr, header, new_index_file_path=None):
   784     def split_inline(self, tr, header, new_index_file_path=None):
   785         """split the data of an inline revlog into an index and a data file"""
   785         """split the data of an inline revlog into an index and a data file"""
       
   786         assert self._delay_buffer is None
   786         existing_handles = False
   787         existing_handles = False
   787         if self._writinghandles is not None:
   788         if self._writinghandles is not None:
   788             existing_handles = True
   789             existing_handles = True
   789             fp = self._writinghandles[0]
   790             fp = self._writinghandles[0]
   790             fp.flush()
   791             fp.flush()
  1163             # delay or divert already in place
  1164             # delay or divert already in place
  1164             return None
  1165             return None
  1165         elif len(self.index) == 0:
  1166         elif len(self.index) == 0:
  1166             self._orig_index_file = self.index_file
  1167             self._orig_index_file = self.index_file
  1167             self.index_file = self._divert_index()
  1168             self.index_file = self._divert_index()
  1168             self._segmentfile.filename = self.index_file
       
  1169             assert self._orig_index_file is not None
  1169             assert self._orig_index_file is not None
  1170             assert self.index_file is not None
  1170             assert self.index_file is not None
  1171             if self.opener.exists(self.index_file):
  1171             if self.opener.exists(self.index_file):
  1172                 self.opener.unlink(self.index_file)
  1172                 self.opener.unlink(self.index_file)
  1173             return self.index_file
  1173             return self.index_file
  1174         else:
  1174         else:
  1175             self._segmentfile._delay_buffer = self._delay_buffer = []
  1175             self._delay_buffer = []
       
  1176             if self.inline:
       
  1177                 self._segmentfile._delay_buffer = self._delay_buffer
  1176             return None
  1178             return None
  1177 
  1179 
  1178     def write_pending(self):
  1180     def write_pending(self):
  1179         assert not self.is_open
  1181         assert not self.is_open
  1180         if self._orig_index_file is not None:
  1182         if self._orig_index_file is not None:
  1190         if self._delay_buffer:
  1192         if self._delay_buffer:
  1191             with self.opener(pending_index_file, b'r+') as ifh:
  1193             with self.opener(pending_index_file, b'r+') as ifh:
  1192                 ifh.seek(0, os.SEEK_END)
  1194                 ifh.seek(0, os.SEEK_END)
  1193                 ifh.write(b"".join(self._delay_buffer))
  1195                 ifh.write(b"".join(self._delay_buffer))
  1194             any_pending = True
  1196             any_pending = True
  1195         self._segmentfile._delay_buffer = self._delay_buffer = None
  1197         self._delay_buffer = None
       
  1198         if self.inline:
       
  1199             self._segmentfile._delay_buffer = self._delay_buffer
       
  1200         else:
       
  1201             assert self._segmentfile._delay_buffer is None
  1196         self._orig_index_file = self.index_file
  1202         self._orig_index_file = self.index_file
  1197         self.index_file = pending_index_file
  1203         self.index_file = pending_index_file
  1198         self._segmentfile.filename = self.index_file
       
  1199         return self.index_file, any_pending
  1204         return self.index_file, any_pending
  1200 
  1205 
  1201     def finalize_pending(self):
  1206     def finalize_pending(self):
  1202         assert not self.is_open
  1207         assert not self.is_open
  1203 
  1208 
  1219                     self._orig_index_file,
  1224                     self._orig_index_file,
  1220                     checkambig=True,
  1225                     checkambig=True,
  1221                 )
  1226                 )
  1222             self.index_file = self._orig_index_file
  1227             self.index_file = self._orig_index_file
  1223             self._orig_index_file = None
  1228             self._orig_index_file = None
  1224             self._segmentfile.filename = self.index_file
       
  1225         else:
  1229         else:
  1226             msg = b"not delay or divert found on this revlog"
  1230             msg = b"not delay or divert found on this revlog"
  1227             raise error.ProgrammingError(msg)
  1231             raise error.ProgrammingError(msg)
  1228         return self.canonical_index_file
  1232         return self.canonical_index_file
  1229 
  1233 
  1303         persistentnodemap=False,
  1307         persistentnodemap=False,
  1304         concurrencychecker=None,
  1308         concurrencychecker=None,
  1305         trypending=False,
  1309         trypending=False,
  1306         try_split=False,
  1310         try_split=False,
  1307         canonical_parent_order=True,
  1311         canonical_parent_order=True,
       
  1312         data_config=None,
       
  1313         delta_config=None,
       
  1314         feature_config=None,
       
  1315         may_inline=True,  # may inline new revlog
  1308     ):
  1316     ):
  1309         """
  1317         """
  1310         create a revlog object
  1318         create a revlog object
  1311 
  1319 
  1312         opener is a function that abstracts the file opening operation
  1320         opener is a function that abstracts the file opening operation
  1328         self._sidedatafile = None
  1336         self._sidedatafile = None
  1329         self._nodemap_file = None
  1337         self._nodemap_file = None
  1330         self.postfix = postfix
  1338         self.postfix = postfix
  1331         self._trypending = trypending
  1339         self._trypending = trypending
  1332         self._try_split = try_split
  1340         self._try_split = try_split
       
  1341         self._may_inline = may_inline
  1333         self.opener = opener
  1342         self.opener = opener
  1334         if persistentnodemap:
  1343         if persistentnodemap:
  1335             self._nodemap_file = nodemaputil.get_nodemap_file(self)
  1344             self._nodemap_file = nodemaputil.get_nodemap_file(self)
  1336 
  1345 
  1337         assert target[0] in ALL_KINDS
  1346         assert target[0] in ALL_KINDS
  1338         assert len(target) == 2
  1347         assert len(target) == 2
  1339         self.target = target
  1348         self.target = target
  1340         if b'feature-config' in self.opener.options:
  1349         if feature_config is not None:
       
  1350             self.feature_config = feature_config.copy()
       
  1351         elif b'feature-config' in self.opener.options:
  1341             self.feature_config = self.opener.options[b'feature-config'].copy()
  1352             self.feature_config = self.opener.options[b'feature-config'].copy()
  1342         else:
  1353         else:
  1343             self.feature_config = FeatureConfig()
  1354             self.feature_config = FeatureConfig()
  1344         self.feature_config.censorable = censorable
  1355         self.feature_config.censorable = censorable
  1345         self.feature_config.canonical_parent_order = canonical_parent_order
  1356         self.feature_config.canonical_parent_order = canonical_parent_order
  1346         if b'data-config' in self.opener.options:
  1357         if data_config is not None:
       
  1358             self.data_config = data_config.copy()
       
  1359         elif b'data-config' in self.opener.options:
  1347             self.data_config = self.opener.options[b'data-config'].copy()
  1360             self.data_config = self.opener.options[b'data-config'].copy()
  1348         else:
  1361         else:
  1349             self.data_config = DataConfig()
  1362             self.data_config = DataConfig()
  1350         self.data_config.check_ambig = checkambig
  1363         self.data_config.check_ambig = checkambig
  1351         self.data_config.mmap_large_index = mmaplargeindex
  1364         self.data_config.mmap_large_index = mmaplargeindex
  1352         if b'delta-config' in self.opener.options:
  1365         if delta_config is not None:
       
  1366             self.delta_config = delta_config.copy()
       
  1367         elif b'delta-config' in self.opener.options:
  1353             self.delta_config = self.opener.options[b'delta-config'].copy()
  1368             self.delta_config = self.opener.options[b'delta-config'].copy()
  1354         else:
  1369         else:
  1355             self.delta_config = DeltaConfig()
  1370             self.delta_config = DeltaConfig()
  1356         self.delta_config.upper_bound_comp = upperboundcomp
  1371         self.delta_config.upper_bound_comp = upperboundcomp
  1357 
  1372 
  1399             compute_rank = opts.get(b'changelogv2.compute-rank', True)
  1414             compute_rank = opts.get(b'changelogv2.compute-rank', True)
  1400             self.feature_config.compute_rank = compute_rank
  1415             self.feature_config.compute_rank = compute_rank
  1401         elif b'revlogv2' in opts:
  1416         elif b'revlogv2' in opts:
  1402             new_header = REVLOGV2
  1417             new_header = REVLOGV2
  1403         elif b'revlogv1' in opts:
  1418         elif b'revlogv1' in opts:
  1404             new_header = REVLOGV1 | FLAG_INLINE_DATA
  1419             new_header = REVLOGV1
       
  1420             if self._may_inline:
       
  1421                 new_header |= FLAG_INLINE_DATA
  1405             if b'generaldelta' in opts:
  1422             if b'generaldelta' in opts:
  1406                 new_header |= FLAG_GENERALDELTA
  1423                 new_header |= FLAG_GENERALDELTA
  1407         elif b'revlogv0' in self.opener.options:
  1424         elif b'revlogv0' in self.opener.options:
  1408             new_header = REVLOGV0
  1425             new_header = REVLOGV0
  1409         else:
  1426         else: