changeset 45325:c6eea5804551

commitctx: extract sidedata encoding inside its own function This part of the code is quite independent from the rest. Thank to the new ChangingFiles object, moving with the rest of the sidedata code (in metadata.py) is simple. The changelog.add method is simply passing the `files` object to the new function. It will be easy to increase/change the data we gather and encode without impacting the changelog method.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 25 Jul 2020 16:02:26 +0200
parents 6c56277317c2
children 99614011892b
files mercurial/changelog.py mercurial/metadata.py
diffstat 2 files changed, 25 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Sat Jul 25 15:55:09 2020 +0200
+++ b/mercurial/changelog.py	Sat Jul 25 16:02:26 2020 +0200
@@ -558,27 +558,7 @@
         sortedfiles = sorted(files.touched)
         sidedata = None
         if self._copiesstorage == b'changeset-sidedata':
-            sidedata = {}
-            p1copies = files.copied_from_p1
-            if p1copies:
-                p1copies = metadata.encodecopies(sortedfiles, p1copies)
-                sidedata[sidedatamod.SD_P1COPIES] = p1copies
-            p2copies = files.copied_from_p2
-            if p2copies:
-                p2copies = metadata.encodecopies(sortedfiles, p2copies)
-                sidedata[sidedatamod.SD_P2COPIES] = p2copies
-            filesadded = files.added
-            if filesadded:
-                filesadded = metadata.encodefileindices(sortedfiles, filesadded)
-                sidedata[sidedatamod.SD_FILESADDED] = filesadded
-            filesremoved = files.removed
-            if filesremoved:
-                filesremoved = metadata.encodefileindices(
-                    sortedfiles, filesremoved
-                )
-                sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
-            if not sidedata:
-                sidedata = None
+            sidedata = metadata.encode_copies_sidedata(files)
 
         if extra:
             extra = encodeextra(extra)
--- a/mercurial/metadata.py	Sat Jul 25 15:55:09 2020 +0200
+++ b/mercurial/metadata.py	Sat Jul 25 16:02:26 2020 +0200
@@ -254,6 +254,30 @@
         return None
 
 
+def encode_copies_sidedata(files):
+    sortedfiles = sorted(files.touched)
+    sidedata = {}
+    p1copies = files.copied_from_p1
+    if p1copies:
+        p1copies = encodecopies(sortedfiles, p1copies)
+        sidedata[sidedatamod.SD_P1COPIES] = p1copies
+    p2copies = files.copied_from_p2
+    if p2copies:
+        p2copies = encodecopies(sortedfiles, p2copies)
+        sidedata[sidedatamod.SD_P2COPIES] = p2copies
+    filesadded = files.added
+    if filesadded:
+        filesadded = encodefileindices(sortedfiles, filesadded)
+        sidedata[sidedatamod.SD_FILESADDED] = filesadded
+    filesremoved = files.removed
+    if filesremoved:
+        filesremoved = encodefileindices(sortedfiles, filesremoved)
+        sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
+    if not sidedata:
+        sidedata = None
+    return sidedata
+
+
 def _getsidedata(srcrepo, rev):
     ctx = srcrepo[rev]
     filescopies = computechangesetcopies(ctx)