Patchwork [3,of,4] ui: edit(): rebase, graft: set HGREVISION environment variable for an editor

login
register
mail settings
Submitter Alexander Drozdov
Date Feb. 10, 2014, 3:18 a.m.
Message ID <e74e44b95b9986dec38f.1392002292@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/3536/
State Superseded
Headers show

Comments

Alexander Drozdov - Feb. 10, 2014, 3:18 a.m.
# HG changeset patch
# User Alexander Drozdov <al.drozdov@gmail.com>
# Date 1391674880 -14400
#      Thu Feb 06 12:21:20 2014 +0400
# Node ID e74e44b95b9986dec38ff5ac1e64464a1c416e1d
# Parent  fb0f7ae8687fc32722802e0120026e3995b79c2f
ui: edit(): rebase, graft: set HGREVISION environment variable for an editor

rebase and graft commands set 'rebase_source' or 'source' extras for the revision.
Allow an editor to access the extras using HGREVISION environment variable.

This may be useful when an editor is actually a script which modifies a commit
message.

The name 'HGREVISION' has been selected as transplant already sets this variable
for its filters (--filter).

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -720,10 +720,16 @@ 
             f.write(text)
             f.close()
 
+            environ = {'HGUSER': user}
+            for label in ('source', 'rebase_source'):
+                if label in extra:
+                    environ.update({'HGREVISION': extra[label]})
+                    break
+
             editor = self.geteditor()
 
             util.system("%s \"%s\"" % (editor, name),
-                        environ={'HGUSER': user},
+                        environ=environ,
                         onerr=util.Abort, errprefix=_("edit failed"),
                         out=self.fout)