Patchwork [3,of,7] color: move git-subrepo support into the subrepo module

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 25, 2017, 1:11 p.m.
Message ID <81c3db1bc60255c7a5a1.1488028295@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18784/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 25, 2017, 1:11 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1487695804 -3600
#      Tue Feb 21 17:50:04 2017 +0100
# Node ID 81c3db1bc60255c7a5a1455106f4fb69b96b3658
# Parent  03ad2d8bdc83713c1aee2ac729c4710c3bcd06a2
# EXP-Topic color
color: move git-subrepo support into the subrepo module

Now that all ui instance carry a '_colormode' attribute, we can access and
comply to it directly in the subrepo code. The actual implementation could
probably be a bit smarter, but we stick close to the current one for the sake
of simplicity.
Yuya Nishihara - Feb. 27, 2017, 2:39 p.m.
On Sat, 25 Feb 2017 14:11:35 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1487695804 -3600
> #      Tue Feb 21 17:50:04 2017 +0100
> # Node ID 81c3db1bc60255c7a5a1455106f4fb69b96b3658
> # Parent  03ad2d8bdc83713c1aee2ac729c4710c3bcd06a2
> # EXP-Topic color
> color: move git-subrepo support into the subrepo module

> --- a/mercurial/subrepo.py	Thu Dec 22 14:30:46 2016 +0100
> +++ b/mercurial/subrepo.py	Tue Feb 21 17:50:04 2017 +0100
> @@ -1410,6 +1410,10 @@ class gitsubrepo(abstractsubrepo):
>          errpipe = None
>          if self.ui.quiet:
>              errpipe = open(os.devnull, 'w')
> +        if self.ui._colormode and len(commands) and commands[0] == "diff":
> +                # insert the argument in the front,
> +                # the end of git diff arguments is used for paths
> +                commands.insert(1, '--color')

Fixed excessive indent in flight.

Patch

diff -r 03ad2d8bdc83 -r 81c3db1bc602 hgext/color.py
--- a/hgext/color.py	Thu Dec 22 14:30:46 2016 +0100
+++ b/hgext/color.py	Tue Feb 21 17:50:04 2017 +0100
@@ -177,7 +177,6 @@  from mercurial import (
     commands,
     dispatch,
     extensions,
-    subrepo,
     ui as uimod,
 )
 
@@ -198,14 +197,7 @@  def uisetup(ui):
         if mode and mode != 'debug':
             color.configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
-    def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
-        if gitsub.ui._colormode and len(commands) and commands[0] == "diff":
-                # insert the argument in the front,
-                # the end of git diff arguments is used for paths
-                commands.insert(1, '--color')
-        return orig(gitsub, commands, env, stream, cwd)
     extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
-    extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit)
 
 def extsetup(ui):
     commands.globalopts.append(
diff -r 03ad2d8bdc83 -r 81c3db1bc602 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Thu Dec 22 14:30:46 2016 +0100
+++ b/mercurial/subrepo.py	Tue Feb 21 17:50:04 2017 +0100
@@ -1410,6 +1410,10 @@  class gitsubrepo(abstractsubrepo):
         errpipe = None
         if self.ui.quiet:
             errpipe = open(os.devnull, 'w')
+        if self.ui._colormode and len(commands) and commands[0] == "diff":
+                # insert the argument in the front,
+                # the end of git diff arguments is used for paths
+                commands.insert(1, '--color')
         p = subprocess.Popen([self._gitexecutable] + commands, bufsize=-1,
                              cwd=cwd, env=env, close_fds=util.closefds,
                              stdout=subprocess.PIPE, stderr=errpipe)