[PATCH 2 of 2 V2] destutil: choose non-closed branch head at first (BC)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Mar 1 19:53:06 EST 2016


At Wed, 2 Mar 2016 00:04:54 +0900,
Yuya Nishihara wrote:
> 
> On Mon, 29 Feb 2016 02:27:25 +0900, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > # Date 1456680134 -32400
> > #      Mon Feb 29 02:22:14 2016 +0900
> > # Node ID 38c42dcba037e4fec3e129370850d464d535217e
> > # Parent  a694cb0ea3a9ca64ac729c8fb2d507fb188eae97
> > destutil: choose non-closed branch head at first (BC)
> 
> [snip]
> 
> > +def _destupdatebranchfallback(repo, clean, check):
> > +    """decide on an update destination from closed heads in current branch"""
> > +    wc = repo[None]
> > +    currentbranch = wc.branch()
> > +    movemark = None
> > +    if currentbranch in repo.branchmap():
> > +        # here, all descendant branch heads are closed
> > +        heads = repo.branchheads(currentbranch, closed=True)
> > +        assert heads, "any branch has at least one head"
> > +        node = repo.revs('max(.::(%ln))', heads).first()
> > +        assert node, "any revision has at least one descendant branch head"
> 
> What if a node (which is actually a rev) is 0 ?

If we create a revision closing branch head only via "hg commit",
closing non-existing branch is aborted (empty repo is variant of this
case). Therefore, closing revision should be 1 or more,

    https://selenic.com/repo/hg/file/9a7c27ba166b/mercurial/commands.py#l1662

But "assert node is not None" is safer and more readable than "assert
node". I'll post revised one.


> > +        if bookmarks.isactivewdirparent(repo):
> > +            movemark = repo['.'].node()
> > +    else:
> > +        # here, no "default" branch, and all branches are closed
> > +        node = repo.lookup('tip')
> > +        assert node, "'tip' exists even in empty repository"
> > +    return node, movemark, None
> 
> Though I'm not sure if we should create a separate "branchfallback" step, the
> change looks good to me.
> 

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


More information about the Mercurial-devel mailing list