Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlog.py @ 40005:fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
I found myself having to copy this method as part of implementing a new
storage backend. With a little tweaking, we can extract it to a
standalone function so it can be reused easily.
We'll likely want to implement a better method for removing revisions
on the storage interface someday. But until then, let's use what we
have.
Differential Revision: https://phab.mercurial-scm.org/D4799
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 11:29:05 -0700 |
parents | 8af835af0a85 |
children | 842ffcf1d42f |
line wrap: on
line diff
--- a/mercurial/revlog.py Fri Sep 28 11:16:44 2018 -0700 +++ b/mercurial/revlog.py Fri Sep 28 11:29:05 2018 -0700 @@ -2096,39 +2096,9 @@ Returns a tuple containing the minimum rev and a set of all revs that have linkrevs that will be broken by this strip. """ - brokenrevs = set() - strippoint = len(self) - - heads = {} - futurelargelinkrevs = set() - for head in self.headrevs(): - headlinkrev = self.linkrev(head) - heads[head] = headlinkrev - if headlinkrev >= minlink: - futurelargelinkrevs.add(headlinkrev) - - # This algorithm involves walking down the rev graph, starting at the - # heads. Since the revs are topologically sorted according to linkrev, - # once all head linkrevs are below the minlink, we know there are - # no more revs that could have a linkrev greater than minlink. - # So we can stop walking. - while futurelargelinkrevs: - strippoint -= 1 - linkrev = heads.pop(strippoint) - - if linkrev < minlink: - brokenrevs.add(strippoint) - else: - futurelargelinkrevs.remove(linkrev) - - for p in self.parentrevs(strippoint): - if p != nullrev: - plinkrev = self.linkrev(p) - heads[p] = plinkrev - if plinkrev >= minlink: - futurelargelinkrevs.add(plinkrev) - - return strippoint, brokenrevs + return storageutil.resolvestripinfo(minlink, len(self) - 1, + self.headrevs(), + self.linkrev, self.parentrevs) def strip(self, minlink, transaction): """truncate the revlog on the first revision with a linkrev >= minlink