mercurial/cmdutil.py
changeset 26742 bec1a579ebc4
parent 26639 92d67e5729b9
child 26746 3c1d297fe929
equal deleted inserted replaced
26741:e1568d5eb052 26742:bec1a579ebc4
  2689     return newid
  2689     return newid
  2690 
  2690 
  2691 def commiteditor(repo, ctx, subs, editform=''):
  2691 def commiteditor(repo, ctx, subs, editform=''):
  2692     if ctx.description():
  2692     if ctx.description():
  2693         return ctx.description()
  2693         return ctx.description()
  2694     return commitforceeditor(repo, ctx, subs, editform=editform)
  2694     return commitforceeditor(repo, ctx, subs, editform=editform,
       
  2695                              unchangedmessagedetection=True)
  2695 
  2696 
  2696 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
  2697 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
  2697                       editform=''):
  2698                       editform='', unchangedmessagedetection=False):
  2698     if not extramsg:
  2699     if not extramsg:
  2699         extramsg = _("Leave message empty to abort commit.")
  2700         extramsg = _("Leave message empty to abort commit.")
  2700 
  2701 
  2701     forms = [e for e in editform.split('.') if e]
  2702     forms = [e for e in editform.split('.') if e]
  2702     forms.insert(0, 'changeset')
  2703     forms.insert(0, 'changeset')
       
  2704     templatetext = None
  2703     while forms:
  2705     while forms:
  2704         tmpl = repo.ui.config('committemplate', '.'.join(forms))
  2706         tmpl = repo.ui.config('committemplate', '.'.join(forms))
  2705         if tmpl:
  2707         if tmpl:
  2706             committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
  2708             templatetext = committext = buildcommittemplate(
       
  2709                 repo, ctx, subs, extramsg, tmpl)
  2707             break
  2710             break
  2708         forms.pop()
  2711         forms.pop()
  2709     else:
  2712     else:
  2710         committext = buildcommittext(repo, ctx, subs, extramsg)
  2713         committext = buildcommittext(repo, ctx, subs, extramsg)
  2711 
  2714 
  2712     # run editor in the repository root
  2715     # run editor in the repository root
  2713     olddir = os.getcwd()
  2716     olddir = os.getcwd()
  2714     os.chdir(repo.root)
  2717     os.chdir(repo.root)
  2715     text = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform)
  2718     editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
  2716     text = re.sub("(?m)^HG:.*(\n|$)", "", text)
  2719                               editform=editform)
       
  2720 
       
  2721     text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
  2717     os.chdir(olddir)
  2722     os.chdir(olddir)
  2718 
  2723 
  2719     if finishdesc:
  2724     if finishdesc:
  2720         text = finishdesc(text)
  2725         text = finishdesc(text)
  2721     if not text.strip():
  2726     if not text.strip():
  2722         raise error.Abort(_("empty commit message"))
  2727         raise error.Abort(_("empty commit message"))
       
  2728     if unchangedmessagedetection and editortext == templatetext:
       
  2729         raise error.Abort(_("commit message unchanged"))
  2723 
  2730 
  2724     return text
  2731     return text
  2725 
  2732 
  2726 def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
  2733 def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
  2727     ui = repo.ui
  2734     ui = repo.ui