tweakdefaults: add bookmark -D support

Summary:
It got removed from inhibit by D5258813. It's a useful feature so let's
re-implement it in tweakdefaults.

Test Plan: Added test cases with plain strip and fbamend's safe strip.

Reviewers: #mercurial, durham

Reviewed By: durham

Subscribers: medson, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D5313291

Signature: t1:5313291:1498321590:03e61a5b1acc2df44afcfd6ceb723e17c648ce79
This commit is contained in:
Jun Wu 2017-06-24 23:18:52 -07:00
parent 17886e370b
commit 14440f1fcf
2 changed files with 83 additions and 0 deletions

View File

@ -53,6 +53,7 @@ Config::
from mercurial.i18n import _
from mercurial import (
bookmarks,
cmdutil,
commands,
error,
encoding,
@ -173,6 +174,11 @@ def extsetup(ui):
# metadata (e.g. 'amend', 'rebase' and so forth)
wrapfunction(obsolete, 'createmarkers', _createmarkers)
# bookmark -D is an alias to strip -B
entry = wrapcommand(commands.table, 'bookmarks', bookmarkcmd)
entry[1].insert(3, ('D', 'strip', None,
_('like --delete but also strip changesets')))
# wrap bookmarks after remotenames
def afterloaded(loaded):
if loaded:
@ -792,6 +798,21 @@ def tagscmd(orig, ui, repo, **opts):
ui.warn(message + '\n')
return orig(ui, repo, **opts)
def bookmarkcmd(orig, ui, repo, *names, **opts):
strip = opts.pop('strip')
if not strip:
return orig(ui, repo, *names, **opts)
# check conflicted opts
for name in ['force', 'rev', 'rename', 'inactive', 'track', 'untrack',
'all', 'remote']:
if opts.get(name):
raise error.Abort(_('--strip cannot be used together with %s')
% ('--%s' % name))
# call strip -B, may raise UnknownCommand
stripfunc = cmdutil.findcmd('strip', commands.table)[1][0]
return stripfunc(ui, repo, bookmark=names, rev=[])
def unfilteredcmd(orig, *args, **opts):
# use unfiltered repo for performance
#

View File

@ -545,3 +545,65 @@ Test diff --per-file-stat
+b
$ hg diff -r ".^" -r . --per-file-stat-json
{"a": {"adds": 1, "isbinary": false, "removes": 0}, "b": {"adds": 1, "isbinary": false, "removes": 0}}
Test bookmark -D
$ cd $TESTTMP
$ hg init book-D
$ cd book-D
$ cat >> .hg/hgrc <<EOF
> [extensions]
> strip=
> [experimental]
> evolution=all
> EOF
$ hg debugbuilddag '+4*2*2*2'
$ hg bookmark -i -r 1 master
$ hg bookmark -i -r 5 feature1
$ hg bookmark -i -r 6 feature2
$ hg log -G -T '{rev} {bookmarks}' -r 'all()'
o 6 feature2
|
| o 5 feature1
| |
o | 4
| |
| o 3
|/
o 2
|
o 1 master
|
o 0
$ hg bookmark -D feature1
bookmark 'feature1' deleted
2 changesets pruned
$ hg log -G -T '{rev} {bookmarks}' -r 'all()' --hidden
o 6 feature2
|
| x 5
| |
o | 4
| |
| x 3
|/
o 2
|
o 1 master
|
o 0
$ hg bookmark -D feature2 --config extensions.fbamend=!
saved backup bundle to $TESTTMP/book-D/.hg/strip-backup/1c4dfc7a8985-4027cf08-backup.hg (glob)
bookmark 'feature2' deleted
$ hg log -G -T '{rev} {bookmarks}' -r 'all()' --hidden
x 4
|
x 3
|
o 2
|
o 1 master
|
o 0