Mercurial > evolve
comparison hgext3rd/topic/discovery.py @ 5203:034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
In 36f08ae87ef687be53a59bd87376bcfbe4479205 in core mercurial, `_validator`
attribute to transaction class was removed and a dict was introduced. It added a
`addvalidator()` function to transaction class which can be used to register
multiple validator callbacks.
This updates the code to use `addvalidator()` when `_validator` attribute is not
present.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 19 Mar 2020 20:09:18 +0530 |
parents | a4d081923c81 |
children | 8431bb224862 |
comparison
equal
deleted
inserted
replaced
5195:85640f1feced | 5203:034d6d0efa7d |
---|---|
157 return | 157 return |
158 tr._prepushheads = _nbheads(op.repo) | 158 tr._prepushheads = _nbheads(op.repo) |
159 reporef = weakref.ref(op.repo) | 159 reporef = weakref.ref(op.repo) |
160 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) | 160 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) |
161 oldvalidator = tr.validator | 161 oldvalidator = tr.validator |
162 else: | 162 elif util.safehasattr(tr, '_validator'): |
163 # hg <= 5.3 (36f08ae87ef6) | |
163 oldvalidator = tr._validator | 164 oldvalidator = tr._validator |
164 | 165 |
165 def validator(tr): | 166 def _validate(tr): |
166 repo = reporef() | 167 repo = reporef() |
167 if repo is not None: | 168 if repo is not None: |
168 repo.invalidatecaches() | 169 repo.invalidatecaches() |
169 finalheads = _nbheads(repo) | 170 finalheads = _nbheads(repo) |
170 for branch, oldnb in tr._prepushheads.items(): | 171 for branch, oldnb in tr._prepushheads.items(): |
175 for branch, newnb in finalheads.items(): | 176 for branch, newnb in finalheads.items(): |
176 if 1 < newnb: | 177 if 1 < newnb: |
177 msg = _(b'push create more than 1 head on new branch "%s"' | 178 msg = _(b'push create more than 1 head on new branch "%s"' |
178 % branch) | 179 % branch) |
179 raise error.Abort(msg) | 180 raise error.Abort(msg) |
181 | |
182 def validator(tr): | |
183 _validate(tr) | |
180 return oldvalidator(tr) | 184 return oldvalidator(tr) |
185 | |
181 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) | 186 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) |
182 tr.validator = validator | 187 tr.validator = validator |
188 elif util.safehasattr(tr, '_validator'): | |
189 # hg <= 5.3 (36f08ae87ef6) | |
190 tr._validator = validator | |
183 else: | 191 else: |
184 tr._validator = validator | 192 tr.addvalidator(b'000-new-head-check', _validate) |
193 | |
185 handlecheckheads.params = frozenset() | 194 handlecheckheads.params = frozenset() |
186 | 195 |
187 def _pushb2phases(orig, pushop, bundler): | 196 def _pushb2phases(orig, pushop, bundler): |
188 if common.hastopicext(pushop.repo): | 197 if common.hastopicext(pushop.repo): |
189 checktypes = (b'check:heads', b'check:updated-heads') | 198 checktypes = (b'check:heads', b'check:updated-heads') |