hg branches issue?

Alexis S. L. Carvalho alexis at cecm.usp.br
Wed Nov 22 14:54:24 CST 2006


Thus spake Josef "Jeff" Sipek:
> I noticed that hg branches can do seemingly odd thing when two commits (one
> of them being a head and the other not) on two different branches with the
> same branch name (basically one of the branches was renamed at some point in
> time) the one that is not head may be associated with the branch name.
> 
> This probably explains it a bit better...

> jeffpc at batlh:/tmp/hg/a$ hg branches
> devel                          3:38f3320fb04f
> master                         2:b86cb8497c25
> jeffpc at batlh:/tmp/hg/a$ hg heads
> changeset:   3:38f3320fb04f
> branch:      devel

> changeset:   1:d909dbd326d7
> branch:      master

> # Note that the head for master is rev=1, while hg branches says 2!
> 
> # and here's full log just for fun
> 
> jeffpc at batlh:/tmp/hg/a$ hg log
> changeset:   3:38f3320fb04f
> branch:      devel
> tag:         tip
> user:        Josef "Jeff" Sipek <jeffpc at josefsipek.net>
> date:        Sat Nov 04 15:57:17 2006 -0500
> summary:     some more stuff on test branch
> 
> changeset:   2:b86cb8497c25
> branch:      master
> parent:      0:c071854c3fb1
> user:        Josef "Jeff" Sipek <jeffpc at josefsipek.net>
> date:        Sat Nov 04 15:50:31 2006 -0500
> summary:     some stuff on test branch
> 
> changeset:   1:d909dbd326d7
> branch:      master
> user:        Josef "Jeff" Sipek <jeffpc at josefsipek.net>
> date:        Sat Nov 04 15:57:59 2006 -0500
> summary:     fix some badness
> 
> changeset:   0:c071854c3fb1
> branch:      master
> user:        Josef "Jeff" Sipek <jeffpc at josefsipek.net>
> date:        Sat Nov 04 15:50:06 2006 -0500
> summary:     initial

Your revision graph looks like this (in rev:branchname format):

0:master ---> 1:master
       \
        ----> 2:master ---> 3:devel

Right now hg gives the name "master" to the tip of the branch "master"
(i.e. the changeset in branch "master" that has the highest revision
number).  That's something easy to calculate.

If we changed that to something like "if the repository has a head in
branch 'master', use that; otherwise, use the tip of the branch", what
should we do when the repository has more than one head in branch
"master"?  Maybe just use the one with the highest revision number?

Arguably, the correct thing here would be to detect that the branch
"master" has two heads and abort with some kind of "'master' is an
ambiguous name" error (except that the -r option to pull/push/clone/log
should just do the right thing with all the revisions).

(Here I'll define "head of the branch 'master'" as a changeset in branch
"master" that has no other descendants in branch "master".  Compare to
"head of the repository" = a changeset in the repository that has no
other descendants in the repository.)

> I mentioned this on IRC, and tonfa made this patch to fix this issue (if you
> consider it an issue - I do.)
> 
> diff -r 1d2fdea875bc mercurial/localrepo.py
> --- a/mercurial/localrepo.py        Thu Nov 02 19:23:55 2006 +0100
> +++ b/mercurial/localrepo.py        Sat Nov 04 22:32:47 2006 +0100
> @@ -348,10 +348,13 @@ class localrepository(repo.repository):
>              pass
>  
>      def _updatebranchcache(self, partial, start, end):
> +        heads = dict.fromkeys(self.heads())

localrepo.heads() is a tad too expensive to use here...

Alexis


More information about the Mercurial-devel mailing list