Patchwork [5,of,8] upgrade: introduce the internal code for revlog cloning selection

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 5, 2019, 4:36 p.m.
Message ID <5b8a0d3b7596be28a31f.1565022993@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/41155/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 5, 2019, 4:36 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1564622158 -7200
#      Thu Aug 01 03:15:58 2019 +0200
# Node ID 5b8a0d3b7596be28a31faac4ffc499da46c0b62e
# Parent  71edc0b44b7108cddee33d99f0ec586a0b0405c9
# EXP-Topic upgrade-select
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5b8a0d3b7596
upgrade: introduce the internal code for revlog cloning selection

For now we still clone every single revlogs but all the selection mechanism is
now in place in the lower layer.

The next changesets will introduce the user interface part of the selection.

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -562,7 +562,26 @@  def _copyrevlog(tr, destrepo, oldrl, une
             or unencodedname.endswith('00manifest.i')):
         destrepo.svfs.fncache.add(unencodedname)
 
-def _clonerevlogs(ui, srcrepo, dstrepo, tr, deltareuse, forcedeltabothparents):
+UPGRADE_CHANGELOG = object()
+UPGRADE_MANIFEST = object()
+UPGRADE_FILELOG = object()
+
+UPGRADE_ALL_REVLOGS = frozenset([UPGRADE_CHANGELOG,
+                                 UPGRADE_MANIFEST,
+                                 UPGRADE_FILELOG])
+
+def matchrevlog(revlogfilter, entry):
+    """check is a revlog is selected for cloning
+
+    The store entry is checked against the passed filter"""
+    if entry.endswith('00changelog.i'):
+        return UPGRADE_CHANGELOG in revlogfilter
+    elif entry.endswith('00manifest.i'):
+        return UPGRADE_MANIFEST in revlogfilter
+    return UPGRADE_FILELOG in revlogfilter
+
+def _clonerevlogs(ui, srcrepo, dstrepo, tr, deltareuse, forcedeltabothparents,
+                 revlogs=UPGRADE_ALL_REVLOGS):
     """Copy revlogs between 2 repos."""
     revcount = 0
     srcsize = 0
@@ -643,7 +662,6 @@  def _clonerevlogs(ui, srcrepo, dstrepo, 
             continue
 
         oldrl = _revlogfrompath(srcrepo, unencoded)
-        newrl = _revlogfrompath(dstrepo, unencoded)
 
         if isinstance(oldrl, changelog.changelog) and 'c' not in seen:
             ui.write(_('finished migrating %d manifest revisions across %d '
@@ -683,10 +701,20 @@  def _clonerevlogs(ui, srcrepo, dstrepo, 
                                                total=frevcount)
 
 
-        ui.note(_('cloning %d revisions from %s\n') % (len(oldrl), unencoded))
-        oldrl.clone(tr, newrl, addrevisioncb=oncopiedrevision,
-                    deltareuse=deltareuse,
-                    forcedeltabothparents=forcedeltabothparents)
+
+        if matchrevlog(revlogs, unencoded):
+            ui.note(_('cloning %d revisions from %s\n')
+                    % (len(oldrl), unencoded))
+            newrl = _revlogfrompath(dstrepo, unencoded)
+            oldrl.clone(tr, newrl, addrevisioncb=oncopiedrevision,
+                        deltareuse=deltareuse,
+                        forcedeltabothparents=forcedeltabothparents)
+        else:
+            msg = _('blindly copying %s containing %i revisions\n')
+            ui.note(msg % (unencoded, len(oldrl)))
+            _copyrevlog(tr, dstrepo, oldrl, unencoded)
+
+            newrl = _revlogfrompath(dstrepo, unencoded)
 
         info = newrl.storageinfo(storedsize=True)
         datasize = info['storedsize'] or 0
@@ -746,7 +774,8 @@  def _finishdatamigration(ui, srcrepo, ds
     before the new store is swapped into the original location.
     """
 
-def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions):
+def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions,
+                 revlogs=UPGRADE_ALL_REVLOGS):
     """Do the low-level work of upgrading a repository.
 
     The upgrade is effectively performed as a copy between a source
@@ -775,7 +804,7 @@  def _upgraderepo(ui, srcrepo, dstrepo, r
 
     with dstrepo.transaction('upgrade') as tr:
         _clonerevlogs(ui, srcrepo, dstrepo, tr, deltareuse,
-                     're-delta-multibase' in actions)
+                     're-delta-multibase' in actions, revlogs=revlogs)
 
     # Now copy other files in the store directory.
     # The sorted() makes execution deterministic.