ui: allow open editor with custom filename
By default, editor will use temp file named after hard-coded pattern
'hg-editor-XXX.txt' which makes it impossible for extensions to use
another filename if desired.
Now the middle part of the pattern ('editor') can be changed by
setting extra['prefix'].
--- a/mercurial/ui.py Mon Nov 30 20:45:07 2015 +0000
+++ b/mercurial/ui.py Sat Nov 21 22:04:09 2015 +0200
@@ -846,10 +846,12 @@
self.write(*msg, **opts)
def edit(self, text, user, extra=None, editform=None, pending=None):
- if extra is None:
- extra = {}
- (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt",
- text=True)
+ extra_defaults = { 'prefix': 'editor' }
+ if extra is not None:
+ extra_defaults.update(extra)
+ extra = extra_defaults
+ (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-',
+ suffix=".txt", text=True)
try:
f = os.fdopen(fd, "w")
f.write(text)