diff mercurial/copies.py @ 43148:843da18386d5

sidedatacopies: deal with upgrading and downgrading to that format This is quite useful to test this on real life data. Differential Revision: https://phab.mercurial-scm.org/D6955
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 06 Oct 2019 23:36:52 -0400
parents 54e943b28101
children c16fe77e340a
line wrap: on
line diff
--- a/mercurial/copies.py	Sun Oct 06 23:36:51 2019 -0400
+++ b/mercurial/copies.py	Sun Oct 06 23:36:52 2019 -0400
@@ -13,6 +13,9 @@
 
 from .i18n import _
 
+
+from .revlogutils.flagutil import REVIDX_SIDEDATA
+
 from . import (
     error,
     match as matchmod,
@@ -21,6 +24,9 @@
     pycompat,
     util,
 )
+
+from .revlogutils import sidedata as sidedatamod
+
 from .utils import stringutil
 
 
@@ -955,3 +961,49 @@
         # Perhaps someone had chosen the same key name (e.g. "added") and
         # used different syntax for the value.
         return None
+
+
+def _getsidedata(srcrepo, rev):
+    ctx = srcrepo[rev]
+    filescopies = computechangesetcopies(ctx)
+    filesadded = computechangesetfilesadded(ctx)
+    filesremoved = computechangesetfilesremoved(ctx)
+    sidedata = {}
+    if any([filescopies, filesadded, filesremoved]):
+        sortedfiles = sorted(ctx.files())
+        p1copies, p2copies = filescopies
+        p1copies = encodecopies(sortedfiles, p1copies)
+        p2copies = encodecopies(sortedfiles, p2copies)
+        filesadded = encodefileindices(sortedfiles, filesadded)
+        filesremoved = encodefileindices(sortedfiles, filesremoved)
+        sidedata[sidedatamod.SD_P1COPIES] = p1copies
+        sidedata[sidedatamod.SD_P2COPIES] = p2copies
+        sidedata[sidedatamod.SD_FILESADDED] = filesadded
+        sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
+    return sidedata
+
+
+def getsidedataadder(srcrepo, destrepo):
+    def sidedatacompanion(revlog, rev):
+        sidedata = {}
+        if util.safehasattr(revlog, 'filteredrevs'):  # this is a changelog
+            sidedata = _getsidedata(srcrepo, rev)
+        return False, (), sidedata
+
+    return sidedatacompanion
+
+
+def getsidedataremover(srcrepo, destrepo):
+    def sidedatacompanion(revlog, rev):
+        f = ()
+        if util.safehasattr(revlog, 'filteredrevs'):  # this is a changelog
+            if revlog.flags(rev) & REVIDX_SIDEDATA:
+                f = (
+                    sidedatamod.SD_P1COPIES,
+                    sidedatamod.SD_P2COPIES,
+                    sidedatamod.SD_FILESADDED,
+                    sidedatamod.SD_FILESREMOVED,
+                )
+        return False, f, {}
+
+    return sidedatacompanion