diff mercurial/debugcommands.py @ 45665:308ca5528ee6

changing-files: add a debug command display changed files The binary output from sidedata is useful to verify the underlying data do not get corrupted. However having a human readable version is much simpler for debuging the changed files data itself. So we add a debug command to dump this information and we use it in the tests. Differential Revision: https://phab.mercurial-scm.org/D9125
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 30 Sep 2020 09:21:33 +0200
parents 00e4e97c6bc8
children d2e1dcd4490d
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Tue Sep 29 23:16:09 2020 +0200
+++ b/mercurial/debugcommands.py	Wed Sep 30 09:21:33 2020 +0200
@@ -59,6 +59,7 @@
     lock as lockmod,
     logcmdutil,
     mergestate as mergestatemod,
+    metadata,
     obsolete,
     obsutil,
     pathutil,
@@ -99,6 +100,7 @@
 from .revlogutils import (
     deltas as deltautil,
     nodemap,
+    sidedata,
 )
 
 release = lockmod.release
@@ -478,6 +480,40 @@
                 ui.write(b'    %s\n' % v)
 
 
+@command(b'debugchangedfiles', [], b'REV')
+def debugchangedfiles(ui, repo, rev):
+    """list the stored files changes for a revision"""
+    ctx = scmutil.revsingle(repo, rev, None)
+    sd = repo.changelog.sidedata(ctx.rev())
+    files_block = sd.get(sidedata.SD_FILES)
+    if files_block is not None:
+        files = metadata.decode_files_sidedata(sd)
+        for f in sorted(files.touched):
+            if f in files.added:
+                action = b"added"
+            elif f in files.removed:
+                action = b"removed"
+            elif f in files.merged:
+                action = b"merged"
+            elif f in files.salvaged:
+                action = b"salvaged"
+            else:
+                action = b"touched"
+
+            copy_parent = b""
+            copy_source = b""
+            if f in files.copied_from_p1:
+                copy_parent = b"p1"
+                copy_source = files.copied_from_p1[f]
+            elif f in files.copied_from_p2:
+                copy_parent = b"p2"
+                copy_source = files.copied_from_p2[f]
+
+            data = (action, copy_parent, f, copy_source)
+            template = b"%-8s %2s: %s, %s;\n"
+            ui.write(template % data)
+
+
 @command(b'debugcheckstate', [], b'')
 def debugcheckstate(ui, repo):
     """validate the correctness of the current dirstate"""