color: add support for colorizing git subrepo diffs
authorMathias De Maré <mathias.demare@gmail.com>
Thu, 08 Jan 2015 21:30:22 +0100
changeset 23780 a857755144dc
parent 23779 427b8728536f
child 23781 49caef455912
color: add support for colorizing git subrepo diffs
hgext/color.py
--- a/hgext/color.py	Thu Jan 08 23:33:56 2015 -0500
+++ b/hgext/color.py	Thu Jan 08 21:30:22 2015 +0100
@@ -144,7 +144,8 @@
 
 import os
 
-from mercurial import cmdutil, commands, dispatch, extensions, ui as uimod, util
+from mercurial import cmdutil, commands, dispatch, extensions, subrepo, util
+from mercurial import ui as uimod
 from mercurial import templater, error
 from mercurial.i18n import _
 
@@ -488,7 +489,14 @@
             extstyles()
             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)
     templater.funcs['label'] = templatelabel
 
 def extsetup(ui):