Patchwork [6,of,9] context: move editor invocation from "makememctx()" to "memctx.__init__()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 5, 2014, 12:33 p.m.
Message ID <cd4a83a83ed9f038645c.1399293186@feefifofum>
Download mbox | patch
Permalink /patch/4637/
State Accepted
Commit 25d6fdc0294a5d6accabc7696cb97a0569688ae9
Headers show

Comments

Katsunori FUJIWARA - May 5, 2014, 12:33 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1399292800 -32400
#      Mon May 05 21:26:40 2014 +0900
# Branch stable
# Node ID cd4a83a83ed9f038645cdab9d710b3ca0a4eb481
# Parent  9152874122c6ff967387d38081aa87f5ed677654
context: move editor invocation from "makememctx()" to "memctx.__init__()"

This patch introduces "editor" argument to "memctx.__init__()", and
moves editor invocation from "makememctx()" to "memctx.__init__()", to
centralize editor invocation into "memctx" object creation.

This relocation is needed, because "makememctx()" requires the "store"
object providing "getfile()" to create "memfilectx" object, and this
prevents some code paths from using "makememctx()" instead of
"memctx.__init__()".

This patch also invokes "localrepository.savecommitmessage()", when
"editor" is specified explicitly, to centralize saving commit message
into "memctx" object creation: passing "cmdutil.commiteditor" as
"editor" can achieve both suppressing editor invocation and saving
into ".hg/last-message.txt" for non empty commit messages.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -208,9 +208,7 @@ 
     if branch:
         extra['branch'] = encoding.fromlocal(branch)
     ctx =  memctx(repo, parents, text, files, getfilectx, user,
-                          date, extra)
-    if editor:
-        ctx._text = editor(repo, ctx, [])
+                          date, extra, editor)
     return ctx
 
 class changectx(basectx):
@@ -1287,7 +1285,7 @@ 
     is a dictionary of metadata or is left empty.
     """
     def __init__(self, repo, parents, text, files, filectxfn, user=None,
-                 date=None, extra=None):
+                 date=None, extra=None, editor=False):
         self._repo = repo
         self._rev = None
         self._node = None
@@ -1305,6 +1303,10 @@ 
         if self._extra.get('branch', '') == '':
             self._extra['branch'] = 'default'
 
+        if editor:
+            self._text = editor(self._repo, self, [])
+            self._repo.savecommitmessage(self._text)
+
     def __str__(self):
         return str(self._parents[0]) + "+"