# HG changeset patch # User Gregory Szorc <gregory.sz...@gmail.com> # Date 1478405835 25200 # Sat Nov 05 21:17:15 2016 -0700 # Node ID ebbd8d975e4bf59b2bdd44736fdf13222988d1a4 # Parent f01367faa792635ad2f7a6b175ae3252292b5121 revlog: add clone method
Upcoming patches will introduce functionality for in-place repository/store "upgrades." Copying the contents of a revlog feels sufficiently low-level to warrant being in the revlog class. diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1818,3 +1818,32 @@ class revlog(object): if not self._inline: res.append(self.datafile) return res + + def clone(self, tr, destrevlog, addrevisioncb=None): + """Copy the contents of this revlog to another revlog. + + The destination revlog will contain the same revisions and nodes. + However, it may not be bit-for-bit identical due to e.g. delta encoding + differences. + """ + if len(destrevlog): + raise ValueError(_('destination revlog is not empty')) + + index = self.index + for rev in self: + entry = index[rev] + + # Some classes override linkrev to take filtered revs into + # account. Use raw entry from index. + linkrev = entry[4] + p1 = index[entry[5]][7] + p2 = index[entry[6]][7] + node = entry[7] + # FUTURE we could optionally allow reusing the delta to avoid + # expensive recomputation. + text = self.revision(rev) + + destrevlog.addrevision(text, tr, linkrev, p1, p2, node=node) + + if addrevisioncb: + addrevisioncb(self, rev, node) _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel