diff mercurial/changelog.py @ 45249:b3040b6739ce

commitctx: extract copy information encoding into extra into commit.py The encoding of copy information into extra has multiple subcases and become quite complicated (eg: empty list can be explicitly or implicitly stored for example). In addition, it is niche experimental feature since as it affect the hash, it is only suitable for user who don't mercurial for storage server side (ie: Google). Having this complexity part of the changelog will get in the way of further cleanup. We could have to either move more of that logic into the changelog or to move or extract more of the logic at the higher level. We take the second approach and start gather logic in dedicated function in commit.py.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 25 Jul 2020 15:13:25 +0200
parents 4c1d39215034
children 6c56277317c2
line wrap: on
line diff
--- a/mercurial/changelog.py	Sat Jul 25 14:59:55 2020 +0200
+++ b/mercurial/changelog.py	Sat Jul 25 15:13:25 2020 +0200
@@ -561,43 +561,21 @@
                 )
         sortedfiles = sorted(files)
         sidedata = None
-        if extra is not None:
-            for name in (
-                b'p1copies',
-                b'p2copies',
-                b'filesadded',
-                b'filesremoved',
-            ):
-                extra.pop(name, None)
-        if p1copies is not None:
-            p1copies = metadata.encodecopies(sortedfiles, p1copies)
-        if p2copies is not None:
-            p2copies = metadata.encodecopies(sortedfiles, p2copies)
-        if filesadded is not None:
-            filesadded = metadata.encodefileindices(sortedfiles, filesadded)
-        if filesremoved is not None:
-            filesremoved = metadata.encodefileindices(sortedfiles, filesremoved)
-        if self._copiesstorage == b'extra':
-            extrasentries = p1copies, p2copies, filesadded, filesremoved
-            if extra is None and any(x is not None for x in extrasentries):
-                extra = {}
-            if p1copies is not None:
-                extra[b'p1copies'] = p1copies
-            if p2copies is not None:
-                extra[b'p2copies'] = p2copies
-            if filesadded is not None:
-                extra[b'filesadded'] = filesadded
-            if filesremoved is not None:
-                extra[b'filesremoved'] = filesremoved
-        elif self._copiesstorage == b'changeset-sidedata':
+        if self._copiesstorage == b'changeset-sidedata':
             sidedata = {}
             if p1copies:
+                p1copies = metadata.encodecopies(sortedfiles, p1copies)
                 sidedata[sidedatamod.SD_P1COPIES] = p1copies
             if p2copies:
+                p2copies = metadata.encodecopies(sortedfiles, p2copies)
                 sidedata[sidedatamod.SD_P2COPIES] = p2copies
             if filesadded:
+                filesadded = metadata.encodefileindices(sortedfiles, filesadded)
                 sidedata[sidedatamod.SD_FILESADDED] = filesadded
             if filesremoved:
+                filesremoved = metadata.encodefileindices(
+                    sortedfiles, filesremoved
+                )
                 sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
             if not sidedata:
                 sidedata = None