[PATCH] changegroup: do not prompt to merge after adding only closed heads (issue2697)

Wagner Bruna wagner.bruna+mercurial at gmail.com
Fri Apr 15 11:35:21 CDT 2011


On 04/14/2011 03:31 PM, Kevin Gessner wrote:
> # HG changeset patch
> # User Kevin Gessner <kevin at fogcreek.com>
> # Date 1302729493 14400
> # Node ID 9afc365d6c2a351d01d6ae18021fc67c45ceb139
> # Parent  3d83c7d70a98a1fd4ff1ad4f840c8ce82100bfdb
> changegroup: do not prompt to merge after adding only closed heads (issue2697)
> 
> When adding a changegroup adds closed heads, note them in the "(+n heads)"
> alert. Don't count them in the total number of heads for the note to merge
> or update.
> 
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1691,6 +1691,8 @@
>          cl = self.changelog
>          cl.delayupdate()
>          oldheads = len(cl.heads())
> +        oldclosedheads = len([h for h in cl.heads()
> +                              if 'close' in self[h].extra()])
>  
>          tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)]))
>          try:
> @@ -1782,9 +1784,18 @@
>                              (f, hex(n)))
>  
>              newheads = len(cl.heads())
> +            newclosedheads = len([h for h in cl.heads()
> +                                  if 'close' in self[h].extra()])
> +            closingheads = max(0, newclosedheads - oldclosedheads)
>              heads = ""
>              if oldheads and newheads != oldheads:
> -                heads = _(" (%+d heads)") % (newheads - oldheads)
> +                closedheads = ""
> +                if closingheads:
> +                    closedheads = _(", %d closed") % closingheads
> +                heads = _(" (%+d heads%s)") % ((newheads - oldheads),
> +                                               closedheads)

Please avoid joining translated messages like this: some languages may need a
different phrase structure (see [1]). It's better to mark whole sentences:

if closingheads:
    heads = _(" (%+d heads, %d closed") % (
                (newheads - oldheads), closingheads)
else:
    heads = _(" (%+d heads)") % (newheads - oldheads)

Of course, by the same reasoning we should translate this part together with
the message beginning. But arguably the parenthesis themselves break the
phrase structure, so IMHO we may let it like this to avoid cluttering the code
too much.

Regards,
Wagner

[1]: http://www.gnu.org/software/gettext/manual/gettext.html#Preparing-Strings

> +            oldheads -= oldclosedheads
> +            newheads -= newclosedheads
>  
>              self.ui.status(_("added %d changesets"
>                               " with %d changes to %d files%s\n")


More information about the Mercurial-devel mailing list