ui: add a parameter to set the temporary directory for edit
authorSean Farley <sean@farley.io>
Mon, 16 Jan 2017 21:05:22 -0800
changeset 30835 bcad61a1f9a7
parent 30834 64a9160bf150
child 30836 565c07036066
ui: add a parameter to set the temporary directory for edit Until callsites are updated, this will have no effect. Once callsites are updated, specifying experimental.editortmpinhg will create editor temporary files in a subdirectory of .hg, which will make it easier for tool integrations to determine what repository is in play when they're asked to edit an hg-related file.
mercurial/ui.py
--- a/mercurial/ui.py	Wed Jan 18 03:44:19 2017 +0530
+++ b/mercurial/ui.py	Mon Jan 16 21:05:22 2017 -0800
@@ -1021,7 +1021,8 @@
             opts['label'] = opts.get('label', '') + ' ui.debug'
             self.write(*msg, **opts)
 
-    def edit(self, text, user, extra=None, editform=None, pending=None):
+    def edit(self, text, user, extra=None, editform=None, pending=None,
+             tmpdir=None):
         extra_defaults = {
             'prefix': 'editor',
             'suffix': '.txt',
@@ -1029,8 +1030,13 @@
         if extra is not None:
             extra_defaults.update(extra)
         extra = extra_defaults
+
+        tdir = None
+        if self.configbool('experimental', 'editortmpinhg'):
+            tdir = tmpdir
         (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-',
-                                      suffix=extra['suffix'], text=True)
+                                      suffix=extra['suffix'], text=True,
+                                      dir=tdir)
         try:
             f = os.fdopen(fd, "w")
             f.write(text)