[PATCH 02 of 12 V3] bookmarks: rewrite "updatefromremote()" by "compare()"

David Soria Parra dsp at experimentalworks.net
Wed Oct 2 10:55:03 CDT 2013


On 10/02/2013 04:38 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1380723659 -32400
> #      Wed Oct 02 23:20:59 2013 +0900
> # Node ID 1559588706e842780f2f54c488fde65bd1f188d2
> # Parent  47300b7a97837455ff54fb6c0488b687eb230d65
> bookmarks: rewrite "updatefromremote()" by "compare()"
> 
> To update entries in bmstore "localmarks", this patch uses
> "bin(changesetid)" instead of "repo[changesetid].node()" used in
> original "updatefromremote()" implementation, because the former is
> cheaper than the latter.
> 
> This patch also changes order of updating bookmarks. Before this
> patch, bookmarks are updated completely in order of their name. After
> this patch, adding new bookmarks, updating existing bookmarks and
> creating divergent bookmarks are executed in this order.
> 
> diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
> --- a/mercurial/bookmarks.py
> +++ b/mercurial/bookmarks.py
> @@ -6,7 +6,7 @@
>  # GNU General Public License version 2 or any later version.
>  
>  from mercurial.i18n import _
> -from mercurial.node import hex
> +from mercurial.node import hex, bin
>  from mercurial import encoding, error, util, obsolete
>  import errno, os
>  
> @@ -325,46 +325,42 @@
>  
>      return results
>  
> +def _diverge(ui, b, path, localmarks):
> +    if b == '@':
> +        b = ''
> +    # find a unique @ suffix
> +    for x in range(1, 100):
> +        n = '%s@%d' % (b, x)
> +        if n not in localmarks:
> +            break
> +    # try to use an @pathalias suffix
> +    # if an @pathalias already exists, we overwrite (update) it
> +    for p, u in ui.configitems("paths"):
> +        if path == u:
> +            n = '%s@%s' % (b, p)
> +    return n

We prefer pathaliase over integers, so I think it's better to do.
If we have a path we never have to start looking for anything else.

def diverge(....):
    ....
    for p, u in ui.configitems("paths"):
        if path == u:
            return n = '%s@%s' % (b, p)

    for x in range(1, 100):
        n = '%s@%d' % (b, x):
        if n not in localmarks:
            return n
    ...error handling..

followed by error handling in case we cannot find a proper unique suffix.



More information about the Mercurial-devel mailing list