[PATCH] color: enabled color support for export command (issue1507)

Ankur Dahiya ankurd at fb.com
Fri Aug 31 05:03:02 CDT 2012


On 8/30/12 10:25 PM, "Matt Mackall" <mpm at selenic.com> wrote:

>On Thu, 2012-08-30 at 03:57 -0700, Ankur Dahiya wrote:
>> # HG changeset patch
>> # User Ankur Dahiya <ankurd at fb.com>
>> # Date 1346085469 25200
>> # Node ID decb610de84f84e9de32ba3a8073eeb2235496a6
>> # Parent  99a2a4ae35e2180b7f825ef2677c36d538eac4ba
>> color: enabled color support for export command (issue1507)
>> 
>> The export command didn't output the diffs in color, even when color
>>support
>> was enabled. This patch fixes that by making the export command use the
>>default
>> ui.write method, instead of directly manipulating the ui.fout file
>>object.
>> Also added a test case to verify color output to test-export.t.
>
>I guess this is ok. Historically, 'hg export' exists to work with
>'patch' or 'hg import', being pretty is not a goal. But I guess I
>occasionally use 'hg export' to look at patches rather than 'hg log
>-vpr'.
>
>> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
>> --- a/mercurial/cmdutil.py
>> +++ b/mercurial/cmdutil.py
>> @@ -547,30 +547,37 @@
>>          prev = (parents and parents[0]) or nullid
>>  
>>          shouldclose = False
>> -        if not fp:
>> +        if not fp and len(template) > 0:
>
>I can't tell if this change has a purpose, as it isn't mentioned in
>$DESC.

If there is no template, we know that output is going to stdout, so we
don't need to create a fileobject, instead we use repo.ui.write (look at
cmdutil.py:560).

>
>>              desc_lines = ctx.description().rstrip().split('\n')
>>              desc = desc_lines[0]    #Commit always has a first line.
>>              fp = makefileobj(repo, template, node, desc=desc,
>>total=total,
>>                               seqno=seqno, revwidth=revwidth, mode='ab')
>>              if fp != template:
>>                  shouldclose = True
>> -        if fp != sys.stdout and util.safehasattr(fp, 'name'):
>> +        if fp and fp != sys.stdout and util.safehasattr(fp, 'name'):
>
>Same here.

Here also, if we don't have a fileobject, we don't need to do this.
Both the above changes are to ensure that we get fp==None at
cmdutil.py:560.

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

Ankur Dahiya



More information about the Mercurial-devel mailing list