Patchwork [3,of,6] ui: invoke external process with HG_PENDING if transaction is active

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 14, 2015, 5:35 p.m.
Message ID <2b4f221f324532e3451c.1444844118@feefifofum>
Download mbox | patch
Permalink /patch/11064/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Oct. 14, 2015, 5:35 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1444843899 -32400
#      Thu Oct 15 02:31:39 2015 +0900
# Node ID 2b4f221f324532e3451c626c153e2b8353cd88bc
# Parent  795039426542deb61dd1ae0b75cebe02c0eebfe3
ui: invoke external process with HG_PENDING if transaction is active

This can centralize passing HG_PENDING to external process into
'ui.system()'.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -869,13 +869,26 @@ 
 
         return t
 
-    def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None):
+    def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None,
+               repo=None):
         '''execute shell command with appropriate output stream. command
         output will be redirected if fout is not stdout.
+
+        If 'repo' is specified, external command is executed with
+        'HG_PENDING' environment variable according to current
+        transaction activity.
         '''
         out = self.fout
         if any(s[1] for s in self._bufferstates):
             out = self
+
+        if repo:
+            repo.dirstate.write(repo)
+            tr = repo.currenttransaction()
+            if tr and tr.writepending():
+                environ = environ.copy() # to avoid changing specified dict
+                environ['HG_PENDING'] = repo.root
+
         return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
                            errprefix=errprefix, out=out)