Patchwork [1,of,2] rebase: rework extrafn handling to support multiple extrafns

login
register
mail settings
Submitter Augie Fackler
Date Oct. 1, 2013, 7:07 p.m.
Message ID <d094382a3938b5eea839.1380654428@augie-macbookair>
Download mbox | patch
Permalink /patch/2687/
State Accepted
Commit 6cd9b8428104ed62b4fd477d618361f298b34865
Headers show

Comments

Augie Fackler - Oct. 1, 2013, 7:07 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1380652098 14400
#      Tue Oct 01 14:28:18 2013 -0400
# Node ID d094382a3938b5eea8397780e73e2a12f0c074ea
# Parent  5c0dc243fe5b921589688633a6d2fbe4756d5d1c
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.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -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
@@ -229,9 +246,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:
@@ -251,6 +269,8 @@ 
         if activebookmark:
             bookmarks.unsetcurrent(repo)
 
+        extrafn = _makeextrafn(extrafns)
+
         sortedstate = sorted(state)
         total = len(sortedstate)
         pos = 0