mercurial/cmdutil.py
changeset 21924 5375ba75df40
parent 21923 e582e20cd3e6
child 21944 0483ff40e326
equal deleted inserted replaced
21923:e582e20cd3e6 21924:5375ba75df40
  2171     return commitforceeditor(repo, ctx, subs)
  2171     return commitforceeditor(repo, ctx, subs)
  2172 
  2172 
  2173 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
  2173 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
  2174     if not extramsg:
  2174     if not extramsg:
  2175         extramsg = _("Leave message empty to abort commit.")
  2175         extramsg = _("Leave message empty to abort commit.")
  2176     committext = buildcommittext(repo, ctx, subs, extramsg)
  2176     tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
       
  2177     if tmpl:
       
  2178         committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
       
  2179     else:
       
  2180         committext = buildcommittext(repo, ctx, subs, extramsg)
  2177 
  2181 
  2178     # run editor in the repository root
  2182     # run editor in the repository root
  2179     olddir = os.getcwd()
  2183     olddir = os.getcwd()
  2180     os.chdir(repo.root)
  2184     os.chdir(repo.root)
  2181     text = repo.ui.edit(committext, ctx.user(), ctx.extra())
  2185     text = repo.ui.edit(committext, ctx.user(), ctx.extra())
  2186         text = finishdesc(text)
  2190         text = finishdesc(text)
  2187     if not text.strip():
  2191     if not text.strip():
  2188         raise util.Abort(_("empty commit message"))
  2192         raise util.Abort(_("empty commit message"))
  2189 
  2193 
  2190     return text
  2194     return text
       
  2195 
       
  2196 def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
       
  2197     ui = repo.ui
       
  2198     tmpl, mapfile = gettemplate(ui, tmpl, None)
       
  2199 
       
  2200     try:
       
  2201         t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False)
       
  2202     except SyntaxError, inst:
       
  2203         raise util.Abort(inst.args[0])
       
  2204 
       
  2205     if not extramsg:
       
  2206         extramsg = '' # ensure that extramsg is string
       
  2207 
       
  2208     ui.pushbuffer()
       
  2209     t.show(ctx, extramsg=extramsg)
       
  2210     return ui.popbuffer()
  2191 
  2211 
  2192 def buildcommittext(repo, ctx, subs, extramsg):
  2212 def buildcommittext(repo, ctx, subs, extramsg):
  2193     edittext = []
  2213     edittext = []
  2194     modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
  2214     modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
  2195     if ctx.description():
  2215     if ctx.description():