Patchwork [1,of,2] cmdutil: separate building commit text from 'commitforceeditor'

login
register
mail settings
Submitter Katsunori FUJIWARA
Date July 14, 2014, 4:31 p.m.
Message ID <f5df6f7bf9a04559b31d.1405355478@feefifofum>
Download mbox | patch
Permalink /patch/5162/
State Accepted
Commit e353fac7db2633c59d29a5059a08830a498aea49
Headers show

Comments

Katsunori FUJIWARA - July 14, 2014, 4:31 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1405353549 -32400
#      Tue Jul 15 00:59:09 2014 +0900
# Node ID f5df6f7bf9a04559b31df62592244209d90e79ab
# Parent  ba3bc6474bbf3a29e5fa16d13ff44b9c0848043c
cmdutil: separate building commit text from 'commitforceeditor'

This separation makes it easier to extend/hook building commit text
from the specified context.

This patch uses 'committext' instead of 'edittext' for names of newly
added variable and function, because the former is more purpose
specific than the latter, even though 'edittext' in 'buildcommittext'
is left as it is to reduce amount of diff.
Matt Mackall - July 14, 2014, 10:36 p.m.
On Tue, 2014-07-15 at 01:31 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1405353549 -32400
> #      Tue Jul 15 00:59:09 2014 +0900
> # Node ID f5df6f7bf9a04559b31df62592244209d90e79ab
> # Parent  ba3bc6474bbf3a29e5fa16d13ff44b9c0848043c
> cmdutil: separate building commit text from 'commitforceeditor'

Queued for default, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2170,6 +2170,23 @@ 
     return commitforceeditor(repo, ctx, subs)
 
 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
+    committext = buildcommittext(repo, ctx, subs, extramsg)
+
+    # run editor in the repository root
+    olddir = os.getcwd()
+    os.chdir(repo.root)
+    text = repo.ui.edit(committext, ctx.user(), ctx.extra())
+    text = re.sub("(?m)^HG:.*(\n|$)", "", text)
+    os.chdir(olddir)
+
+    if finishdesc:
+        text = finishdesc(text)
+    if not text.strip():
+        raise util.Abort(_("empty commit message"))
+
+    return text
+
+def buildcommittext(repo, ctx, subs, extramsg):
     edittext = []
     modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
     if ctx.description():
@@ -2197,19 +2214,8 @@ 
     if not added and not modified and not removed:
         edittext.append(_("HG: no files changed"))
     edittext.append("")
-    # run editor in the repository root
-    olddir = os.getcwd()
-    os.chdir(repo.root)
-    text = repo.ui.edit("\n".join(edittext), ctx.user(), ctx.extra())
-    text = re.sub("(?m)^HG:.*(\n|$)", "", text)
-    os.chdir(olddir)
 
-    if finishdesc:
-        text = finishdesc(text)
-    if not text.strip():
-        raise util.Abort(_("empty commit message"))
-
-    return text
+    return "\n".join(edittext)
 
 def commitstatus(repo, node, branch, bheads=None, opts={}):
     ctx = repo[node]