Commits

Yujie Wu committed a954872

Implemented functionality of the `--stamp` option.

  • Participants
  • Parent commits bd6f8db
  • Branches hotfix/0.9.6/add_stamp_option

Comments (0)

Files changed (1)

File src/hgflow.py

         self._via_quiet   = False
         self._dryrun      = False
         self._common_opts = {}
+        self._opt_mutator = {}
 
         
     
         elif (cmd == "rebase") : where = extensions.find( "rebase" )
         else                   : where = mercurial.commands
 
-        opts = self._filter_common_options( where, cmd )
-        opts.update( kwarg )
-        kwarg = opts
-        
+        kwarg = self._mutate_options( where, cmd, kwarg )
+
         for key, value in kwarg.items() :
             if (value is None) :
                 continue
         
         try :
             ret = None
-            ret = getattr( where, cmd )( ui, repo, *arg, **opts )
+            ret = getattr( where, cmd )( ui, repo, *arg, **kwarg )
             if (ret and cmd not in ["commit", "rebase",]) :
                 raise AbortFlow( "Nonzero return code from hg command" )
         except Exception, e :
                     ret[e] = self._common_opts[e]
         return ret
 
-     
+    
+
+    def _mutate_options( self, where, cmd, opts ) :
+        """
+
+        """
+        common_opts = self._filter_common_options( where, cmd )
+        common_opts.update( opts )
+
+        mutator = self._opt_mutator.get( cmd )
+        if (mutator) :
+            opts = mutator( opts )
+        
+        return opts
+
+        
 
     def use_quiet_channel( self, via_quiet = True ) :
         """
 
 
 
+    def reg_option_mutator( self, cmd, mutator ) :
+        """
+        Register common options.
+
+        @type  opts: C{dict}
+        @param opts: Common options. Key = option's flag, value = option's value. 
+        """
+        self._opt_mutator[cmd] = mutator
+
+
+
     def dryrun( self, switch = None ) :
         """
         Switch the dry-run mode.
             common_opts[e] = v
     commands.reg_common_options( common_opts )
 
+    # - Up to this point, `cmd' is a name of command or stream, or `None'.
+    # - We assign `stream' to be a stream name (or `None') and `cmd' to be a name of command or action.
+    # - When `arg' is a 0-tuple, `cmd' should be "list" as the default action. We use `arg + ("list",)' to ensure we can get the
+    #   first element.
+    stream, cmd = (None, cmd) if (cmd in func) else (cmd, (arg + ("list",))[0] )
+    
     try :
         # Checks the options for all commands and actions.
         kwarg = _getopt( ui, cmd, kwarg )
+        stamp = kwarg.pop( "stamp", None )
+        if (stamp) :
+            def stamp_commit_message( opts ) :
+                msg = opts["message"]
+                if (0 > msg.lower().find( stamp.lower() )) :
+                    msg += " %s" % stamp
+                opts["message"] = msg
+                return opts
+            commands.reg_option_mutator( "commit", stamp_commit_message )
         
-        func = func.get( cmd, lambda *arg, **kwarg : flow.action( cmd, *arg, **kwarg ) )
+        func = func.get( cmd, lambda *arg, **kwarg : flow.action( stream, *arg, **kwarg ) )
         func( *arg, **kwarg )
     except AbortFlow, e :
         errmsg = e.error_message()