comparison mercurial/destutil.py @ 27262:3d0feb2f978b

histedit: pick an appropriate base changeset by default (BC) Previously, `hg histedit` required a revision argument specifying which revision to use as the base for the current histedit operation. There was an undocumented and experimental "histedit.defaultrev" option that supported defining a single revision to be used if no argument is passed. Mercurial knows what changesets can be edited. And in most scenarios, people want to edit this history of everything on the current head that is rewritable. Making histedit do this by default and not require an explicit argument or additional configuration is a major usability win and will enable more people to use histedit. This patch changes the behavior of the experimental and undocumented "histedit.defaultrev" config option to select an appropriate base revision by default. Comprehensive tests exercising the edge cases in the new, somewhat complicated default revset have been added. Surprisingly, no tests broke. I guess we were never testing the behavior with no ANCESTOR argument (it used to fail with "abort: histedit requires exactly one ancestor revision"). The new behavior is much more user friendly. The functionality for choosing the default base revision has been moved to destutil.py, where it can easily be modified by extensions.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 24 Oct 2015 19:56:39 +0100
parents e8f1b7285917
children 2c60b4b2a0de
comparison
equal deleted inserted replaced
27261:986d04b9fedd 27262:3d0feb2f978b
196 if repo._activebookmark: 196 if repo._activebookmark:
197 node = _destmergebook(repo) 197 node = _destmergebook(repo)
198 else: 198 else:
199 node = _destmergebranch(repo) 199 node = _destmergebranch(repo)
200 return repo[node].rev() 200 return repo[node].rev()
201
202 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'
203
204 def desthistedit(ui, repo):
205 """Default base revision to edit for `hg histedit`."""
206 default = ui.config('histedit', 'defaultrev', histeditdefaultrevset)
207 if default:
208 revs = repo.revs(default)
209 if revs:
210 # The revset supplied by the user may not be in ascending order nor
211 # take the first revision. So do this manually.
212 revs.sort()
213 return revs.first()
214
215 return None