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

login
register
mail settings
Submitter Alexander Drozdov
Date Feb. 17, 2014, 3:29 a.m.
Message ID <3dc40b4b56301758c818.1392607777@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/3683/
State Accepted
Commit a8aa699a812a3a2f97bf4195e7a6fdf963399c0c
Headers show

Comments

Alexander Drozdov - Feb. 17, 2014, 3:29 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 3dc40b4b56301758c818e374df04af72f36bb7de
# Parent  5d444f429e90fda0290d8c57287420fdde3cb2c8
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)