Patchwork D10641: revlog: simplify the replace_sidedata_info code

login
register
mail settings
Submitter phabricator
Date May 4, 2021, 2:16 p.m.
Message ID <differential-rev-PHID-DREV-uw4quglnxt3dgrscvg2p-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48960/
State Superseded
Headers show

Comments

phabricator - May 4, 2021, 2:16 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We already know how to serialize and de-serialize and enty. So lets just do that
  and modify the entry tuple directly.
  
  This avoid having to duplicated binary operation in complicated code.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10641

AFFECTED FILES
  mercurial/pure/parsers.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -290,17 +290,17 @@ 
         if rev < 0:
             raise KeyError
         self._check_index(rev)
-        sidedata_format = b">Qi"
-        packed_size = struct.calcsize(sidedata_format)
-        if rev >= self._lgt:
-            packed = _pack(sidedata_format, sidedata_offset, sidedata_length)
-            old = self._extra[rev - self._lgt]
-            offset_flags = struct.pack(b">Q", offset_flags)
-            new = offset_flags + old[8:64] + packed + old[64 + packed_size :]
-            self._extra[rev - self._lgt] = new
-        else:
+        if rev < self._lgt:
             msg = b"cannot rewrite entries outside of this transaction"
             raise KeyError(msg)
+        else:
+            entry = list(self[rev])
+            entry[0] = offset_flags
+            entry[8] = sidedata_offset
+            entry[9] = sidedata_length
+            entry = tuple(entry)
+            new = self._pack_entry(entry)
+            self._extra[rev - self._lgt] = new
 
     def _unpack_entry(self, data):
         return self.index_format.unpack(data)