diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -29,6 +29,20 @@ cmdtable = {} 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 @@ def rebase(ui, repo, **opts): 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 @@ def rebase(ui, repo, **opts): 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 @@ def rebase(ui, repo, **opts): if activebookmark: bookmarks.unsetcurrent(repo) + extrafn = _makeextrafn(extrafns) + sortedstate = sorted(state) total = len(sortedstate) pos = 0