[PATCH 01 of 15 V4] bookmarks: add function to centralize the logic to compare bookmarks

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Oct 17 08:09:15 CDT 2013


At Wed, 16 Oct 2013 13:03:41 -0400,
Augie Fackler wrote:
> 
> On Wed, Oct 16, 2013 at 12:25:23AM +0900, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > # Date 1381849966 -32400
> > #      Wed Oct 16 00:12:46 2013 +0900
> > # Node ID 95c02d8fbf0264b9d273e13528197769c6c2e898
> > # Parent  5b327880a660323087ac8ecc1f00db809e38a208
> > bookmarks: add function to centralize the logic to compare bookmarks
> >
> > This patch adds "compare()" function to centralize the logic to
> > compare bookmarks between two repositories.
> >
> > 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(repo, srcmarks, dstmarks,
> > +            srchex=None, dsthex=None, targets=None):
> > +    '''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
> 
> I'm unclear how we could ever end up in this state. I think it's
> because one of the nodes pointed to by the named bookmark isn't
> available locally. Is that correct? If so, I'd like to see it in the
> odocstring

Yes, it is correct. I'll re-post revised series also fixing typo
below.

> > +    :invalid: unknonw on both side
> 
> typo
> 
> > +
> > +    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 repo.
> > +
> > +    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
> > +        for b in srcmarkset & dstmarkset:
> > +            if srchex(srcmarks[b]) != dsthex(dstmarks[b]):
> > +                bset.add(b)
> > +
> > +    results = ([], [], [], [], [], [], [])
> > +    addsrc = results[0].append
> > +    adddst = results[1].append
> > +    advsrc = results[2].append
> > +    advdst = results[3].append
> > +    diverge = results[4].append
> > +    differ = results[5].append
> > +    invalid = results[6].append
> > +
> > +    for b in sorted(bset):
> > +        if b not in srcmarks:
> > +            if b in dstmarks:
> > +                adddst((b, None, dsthex(dstmarks[b])))
> > +            else:
> > +                invalid((b, None, None))
> > +        elif b not in dstmarks:
> > +            addsrc((b, srchex(srcmarks[b]), None))
> > +        else:
> > +            scid = srchex(srcmarks[b])
> > +            dcid = dsthex(dstmarks[b])
> > +            if scid in repo and dcid in repo:
> > +                sctx = repo[scid]
> > +                dctx = repo[dcid]
> > +                if sctx.rev() < dctx.rev():
> > +                    if validdest(repo, sctx, dctx):
> > +                        advdst((b, scid, dcid))
> > +                    else:
> > +                        diverge((b, scid, dcid))
> > +                else:
> > +                    if validdest(repo, dctx, sctx):
> > +                        advsrc((b, scid, dcid))
> > +                    else:
> > +                        diverge((b, scid, dcid))
> > +            else:
> > +                # it is too expensive to examine in detail, in this case
> > +                differ((b, scid, dcid))
> > +
> > +    return results
> > +
> >  def updatefromremote(ui, repo, remotemarks, path):
> >      ui.debug("checking for updated bookmarks\n")
> >      changed = False
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel at selenic.com
> > http://selenic.com/mailman/listinfo/mercurial-devel
> 

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list