[PATCH 2 of 6] branches: format rev as integer that is necessary for generic templater

Mads Kiilerich mads at kiilerich.com
Thu Oct 2 13:19:39 CDT 2014


On 10/02/2014 05:50 PM, Yuya Nishihara wrote:
> On Thu, 02 Oct 2014 17:23:32 +0200, Mads Kiilerich wrote:
>> On 10/02/2014 04:59 PM, Yuya Nishihara wrote:
>>> # HG changeset patch
>>> # User Yuya Nishihara <yuya at tcha.org>
>>> # Date 1412255739 -32400
>>> #      Thu Oct 02 22:15:39 2014 +0900
>>> # Node ID 04e13b88d3b047406ca954fbb79de228874817eb
>>> # Parent  4ec9dd1b52889c73bbf39159222a161e4374cd4a
>>> branches: format rev as integer that is necessary for generic templater
>>>
>>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>>> --- a/mercurial/commands.py
>>> +++ b/mercurial/commands.py
>>> @@ -1119,8 +1119,10 @@ def branches(ui, repo, active=False, clo
>>>                notice = _(' (inactive)')
>>>            if tag == repo.dirstate.branch():
>>>                label = 'branches.current'
>>> -        rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag))
>>> -        rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())),
>>> +        rev = ctx.rev()
>>> +        fmt = ' ' * max(31 - len(str(rev)) - encoding.colwidth(tag), 0)
>>> +        fmt += '%d:%s'
>> I think it is sad that our 80 characters line limit cause us to spend
>> extra cpu cycles. It will not make a real difference here but it just
>> feels wrong. I have a hard time trying to understand how this can be
>> more readable than a multi line statement.
> Ok, I'll do
>
>    padsize = ...
>    fmt = ' ' * padsize + '%d:%s'

Grumpy me also dislikes introducing extra name bindings just to get 
short lines. In this case the padsize is a welldefined concept and 
naming it serves as documentation, so in this case it isn't that bad.

Others might however love both this and your initial proposal. Pleasing 
everybody will be hard. Do what you think is right and fight for it ;-)

/Mads



More information about the Mercurial-devel mailing list