comparison mercurial/context.py @ 21238:25d6fdc0294a

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 05 May 2014 21:26:40 +0900
parents 9f12d8665c7b
children a45af4da0421
comparison
equal deleted inserted replaced
21237:0054a77f49df 21238:25d6fdc0294a
206 copied=copied) 206 copied=copied)
207 extra = {} 207 extra = {}
208 if branch: 208 if branch:
209 extra['branch'] = encoding.fromlocal(branch) 209 extra['branch'] = encoding.fromlocal(branch)
210 ctx = memctx(repo, parents, text, files, getfilectx, user, 210 ctx = memctx(repo, parents, text, files, getfilectx, user,
211 date, extra) 211 date, extra, editor)
212 if editor:
213 ctx._text = editor(repo, ctx, [])
214 return ctx 212 return ctx
215 213
216 class changectx(basectx): 214 class changectx(basectx):
217 """A changecontext object makes access to data related to a particular 215 """A changecontext object makes access to data related to a particular
218 changeset convenient. It represents a read-only context already present in 216 changeset convenient. It represents a read-only context already present in
1285 repository username, date is the commit date in any format 1283 repository username, date is the commit date in any format
1286 supported by util.parsedate() and defaults to current date, extra 1284 supported by util.parsedate() and defaults to current date, extra
1287 is a dictionary of metadata or is left empty. 1285 is a dictionary of metadata or is left empty.
1288 """ 1286 """
1289 def __init__(self, repo, parents, text, files, filectxfn, user=None, 1287 def __init__(self, repo, parents, text, files, filectxfn, user=None,
1290 date=None, extra=None): 1288 date=None, extra=None, editor=False):
1291 self._repo = repo 1289 self._repo = repo
1292 self._rev = None 1290 self._rev = None
1293 self._node = None 1291 self._node = None
1294 self._text = text 1292 self._text = text
1295 self._date = date and util.parsedate(date) or util.makedate() 1293 self._date = date and util.parsedate(date) or util.makedate()
1302 self._filectxfn = filectxfn 1300 self._filectxfn = filectxfn
1303 1301
1304 self._extra = extra and extra.copy() or {} 1302 self._extra = extra and extra.copy() or {}
1305 if self._extra.get('branch', '') == '': 1303 if self._extra.get('branch', '') == '':
1306 self._extra['branch'] = 'default' 1304 self._extra['branch'] = 'default'
1305
1306 if editor:
1307 self._text = editor(self._repo, self, [])
1308 self._repo.savecommitmessage(self._text)
1307 1309
1308 def __str__(self): 1310 def __str__(self):
1309 return str(self._parents[0]) + "+" 1311 return str(self._parents[0]) + "+"
1310 1312
1311 def __int__(self): 1313 def __int__(self):