# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2020-12-14 08:48:38 # Node ID 85f7cf314b39ac49028008b4b4a4e2f4f663a4ea # Parent 25d11b24dedfd1b0b5885d8e3ebc816e568ea7e4 engine: refactor actual cloning code into separate function The `for ...` under which this cloning code exists is too complicated and based on certain assumptions. I am going to refactor it in next patches and make it bit saner. Differential Revision: https://phab.mercurial-scm.org/D9579 diff --git a/mercurial/upgrade_utils/engine.py b/mercurial/upgrade_utils/engine.py --- a/mercurial/upgrade_utils/engine.py +++ b/mercurial/upgrade_utils/engine.py @@ -118,6 +118,42 @@ def matchrevlog(revlogfilter, entry): return UPGRADE_FILELOGS in revlogfilter +def _perform_clone( + ui, + dstrepo, + tr, + old_revlog, + unencoded, + deltareuse, + forcedeltabothparents, + revlogs, + sidedatacompanion, + oncopiedrevision, +): + """ returns the new revlog object created""" + newrl = None + if matchrevlog(revlogs, unencoded): + ui.note( + _(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded) + ) + newrl = _revlogfrompath(dstrepo, unencoded) + old_revlog.clone( + tr, + newrl, + addrevisioncb=oncopiedrevision, + deltareuse=deltareuse, + forcedeltabothparents=forcedeltabothparents, + sidedatacompanion=sidedatacompanion, + ) + else: + msg = _(b'blindly copying %s containing %i revisions\n') + ui.note(msg % (unencoded, len(old_revlog))) + _copyrevlog(tr, dstrepo, old_revlog, unencoded) + + newrl = _revlogfrompath(dstrepo, unencoded) + return newrl + + def _clonerevlogs( ui, srcrepo, @@ -292,26 +328,18 @@ def _clonerevlogs( _(b'file revisions'), total=frevcount ) - if matchrevlog(revlogs, unencoded): - ui.note( - _(b'cloning %d revisions from %s\n') % (len(oldrl), unencoded) - ) - newrl = _revlogfrompath(dstrepo, unencoded) - oldrl.clone( - tr, - newrl, - addrevisioncb=oncopiedrevision, - deltareuse=deltareuse, - forcedeltabothparents=forcedeltabothparents, - sidedatacompanion=sidedatacompanion, - ) - else: - msg = _(b'blindly copying %s containing %i revisions\n') - ui.note(msg % (unencoded, len(oldrl))) - _copyrevlog(tr, dstrepo, oldrl, unencoded) - - newrl = _revlogfrompath(dstrepo, unencoded) - + newrl = _perform_clone( + ui, + dstrepo, + tr, + oldrl, + unencoded, + deltareuse, + forcedeltabothparents, + revlogs, + sidedatacompanion, + oncopiedrevision, + ) info = newrl.storageinfo(storedsize=True) datasize = info[b'storedsize'] or 0