##// END OF EJS Templates
storageutil: extract functionality for resolving strip revisions...
Gregory Szorc -
r40040:fa3dc85a default
parent child Browse files
Show More
@@ -2096,39 +2096,9 b' class revlog(object):'
2096 2096 Returns a tuple containing the minimum rev and a set of all revs that
2097 2097 have linkrevs that will be broken by this strip.
2098 2098 """
2099 brokenrevs = set()
2100 strippoint = len(self)
2101
2102 heads = {}
2103 futurelargelinkrevs = set()
2104 for head in self.headrevs():
2105 headlinkrev = self.linkrev(head)
2106 heads[head] = headlinkrev
2107 if headlinkrev >= minlink:
2108 futurelargelinkrevs.add(headlinkrev)
2109
2110 # This algorithm involves walking down the rev graph, starting at the
2111 # heads. Since the revs are topologically sorted according to linkrev,
2112 # once all head linkrevs are below the minlink, we know there are
2113 # no more revs that could have a linkrev greater than minlink.
2114 # So we can stop walking.
2115 while futurelargelinkrevs:
2116 strippoint -= 1
2117 linkrev = heads.pop(strippoint)
2118
2119 if linkrev < minlink:
2120 brokenrevs.add(strippoint)
2121 else:
2122 futurelargelinkrevs.remove(linkrev)
2123
2124 for p in self.parentrevs(strippoint):
2125 if p != nullrev:
2126 plinkrev = self.linkrev(p)
2127 heads[p] = plinkrev
2128 if plinkrev >= minlink:
2129 futurelargelinkrevs.add(plinkrev)
2130
2131 return strippoint, brokenrevs
2099 return storageutil.resolvestripinfo(minlink, len(self) - 1,
2100 self.headrevs(),
2101 self.linkrev, self.parentrevs)
2132 2102
2133 2103 def strip(self, minlink, transaction):
2134 2104 """truncate the revlog on the first revision with a linkrev >= minlink
@@ -14,6 +14,7 b' from ..i18n import _'
14 14 from ..node import (
15 15 bin,
16 16 nullid,
17 nullrev,
17 18 )
18 19 from .. import (
19 20 error,
@@ -155,3 +156,54 b' def fileidlookup(store, fileid, identifi'
155 156 pass
156 157
157 158 raise error.LookupError(fileid, identifier, _('no match found'))
159
160 def resolvestripinfo(minlinkrev, tiprev, headrevs, linkrevfn, parentrevsfn):
161 """Resolve information needed to strip revisions.
162
163 Finds the minimum revision number that must be stripped in order to
164 strip ``minlinkrev``.
165
166 Returns a 2-tuple of the minimum revision number to do that and a set
167 of all revision numbers that have linkrevs that would be broken
168 by that strip.
169
170 ``tiprev`` is the current tip-most revision. It is ``len(store) - 1``.
171 ``headrevs`` is an iterable of head revisions.
172 ``linkrevfn`` is a callable that receives a revision and returns a linked
173 revision.
174 ``parentrevsfn`` is a callable that receives a revision number and returns
175 an iterable of its parent revision numbers.
176 """
177 brokenrevs = set()
178 strippoint = tiprev + 1
179
180 heads = {}
181 futurelargelinkrevs = set()
182 for head in headrevs:
183 headlinkrev = linkrevfn(head)
184 heads[head] = headlinkrev
185 if headlinkrev >= minlinkrev:
186 futurelargelinkrevs.add(headlinkrev)
187
188 # This algorithm involves walking down the rev graph, starting at the
189 # heads. Since the revs are topologically sorted according to linkrev,
190 # once all head linkrevs are below the minlink, we know there are
191 # no more revs that could have a linkrev greater than minlink.
192 # So we can stop walking.
193 while futurelargelinkrevs:
194 strippoint -= 1
195 linkrev = heads.pop(strippoint)
196
197 if linkrev < minlinkrev:
198 brokenrevs.add(strippoint)
199 else:
200 futurelargelinkrevs.remove(linkrev)
201
202 for p in parentrevsfn(strippoint):
203 if p != nullrev:
204 plinkrev = linkrevfn(p)
205 heads[p] = plinkrev
206 if plinkrev >= minlinkrev:
207 futurelargelinkrevs.add(plinkrev)
208
209 return strippoint, brokenrevs
General Comments 0
You need to be logged in to leave comments. Login now