mercurial/cmdutil.py
changeset 21999 6ce282ed801e
parent 21998 739095270f48
child 22010 41e969cb9468
equal deleted inserted replaced
21998:739095270f48 21999:6ce282ed801e
   107         except IOError, inst:
   107         except IOError, inst:
   108             raise util.Abort(_("can't read commit message '%s': %s") %
   108             raise util.Abort(_("can't read commit message '%s': %s") %
   109                              (logfile, inst.strerror))
   109                              (logfile, inst.strerror))
   110     return message
   110     return message
   111 
   111 
   112 def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
   112 def getcommiteditor(edit=False, finishdesc=None, extramsg=None,
       
   113                     editform='', **opts):
   113     """get appropriate commit message editor according to '--edit' option
   114     """get appropriate commit message editor according to '--edit' option
   114 
   115 
   115     'finishdesc' is a function to be called with edited commit message
   116     'finishdesc' is a function to be called with edited commit message
   116     (= 'description' of the new changeset) just after editing, but
   117     (= 'description' of the new changeset) just after editing, but
   117     before checking empty-ness. It should return actual text to be
   118     before checking empty-ness. It should return actual text to be
   119     storing.
   120     storing.
   120 
   121 
   121     'extramsg' is a extra message to be shown in the editor instead of
   122     'extramsg' is a extra message to be shown in the editor instead of
   122     'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
   123     'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
   123     is automatically added.
   124     is automatically added.
       
   125 
       
   126     'editform' is a dot-separated list of names, to distinguish
       
   127     the purpose of commit text editing.
   124 
   128 
   125     'getcommiteditor' returns 'commitforceeditor' regardless of
   129     'getcommiteditor' returns 'commitforceeditor' regardless of
   126     'edit', if one of 'finishdesc' or 'extramsg' is specified, because
   130     'edit', if one of 'finishdesc' or 'extramsg' is specified, because
   127     they are specific for usage in MQ.
   131     they are specific for usage in MQ.
   128     """
   132     """
   129     if edit or finishdesc or extramsg:
   133     if edit or finishdesc or extramsg:
   130         return lambda r, c, s: commitforceeditor(r, c, s,
   134         return lambda r, c, s: commitforceeditor(r, c, s,
   131                                                  finishdesc=finishdesc,
   135                                                  finishdesc=finishdesc,
   132                                                  extramsg=extramsg)
   136                                                  extramsg=extramsg,
       
   137                                                  editform=editform)
       
   138     elif editform:
       
   139         return lambda r, c, s: commiteditor(r, c, s, editform=editform)
   133     else:
   140     else:
   134         return commiteditor
   141         return commiteditor
   135 
   142 
   136 def loglimit(opts):
   143 def loglimit(opts):
   137     """get the log limit according to option -l/--limit"""
   144     """get the log limit according to option -l/--limit"""
  2173         if newid is None:
  2180         if newid is None:
  2174             repo.dirstate.invalidate()
  2181             repo.dirstate.invalidate()
  2175         lockmod.release(lock, wlock)
  2182         lockmod.release(lock, wlock)
  2176     return newid
  2183     return newid
  2177 
  2184 
  2178 def commiteditor(repo, ctx, subs):
  2185 def commiteditor(repo, ctx, subs, editform=''):
  2179     if ctx.description():
  2186     if ctx.description():
  2180         return ctx.description()
  2187         return ctx.description()
  2181     return commitforceeditor(repo, ctx, subs)
  2188     return commitforceeditor(repo, ctx, subs, editform=editform)
  2182 
  2189 
  2183 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
  2190 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
       
  2191                       editform=''):
  2184     if not extramsg:
  2192     if not extramsg:
  2185         extramsg = _("Leave message empty to abort commit.")
  2193         extramsg = _("Leave message empty to abort commit.")
  2186     tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
  2194     tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
  2187     if tmpl:
  2195     if tmpl:
  2188         committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
  2196         committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)