context: move editor invocation from "makememctx()" to "memctx.__init__()"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 05 May 2014 21:26:40 +0900
changeset 21238 25d6fdc0294a
parent 21237 0054a77f49df
child 21239 19d98da5c018
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.
mercurial/context.py
--- a/mercurial/context.py	Mon May 05 21:26:40 2014 +0900
+++ b/mercurial/context.py	Mon May 05 21:26:40 2014 +0900
@@ -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]) + "+"