diff mercurial/debugcommands.py @ 47676:096ee2e260a3

dirstate-v2: Rename Header to Root, move it to the end of the data file Now that they don?t have to be at the start, a given data file may contain multiple "roots". A docket only points to one of them, and previous ones are left unused to allow allow append-only in-place writing to an existing data file. Differential Revision: https://phab.mercurial-scm.org/D11090
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 12 Jul 2021 23:05:56 +0200
parents ff97e793ed36
children 78f7f0d490ee
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Mon Jul 12 22:46:52 2021 +0200
+++ b/mercurial/debugcommands.py	Mon Jul 12 23:05:56 2021 +0200
@@ -997,11 +997,13 @@
     or nothing for dirstate-v2
     """
     if repo.dirstate._use_dirstate_v2:
-        hash_offset = 16  # Four 32-bit integers before this field
+        docket = repo.dirstate._map.docket
         hash_len = 20  # 160 bits for SHA-1
-        data_filename = repo.dirstate._map.docket.data_filename()
+        hash_offset = docket.data_size - hash_len  # hash is at the end
+        data_filename = docket.data_filename()
         with repo.vfs(data_filename) as f:
-            hash_bytes = f.read(hash_offset + hash_len)[-hash_len:]
+            f.seek(hash_offset)
+            hash_bytes = f.read(hash_len)
         ui.write(binascii.hexlify(hash_bytes) + b'\n')