##// END OF EJS Templates
delta-computer: stop explicitly taking file handle...
marmoute -
r51913:509f0f7f default
parent child Browse files
Show More
@@ -2580,11 +2580,6 b' class revlog:'
2580 msg = b'adding revision outside `revlog._writing` context'
2580 msg = b'adding revision outside `revlog._writing` context'
2581 raise error.ProgrammingError(msg)
2581 raise error.ProgrammingError(msg)
2582
2582
2583 if self._inline:
2584 fh = self._writinghandles[0]
2585 else:
2586 fh = self._writinghandles[1]
2587
2588 btext = [rawtext]
2583 btext = [rawtext]
2589
2584
2590 curr = len(self)
2585 curr = len(self)
@@ -2650,7 +2645,7 b' class revlog:'
2650 flags,
2645 flags,
2651 )
2646 )
2652
2647
2653 deltainfo = deltacomputer.finddeltainfo(revinfo, fh)
2648 deltainfo = deltacomputer.finddeltainfo(revinfo)
2654
2649
2655 compression_mode = COMP_MODE_INLINE
2650 compression_mode = COMP_MODE_INLINE
2656 if self._docket is not None:
2651 if self._docket is not None:
@@ -2738,7 +2733,7 b' class revlog:'
2738 rawtext = btext[0]
2733 rawtext = btext[0]
2739
2734
2740 if alwayscache and rawtext is None:
2735 if alwayscache and rawtext is None:
2741 rawtext = deltacomputer.buildtext(revinfo, fh)
2736 rawtext = deltacomputer.buildtext(revinfo)
2742
2737
2743 if type(rawtext) == bytes: # only accept immutable objects
2738 if type(rawtext) == bytes: # only accept immutable objects
2744 self._revisioncache = (node, curr, rawtext)
2739 self._revisioncache = (node, curr, rawtext)
@@ -516,7 +516,7 b' def segmentspan(revlog, revs):'
516 return end - revlog.start(revs[0])
516 return end - revlog.start(revs[0])
517
517
518
518
519 def _textfromdelta(fh, revlog, baserev, delta, p1, p2, flags, expectednode):
519 def _textfromdelta(revlog, baserev, delta, p1, p2, flags, expectednode):
520 """build full text from a (base, delta) pair and other metadata"""
520 """build full text from a (base, delta) pair and other metadata"""
521 # special case deltas which replace entire base; no need to decode
521 # special case deltas which replace entire base; no need to decode
522 # base revision. this neatly avoids censored bases, which throw when
522 # base revision. this neatly avoids censored bases, which throw when
@@ -529,7 +529,7 b' def _textfromdelta(fh, revlog, baserev, '
529 else:
529 else:
530 # deltabase is rawtext before changed by flag processors, which is
530 # deltabase is rawtext before changed by flag processors, which is
531 # equivalent to non-raw text
531 # equivalent to non-raw text
532 basetext = revlog.revision(baserev, _df=fh)
532 basetext = revlog.revision(baserev)
533 fulltext = mdiff.patch(basetext, delta)
533 fulltext = mdiff.patch(basetext, delta)
534
534
535 try:
535 try:
@@ -1090,12 +1090,10 b' class deltacomputer:'
1090 def _gather_debug(self):
1090 def _gather_debug(self):
1091 return self._write_debug is not None or self._debug_info is not None
1091 return self._write_debug is not None or self._debug_info is not None
1092
1092
1093 def buildtext(self, revinfo, fh):
1093 def buildtext(self, revinfo):
1094 """Builds a fulltext version of a revision
1094 """Builds a fulltext version of a revision
1095
1095
1096 revinfo: revisioninfo instance that contains all needed info
1096 revinfo: revisioninfo instance that contains all needed info
1097 fh: file handle to either the .i or the .d revlog file,
1098 depending on whether it is inlined or not
1099 """
1097 """
1100 btext = revinfo.btext
1098 btext = revinfo.btext
1101 if btext[0] is not None:
1099 if btext[0] is not None:
@@ -1107,7 +1105,6 b' class deltacomputer:'
1107 delta = cachedelta[1]
1105 delta = cachedelta[1]
1108
1106
1109 fulltext = btext[0] = _textfromdelta(
1107 fulltext = btext[0] = _textfromdelta(
1110 fh,
1111 revlog,
1108 revlog,
1112 baserev,
1109 baserev,
1113 delta,
1110 delta,
@@ -1118,21 +1115,21 b' class deltacomputer:'
1118 )
1115 )
1119 return fulltext
1116 return fulltext
1120
1117
1121 def _builddeltadiff(self, base, revinfo, fh):
1118 def _builddeltadiff(self, base, revinfo):
1122 revlog = self.revlog
1119 revlog = self.revlog
1123 t = self.buildtext(revinfo, fh)
1120 t = self.buildtext(revinfo)
1124 if revlog.iscensored(base):
1121 if revlog.iscensored(base):
1125 # deltas based on a censored revision must replace the
1122 # deltas based on a censored revision must replace the
1126 # full content in one patch, so delta works everywhere
1123 # full content in one patch, so delta works everywhere
1127 header = mdiff.replacediffheader(revlog.rawsize(base), len(t))
1124 header = mdiff.replacediffheader(revlog.rawsize(base), len(t))
1128 delta = header + t
1125 delta = header + t
1129 else:
1126 else:
1130 ptext = revlog.rawdata(base, _df=fh)
1127 ptext = revlog.rawdata(base)
1131 delta = mdiff.textdiff(ptext, t)
1128 delta = mdiff.textdiff(ptext, t)
1132
1129
1133 return delta
1130 return delta
1134
1131
1135 def _builddeltainfo(self, revinfo, base, fh, target_rev=None):
1132 def _builddeltainfo(self, revinfo, base, target_rev=None):
1136 # can we use the cached delta?
1133 # can we use the cached delta?
1137 revlog = self.revlog
1134 revlog = self.revlog
1138 chainbase = revlog.chainbase(base)
1135 chainbase = revlog.chainbase(base)
@@ -1170,7 +1167,7 b' class deltacomputer:'
1170 if self.revlog._lazydelta and currentbase == base:
1167 if self.revlog._lazydelta and currentbase == base:
1171 delta = revinfo.cachedelta[1]
1168 delta = revinfo.cachedelta[1]
1172 if delta is None:
1169 if delta is None:
1173 delta = self._builddeltadiff(base, revinfo, fh)
1170 delta = self._builddeltadiff(base, revinfo)
1174 if self._debug_search:
1171 if self._debug_search:
1175 msg = b"DBG-DELTAS-SEARCH: uncompressed-delta-size=%d\n"
1172 msg = b"DBG-DELTAS-SEARCH: uncompressed-delta-size=%d\n"
1176 msg %= len(delta)
1173 msg %= len(delta)
@@ -1212,8 +1209,8 b' class deltacomputer:'
1212 snapshotdepth,
1209 snapshotdepth,
1213 )
1210 )
1214
1211
1215 def _fullsnapshotinfo(self, fh, revinfo, curr):
1212 def _fullsnapshotinfo(self, revinfo, curr):
1216 rawtext = self.buildtext(revinfo, fh)
1213 rawtext = self.buildtext(revinfo)
1217 data = self.revlog.compress(rawtext)
1214 data = self.revlog.compress(rawtext)
1218 compresseddeltalen = deltalen = dist = len(data[1]) + len(data[0])
1215 compresseddeltalen = deltalen = dist = len(data[1]) + len(data[0])
1219 deltabase = chainbase = curr
1216 deltabase = chainbase = curr
@@ -1231,12 +1228,10 b' class deltacomputer:'
1231 snapshotdepth,
1228 snapshotdepth,
1232 )
1229 )
1233
1230
1234 def finddeltainfo(self, revinfo, fh, excluded_bases=None, target_rev=None):
1231 def finddeltainfo(self, revinfo, excluded_bases=None, target_rev=None):
1235 """Find an acceptable delta against a candidate revision
1232 """Find an acceptable delta against a candidate revision
1236
1233
1237 revinfo: information about the revision (instance of _revisioninfo)
1234 revinfo: information about the revision (instance of _revisioninfo)
1238 fh: file handle to either the .i or the .d revlog file,
1239 depending on whether it is inlined or not
1240
1235
1241 Returns the first acceptable candidate revision, as ordered by
1236 Returns the first acceptable candidate revision, as ordered by
1242 _candidategroups
1237 _candidategroups
@@ -1296,7 +1291,7 b' class deltacomputer:'
1296 # not calling candelta since only one revision needs test, also to
1291 # not calling candelta since only one revision needs test, also to
1297 # avoid overhead fetching flags again.
1292 # avoid overhead fetching flags again.
1298 if not revinfo.textlen or revinfo.flags & REVIDX_RAWTEXT_CHANGING_FLAGS:
1293 if not revinfo.textlen or revinfo.flags & REVIDX_RAWTEXT_CHANGING_FLAGS:
1299 deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
1294 deltainfo = self._fullsnapshotinfo(revinfo, target_rev)
1300 if gather_debug:
1295 if gather_debug:
1301 end = util.timer()
1296 end = util.timer()
1302 dbg['duration'] = end - start
1297 dbg['duration'] = end - start
@@ -1322,7 +1317,7 b' class deltacomputer:'
1322 base = revinfo.cachedelta[0]
1317 base = revinfo.cachedelta[0]
1323 if base == nullrev:
1318 if base == nullrev:
1324 dbg_type = b"full"
1319 dbg_type = b"full"
1325 deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
1320 deltainfo = self._fullsnapshotinfo(revinfo, target_rev)
1326 if gather_debug:
1321 if gather_debug:
1327 snapshotdepth = 0
1322 snapshotdepth = 0
1328 elif base not in excluded_bases:
1323 elif base not in excluded_bases:
@@ -1474,7 +1469,6 b' class deltacomputer:'
1474 candidatedelta = self._builddeltainfo(
1469 candidatedelta = self._builddeltainfo(
1475 revinfo,
1470 revinfo,
1476 candidaterev,
1471 candidaterev,
1477 fh,
1478 target_rev=target_rev,
1472 target_rev=target_rev,
1479 )
1473 )
1480 if self._debug_search:
1474 if self._debug_search:
@@ -1505,7 +1499,7 b' class deltacomputer:'
1505
1499
1506 if deltainfo is None:
1500 if deltainfo is None:
1507 dbg_type = b"full"
1501 dbg_type = b"full"
1508 deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
1502 deltainfo = self._fullsnapshotinfo(revinfo, target_rev)
1509 elif deltainfo.snapshotdepth: # pytype: disable=attribute-error
1503 elif deltainfo.snapshotdepth: # pytype: disable=attribute-error
1510 dbg_type = b"snapshot"
1504 dbg_type = b"snapshot"
1511 else:
1505 else:
@@ -234,7 +234,7 b' def _precompute_rewritten_delta('
234 dc = deltas.deltacomputer(revlog)
234 dc = deltas.deltacomputer(revlog)
235 rewritten_entries = {}
235 rewritten_entries = {}
236 first_excl_rev = min(excluded_revs)
236 first_excl_rev = min(excluded_revs)
237 with revlog.reading(), revlog._segmentfile._open_read() as dfh:
237 with revlog.reading():
238 for rev in range(first_excl_rev, len(old_index)):
238 for rev in range(first_excl_rev, len(old_index)):
239 if rev in excluded_revs:
239 if rev in excluded_revs:
240 # this revision will be preserved as is, so we don't need to
240 # this revision will be preserved as is, so we don't need to
@@ -261,7 +261,7 b' def _precompute_rewritten_delta('
261 flags=entry[ENTRY_DATA_OFFSET] & 0xFFFF,
261 flags=entry[ENTRY_DATA_OFFSET] & 0xFFFF,
262 )
262 )
263 d = dc.finddeltainfo(
263 d = dc.finddeltainfo(
264 info, dfh, excluded_bases=excluded_revs, target_rev=rev
264 info, excluded_bases=excluded_revs, target_rev=rev
265 )
265 )
266 default_comp = revlog._docket.default_compression_header
266 default_comp = revlog._docket.default_compression_header
267 comp_mode, d = deltas.delta_compression(default_comp, d)
267 comp_mode, d = deltas.delta_compression(default_comp, d)
@@ -774,13 +774,7 b' def filter_delta_issue6528(revlog, delta'
774 (base_rev, delta),
774 (base_rev, delta),
775 flags,
775 flags,
776 )
776 )
777 # cached by the global "writing" context
777 return deltacomputer.buildtext(revinfo)
778 assert revlog._writinghandles is not None
779 if revlog._inline:
780 fh = revlog._writinghandles[0]
781 else:
782 fh = revlog._writinghandles[1]
783 return deltacomputer.buildtext(revinfo, fh)
784
778
785 is_affected = _is_revision_affected_fast_inner(
779 is_affected = _is_revision_affected_fast_inner(
786 is_censored,
780 is_censored,
General Comments 0
You need to be logged in to leave comments. Login now