upgrade: introduce a _copyrevlog method
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 30 Jul 2019 19:58:44 +0200
changeset 42691 5535a2201ff1
parent 42690 095dcdd0d55c
child 42693 0812d9fb63fe
upgrade: introduce a _copyrevlog method This function copies a revlog from the old store to the new one, without re-adding all deltas manually. This will eventually save a lot of time when some revlog does not needs any conversions. Code actually using this will be introduced in later changesets.
mercurial/upgrade.py
--- a/mercurial/upgrade.py	Sat Jul 27 19:25:47 2019 +0200
+++ b/mercurial/upgrade.py	Tue Jul 30 19:58:44 2019 +0200
@@ -533,6 +533,35 @@
         #reverse of "/".join(("data", path + ".i"))
         return filelog.filelog(repo.svfs, path[5:-2])
 
+def _copyrevlog(tr, destrepo, oldrl, unencodedname):
+    """copy all relevant files for `oldrl` into `destrepo` store
+
+    Files are copied "as is" without any transformation. The copy is performed
+    without extra checks. Callers are responsible for making sure the copied
+    content is compatible with format of the destination repository.
+    """
+    oldrl = getattr(oldrl, '_revlog', oldrl)
+    newrl = _revlogfrompath(destrepo, unencodedname)
+    newrl = getattr(newrl, '_revlog', newrl)
+
+    oldvfs = oldrl.opener
+    newvfs = newrl.opener
+    oldindex = oldvfs.join(oldrl.indexfile)
+    newindex = newvfs.join(newrl.indexfile)
+    olddata = oldvfs.join(oldrl.datafile)
+    newdata = newvfs.join(newrl.datafile)
+
+    newdir = newvfs.dirname(newrl.indexfile)
+    newvfs.makedirs(newdir)
+
+    util.copyfile(oldindex, newindex)
+    if oldrl.opener.exists(olddata):
+        util.copyfile(olddata, newdata)
+
+    if not (unencodedname.endswith('00changelog.i')
+            or unencodedname.endswith('00manifest.i')):
+        destrepo.svfs.fncache.add(unencodedname)
+
 def _clonerevlogs(ui, srcrepo, dstrepo, tr, deltareuse, forcedeltabothparents):
     """Copy revlogs between 2 repos."""
     revcount = 0