[PATCH 01 of 12 V3] bookmarks: add function to centralize the logic to compare bookmarks
David Soria Parra
dsp at experimentalworks.net
Wed Oct 2 10:32:50 CDT 2013
On 10/02/2013 04:38 PM, FUJIWARA Katsunori wrote:
> diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
> --- a/mercurial/bookmarks.py
> +++ b/mercurial/bookmarks.py
> @@ -239,6 +239,92 @@
> finally:
> w.release()
>
> +def compare(localrepo, srcmarks, dstmarks,
> + srchex=None, dsthex=None, targets=None):
I don't want to be picky but usually we refer to the repo as 'repo'
unless we pass two repo objects.
> + '''Compare bookmarks between srcmarks and dstmarks
> +
> + This returns tuple "(addsrc, adddst, advsrc, advdst, diverge,
> + differ, invalid)", each are list of bookmarks below:
> +
> + :addsrc: added on src side (removed on dst side, perhaps)
> + :adddst: added on dst side (removed on src side, perhaps)
> + :advsrc: advanced on src side
> + :advdst: advanced on dst side
> + :diverge: diverge
> + :differ: changed, but no detail information
> + :invalid: unknonw on both side
> +
> + Each elements of lists in result tuple is tuple "(bookmark name,
> + changeset ID on source side, changeset ID on destination
> + side)". Each changeset IDs are 40 hexadecimal digit string or
> + None.
> +
> + Changeset IDs of tuples in "addsrc", "adddst", "differ" or
> + "invalid" list may be unknown for localrepo.
> +
> + This function expects that "srcmarks" and "dstmarks" return
> + changeset ID in 40 hexadecimal digit string for specified
> + bookmark. If not so (e.g. bmstore "repo._bookmarks" returning
> + binary value), "srchex" or "dsthex" should be specified to convert
> + into such form.
> +
> + If "targets" is specified, only bookmarks listed in it are
> + examined.
> + '''
> + if not srchex:
> + srchex = lambda x: x
> + if not dsthex:
> + dsthex = lambda x: x
> +
> + if targets:
> + bset = set(targets)
> + else:
> + srcmarkset = set(srcmarks)
> + dstmarkset = set(dstmarks)
> + bset = (srcmarkset - dstmarkset) | (dstmarkset - srcmarkset)
this is equivalent to (symmetric_difference)
bset = srcmarkset ^ dstmarkset
David
More information about the Mercurial-devel
mailing list