extsetup: use more generic hggit check and wrap commands earlier

Other extensions (eg, pushrebase) need to wrap commands after remotenames so
they can modify inputs to prevent remotenames from complaining about, eg, a
push --to that would not be a fast-forward. By using the afterloaded() call,
which doesn't do what we expect anyway, we prevented pushrebase from being able
to wrap these functions after remotenames did.

Instead, we change to wrap the command immediately, and then force the option
modifications to the end, by loading them "after" a non-existant extension.
Furthermore, we make the option additions more generic: if any other extension
(including hggit) adds the paramters we want to add, we skip adding them again.
This commit is contained in:
Ryan McElroy 2015-07-06 22:02:34 -07:00
parent 2fc8c56ae1
commit 19c4cb9092
2 changed files with 40 additions and 31 deletions

View File

@ -330,42 +330,41 @@ def extsetup(ui):
# histedit isn't on
pass
def afterhggit(loaded):
entry = extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks)
# check if hggit was loaded; if so, then we'll skip some of the
# duplicate options
hggit = False
for o in entry[1]:
if o[1] == 'remote':
hggit = True
bookcmd = extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks)
branchcmd = extensions.wrapcommand(commands.table, 'branches', exbranches)
pushcmd = extensions.wrapcommand(commands.table, 'push', expushcmd)
if not hggit:
entry[1].append(('a', 'all', None,
'show both remote and local bookmarks'))
entry[1].append(('', 'remote', None, 'show only remote bookmarks'))
if _tracking(ui):
bookcmd[1].append(('t', 'track', '',
'track this bookmark or remote name', 'BOOKMARK'))
bookcmd[1].append(('u', 'untrack', None,
'remove tracking for this bookmark', 'BOOKMARK'))
if _tracking(ui):
entry[1].append(('t', 'track', '',
'track this bookmark or remote name',
'BOOKMARK'))
entry[1].append(('u', 'untrack', None,
'remove tracking for this bookmark',
'BOOKMARK'))
entry = extensions.wrapcommand(commands.table, 'branches', exbranches)
if not hggit:
entry[1].append(('a', 'all', None,
'show both remote and local branches'))
entry[1].append(('', 'remote', None, 'show only remote branches'))
newopts = [
(bookcmd, ('a', 'all', None, 'show both remote and local bookmarks')),
(bookcmd, ('', 'remote', None, 'show only remote bookmarks')),
(branchcmd, ('a', 'all', None, 'show both remote and local branches')),
(branchcmd, ('', 'remote', None, 'show only remote branches')),
(pushcmd, ('t', 'to', '', 'push revs to this bookmark', 'BOOKMARK')),
(pushcmd, ('d', 'delete', '', 'delete remote bookmark', 'BOOKMARK')),
]
entry = extensions.wrapcommand(commands.table, 'push', expushcmd)
if not hggit:
entry[1].append(('t', 'to', '', 'push revs to this bookmark',
'BOOKMARK'))
entry[1].append(('d', 'delete', '', 'delete remote bookmark',
'BOOKMARK'))
extensions.afterloaded('hggit', afterhggit)
def afterload(loaded):
if loaded:
raise ValueError('nonexistant extension should not be loaded')
for cmd, newopt in newopts:
# avoid adding duplicate optionms
skip = False
for opt in cmd[1]:
if opt[1] == newopt[1]:
skip = True
if not skip:
cmd[1].append(newopt)
extensions.afterloaded('nonexistant', afterload)
def exlog(orig, ui, repo, *args, **opts):
# hack for logging that turns on the dynamic blockerhook

View File

@ -282,3 +282,13 @@ Test clone --mirror
bar 2:95cb4ab9fe1d
baz 2:95cb4ab9fe1d
foo 2:95cb4ab9fe1d
Test loading with hggit
$ echo "[extensions]" >> $HGRCPATH
$ echo "hggit=" >> $HGRCPATH
$ hg help bookmarks | grep -A 3 -- '--track'
-t --track BOOKMARK track this bookmark or remote name
-u --untrack remove tracking for this bookmark
-a --all show both remote and local bookmarks
--remote show only remote bookmarks