# HG changeset patch # User FUJIWARA Katsunori # Date 2014-05-05 12:26:40 # Node ID 25d6fdc0294a5d6accabc7696cb97a0569688ae9 # Parent 0054a77f49df42a714eeb2a11596ab7bc9724083 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. diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -208,9 +208,7 @@ def makememctx(repo, parents, text, user 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 @@ class memctx(object): 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 @@ class memctx(object): 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]) + "+"