mercurial/debugcommands.py
changeset 47676 096ee2e260a3
parent 47674 ff97e793ed36
child 47682 78f7f0d490ee
--- 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')