Yujie Wu avatar Yujie Wu committed 0445a93 Merge

flow: Merged <hotfix/0.9.6> 'add_stamp_option' to <hotfix/0.9.6> ('hotfix/0.9.6').

Comments (0)

Files changed (1)

         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.
         except IndexError :
             raise AbortFlow( "You must specify a name for the new branch to start." )
             
-        kwarg    = _getopt( self.ui, "start", kwarg )
         rev      = kwarg.pop( "rev",     None )
         msg      = kwarg.pop( "message", ""   )
         dirty    = kwarg.pop( "dirty",   None )
         @param stream: Stream of which you want to display open branches
         """
         # Lists all open branches in this stream.
-        kwarg         = _getopt( self.ui, "list", kwarg )
         open_branches = stream.branches()
         trunk         = stream.trunk()
         if (trunk) :
         # User may specify a file with a relative path name. Since CWD has changed to the repository's root dir when the
         # `Flow' object was constructed, we need to restore the original dir to get the correct path name of the file.
         os.chdir( self.orig_dir )
-        kwarg     = _getopt( self.ui, "log", kwarg )
         filenames = kwarg.pop( "file", [] )
         onstream  = kwarg.pop( "onstream", False )
         closed    = kwarg.pop( "closed",   False )
         @type  stream: C{Stream}
         @param stream: Stream where the branch which you want to abort is
         """
-        kwarg          = _getopt( self.ui, "abort", kwarg )
         msg            = kwarg.pop( "message",  ""    )
         should_erase   = kwarg.pop( "erase",    False )
         onstream       = kwarg.pop( "onstream", False )
         @param    rev: If provided, promote this revision instead of the head. The specified revision must be in the workspace
                        branch.
         """
-        kwarg          = _getopt( self.ui, "promote", kwarg )
         rev            = kwarg.pop( "rev",     None )
         tag_name       = kwarg.pop( "tag",     None )
         message        = kwarg.pop( "message", None )
                        branch, otherwise it will trigger an error. If not provided, use the tip of the parent branch as the
                        destination of rebasing.
         """
-        kwarg    = _getopt( self.ui, "rebase", kwarg )
         dest     = kwarg.get( "dest" )
         onstream = kwarg.pop( "onstream", False )
         if (onstream) :
         except IndexError :
             tag_name = None
 
-        kwarg          = _getopt( self.ui, "finish", kwarg )
         message        = kwarg.get( "message",  None  )
         onstream       = kwarg.pop( "onstream", False )
         should_erase   = kwarg.pop( "erase",    False )
                 self._print( "autoshelve: %s" % ("on" if (autoshelve) else "off"), prefix = "  " )
 
         # Shall we continue if there already exists a configuration file?
-        kwarg = _getopt( self.ui, "init", kwarg )
         if (has_goodconfig and not kwarg.get( "force" )) :
             return
 
     
         # Creates 'master' and 'develop' streams if they don't yet exist.
         if (not self._find_branch( master_stream )) :
-            self._create_branch( master_stream, "flow initialization: Created <master> trunk: %s" % master_stream )
+            self._create_branch( master_stream, "flow initialization: Created <master> trunk: %s." % master_stream )
         if (not self._find_branch( develop_stream )) :
-            self._create_branch( develop_stream, "flow initialization: Created <develop> trunk: %s" % develop_stream )
+            self._create_branch( develop_stream, "flow initialization: Created <develop> trunk: %s." % develop_stream )
         self._update( workspace )
         self._unshelve()
 
             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 :
-        # If `cmd' is a command (instead of an action), checks the options for it.
-        if (cmd in func) :
-            _getopt( ui, cmd, kwarg )
+        # 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()
 
 options:
  -r --rev REV       Revision to start a new branch from.
- -m --message TEXT  Record TEXT as commit message when open new branch.
+ -m --message TEXT  Record TEXT as commit message when opening new branch.
+ -p --stamp TEXT    Append TEXT to all commit messages.
  -d --date DATE     Record the specified DATE as commit date.
  -u --user USER     Use specified USER as committer.
     --dirty         Start a new branch from current dirty workspace branch and
 options:
  -c --commit        Commit changes before close the branch.
  -m --message TEXT  Record TEXT as commit message.
+ -p --stamp TEXT    Append TEXT to all commit messages.
  -d --date DATE     Record the specified DATE as commit date.
  -u --user USER     Use specified USER as committer.
  -e --erase         Erase branch after it is merged successfully.
 <support>), this syntax is completely equivalent to the other one.
 
 option:
--c --closed    Show open and closed branches in <stream>.
+ -c --closed    Show open and closed branches in <stream>.
 """,
 
 "@log" : """
 syntax:
 {{{hg flow <stream> abort [-m <TEXT>] [-e]}}}
 
-option:
- -m --message TEXT  Record TEXT as commit message when close branch.
+options:
+ -m --message TEXT  Record TEXT as commit message when closing branch.
+ -p --stamp TEXT    Append TEXT to all commit messages.
  -e --erase         Abort branch and erase it.
 """,
 
 The workspace branch must be in <stream>. If the `-r` option is omitted, its
 value will default to the head of the workspace branch.
 
-option:
+options:
  -r --rev REV       Revision to promote to other branches.
- -m --message TEXT  Record TEXT as commit message when promote branch.
+ -m --message TEXT  Record TEXT as commit message when promoting branch.
+ -p --stamp TEXT    Append TEXT to all commit messages.
  -t --tag NAME      Tag the merging changeset with NAME
  -d --date DATE     Record the specified DATE as commit date.
  -u --user USER     Use specified USER as committer.
 syntax:
 {{{hg flow <stream> rebase [-d <rev>]}}}
 
+option:
+ -p --stamp TEXT  Append TEXT to all commit messages.
+
 The workspace branch must be in <stream>. If the destination revision is not
 specified, it will default to the source branch of the workspace branch.
 """,
 {{{hg flow init [<option>...]}}}
 
 options:
- -f --force  Force reinitializing flow.
- -u --user USER     Use specified USER as committer.
+ -f --force       Force reinitializing flow.
+ -u --user USER   Use specified USER as committer.
+ -p --stamp TEXT  Append TEXT to all commit messages.
 """,
 
 "@upgrade" : """
 
 syntax:
 {{{hg flow upgrade}}}
+
+options:
+ -u --user USER   Use specified USER as committer.
+ -p --stamp TEXT  Append TEXT to all commit messages.
 """,
 
 "@unshelve" : """
 
 
 OPT_FILTER = {
-"init"    : ("force", "user",),
-"start"   : ("rev", "message", "date", "user", "dirty",),
-"finish"  : ("commit", "message", "date", "user", "erase", "onstream",),
+"init"    : ("force", "user", "stamp",),
+"upgrade" : ("user", "stamp",),
+"start"   : ("rev", "message", "stamp", "date", "user", "dirty",),
+"finish"  : ("commit", "message", "stamp", "date", "user", "erase", "onstream",),
 "list"    : ("closed",),
 "log"     : ("file", "date", "user", "keyword", "patch", "git", "limit", "graph", "closed", "onstream",),
-"abort"   : ("erase", "message", "onstream",),
-"promote" : ("rev", "message", "tag", "date", "user", "onstream",),
-"rebase"  : ("dest", "onstream",),
+"abort"   : ("erase", "message", "stamp", "onstream",),
+"promote" : ("rev", "message", "stamp", "tag", "date", "user", "onstream",),
+"rebase"  : ("dest", "onstream", "stamp",),
 }
 
 OPT_CONFLICT = {
 "date"   : ("-d", '',   ),
 "closed" : ("-c", False,),
 "commit" : ("-c", False,),
+"stamp"  : ("-p", ''    ),
+"patch"  : ("-p", False ),
 }
 
 def _getopt( ui, key, opt ) :
       ("k", "keyword",   '',    _("Do case-insensitive search for a given text. [log]"),                 _('TEXT'),),
       ("l", "limit",     '',    _("Limit number of changesets displayed. [log]"),                                  ),
       ("m", "message",   '',    _("Record TEXT as commit message. [start, finish, promote, abort]"),     _('TEXT'),),
+      ("p", "stamp",     '',    _("Append TEXT to all commit messages. [init, upgrade, start, finish,"
+                                  " promote, rebase, abort]"),                                           _('TEXT'),),
       ("p", "patch",     False, _("Show patch. [log]"),                                                            ),
       ("r", "rev",       '',    _("Revision to start a new branch from. [start]"),                       _('REV'), ),
       ("r", "rev",       '',    _("Revision to promote to other branches. [promote]"),                   _('REV'), ),
       ("s", "onstream",  False, _("Act on stream. [finish, rebase, log, abort]"),                                  ),
       ("t", "tag",       '',    _("Tag the merging changeset with NAME. [promote]"),                     _('NAME'),),
-      ("u", "user",      '',    _("Use specified user as committer. [init, start, finish, promote]"),    _('USER'),),
+      ("u", "user",      '',    _("Use specified user as committer. [init, upgrade, start, finish,"
+                                  " promote]"),                                                          _('USER'),),
       ("u", "user",      '',    _("Show revisions committed by specified user. [log]"),                  _('USER'),),
      ],
      "hg flow {<stream> [<action> [<arg>]] | <command>} [<option>...]",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.