Mercurial > hg
changeset 19860:6cd9b8428104
rebase: rework extrafn handling to support multiple extrafns
This makes it possible to pass keepbranches and extrafn to rebase at
the same time, although nobody uses that functionality presently. This
is a precursor to keeping graft metadata.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 01 Oct 2013 14:28:18 -0400 |
parents | 5ba3cf17da9e |
children | a69a77a80900 |
files | hgext/rebase.py |
diffstat | 1 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/rebase.py Fri Sep 06 13:30:58 2013 +0400 +++ b/hgext/rebase.py Tue Oct 01 14:28:18 2013 -0400 @@ -29,6 +29,20 @@ command = cmdutil.command(cmdtable) testedwith = 'internal' +def _savebranch(ctx, extra): + extra['branch'] = ctx.branch() + +def _makeextrafn(copiers): + """make an extrafn out of the given copy-functions. + + A copy function takes a context and an extra dict, and mutates the + extra dict as needed based on the given context. + """ + def extrafn(ctx, extra): + for c in copiers: + c(ctx, extra) + return extrafn + @command('rebase', [('s', 'source', '', _('rebase from the specified changeset'), _('REV')), @@ -136,7 +150,10 @@ abortf = opts.get('abort') collapsef = opts.get('collapse', False) collapsemsg = cmdutil.logmessage(ui, opts) - extrafn = opts.get('extrafn') # internal, used by e.g. hgsubversion + e = opts.get('extrafn') # internal, used by e.g. hgsubversion + extrafns = [] + if e: + extrafns = [e] keepf = opts.get('keep', False) keepbranchesf = opts.get('keepbranches', False) # keepopen is not meant for use on the command line, but by @@ -240,9 +257,10 @@ external = checkexternal(repo, state, targetancestors) if keepbranchesf: - assert not extrafn, 'cannot use both keepbranches and extrafn' - def extrafn(ctx, extra): - extra['branch'] = ctx.branch() + # insert _savebranch at the start of extrafns so if + # there's a user-provided extrafn it can clobber branch if + # desired + extrafns.insert(0, _savebranch) if collapsef: branches = set() for rev in state: @@ -262,6 +280,8 @@ if activebookmark: bookmarks.unsetcurrent(repo) + extrafn = _makeextrafn(extrafns) + sortedstate = sorted(state) total = len(sortedstate) pos = 0