Patchwork color: add support for colorizing git subrepo diffs

login
register
mail settings
Submitter Mathias De Maré
Date Jan. 8, 2015, 8:33 p.m.
Message ID <a80a1e66eefc6431e37e.1420749205@mathias-Latitude-E6540>
Download mbox | patch
Permalink /patch/7386/
State Accepted
Headers show

Comments

Mathias De Maré - Jan. 8, 2015, 8:33 p.m.
# HG changeset patch
# User Mathias De Maré <mathias.demare@gmail.com>
# Date 1420749022 -3600
#      Don Jan 08 21:30:22 2015 +0100
# Node ID a80a1e66eefc6431e37e382a5761d8296be7a481
# Parent  7ad155e13f0f51df8e986a0ec4e58ac9a0ccedbb
color: add support for colorizing git subrepo diffs
Sean Farley - Jan. 8, 2015, 9:35 p.m.
Mathias De Maré writes:

> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1420749022 -3600
> #      Don Jan 08 21:30:22 2015 +0100
> # Node ID a80a1e66eefc6431e37e382a5761d8296be7a481
> # Parent  7ad155e13f0f51df8e986a0ec4e58ac9a0ccedbb
> color: add support for colorizing git subrepo diffs
>
> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -144,7 +144,7 @@ codes).
>  
>  import os
>  
> -from mercurial import cmdutil, commands, dispatch, extensions, ui as uimod, util
> +from mercurial import cmdutil, commands, dispatch, extensions, subrepo, ui as uimod, util
>  from mercurial import templater, error
>  from mercurial.i18n import _
>  
> @@ -488,7 +488,15 @@ def uisetup(ui):
>              extstyles()
>              configstyles(ui_)
>          return orig(ui_, opts, cmd, cmdfunc)
> +    def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
> +        if gitsub.ui._colormode:
> +            if len(commands) and commands[0] == "diff":

Small nit: this could be written as 'if gitsub.ui._colormode and command
and commands[0] == "diff"' to save a level of indentation. Not really a
show stopper though.
Pierre-Yves David - Jan. 9, 2015, 5:31 a.m.
On 01/08/2015 01:35 PM, Sean Farley wrote:
>
> Mathias De Maré writes:
>
>> # HG changeset patch
>> # User Mathias De Maré <mathias.demare@gmail.com>
>> # Date 1420749022 -3600
>> #      Don Jan 08 21:30:22 2015 +0100
>> # Node ID a80a1e66eefc6431e37e382a5761d8296be7a481
>> # Parent  7ad155e13f0f51df8e986a0ec4e58ac9a0ccedbb
>> color: add support for colorizing git subrepo diffs
>>
>> diff --git a/hgext/color.py b/hgext/color.py
>> --- a/hgext/color.py
>> +++ b/hgext/color.py
>> @@ -144,7 +144,7 @@ codes).
>>
>>   import os
>>
>> -from mercurial import cmdutil, commands, dispatch, extensions, ui as uimod, util
>> +from mercurial import cmdutil, commands, dispatch, extensions, subrepo, ui as uimod, util
>>   from mercurial import templater, error
>>   from mercurial.i18n import _
>>
>> @@ -488,7 +488,15 @@ def uisetup(ui):
>>               extstyles()
>>               configstyles(ui_)
>>           return orig(ui_, opts, cmd, cmdfunc)
>> +    def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
>> +        if gitsub.ui._colormode:
>> +            if len(commands) and commands[0] == "diff":
>
> Small nit: this could be written as 'if gitsub.ui._colormode and command
> and commands[0] == "diff"' to save a level of indentation. Not really a
> show stopper though.

I've folded the conditional and the result is pushed to the clowncopter.
Matt Mackall - Jan. 9, 2015, 7:44 p.m.
On Thu, 2015-01-08 at 21:33 +0100, Mathias De Maré wrote:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1420749022 -3600
> #      Don Jan 08 21:30:22 2015 +0100
> # Node ID a80a1e66eefc6431e37e382a5761d8296be7a481
> # Parent  7ad155e13f0f51df8e986a0ec4e58ac9a0ccedbb
> color: add support for colorizing git subrepo diffs

Do Mercurial's default color choices agree with git's here?
Mathias De Maré - Jan. 9, 2015, 8:37 p.m.
On Fri, Jan 9, 2015 at 8:44 PM, Matt Mackall <mpm@selenic.com> wrote:

> On Thu, 2015-01-08 at 21:33 +0100, Mathias De Maré wrote:
> > # HG changeset patch
> > # User Mathias De Maré <mathias.demare@gmail.com>
> > # Date 1420749022 -3600
> > #      Don Jan 08 21:30:22 2015 +0100
> > # Node ID a80a1e66eefc6431e37e382a5761d8296be7a481
> > # Parent  7ad155e13f0f51df8e986a0ec4e58ac9a0ccedbb
> > color: add support for colorizing git subrepo diffs
>
> Do Mercurial's default color choices agree with git's here?
>
Partially: the added and removed lines match (green/red), the 'diff --git'
line is bold as well.
Mismatches I see are the following:
- The hunk prefix (it's magenta for Mercurial, cyan for Git)
- diff.file_a and diff.file_b (red, green and bold for Mercurial, white and
bold for Git)


> --
> Mathematics is the supreme nostalgia of our time.
>
>
>

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -144,7 +144,7 @@  codes).
 
 import os
 
-from mercurial import cmdutil, commands, dispatch, extensions, ui as uimod, util
+from mercurial import cmdutil, commands, dispatch, extensions, subrepo, ui as uimod, util
 from mercurial import templater, error
 from mercurial.i18n import _
 
@@ -488,7 +488,15 @@  def uisetup(ui):
             extstyles()
             configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
+    def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
+        if gitsub.ui._colormode:
+            if 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):