Skip to content

Commit c378da8

Browse files
committed
Fix BranchHeads to work with branch2*
As of http://selenic.com/pipermail/mercurial-devel/2013-November/054749.html the new format should be: <branch head hex node> <open/closed state> <branch name> Ran into this problem on Mercurial 3.0.2.
1 parent 80c5ee8 commit c378da8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

branches.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ func (dest *BranchHeads) copy(src *BranchHeads) {
3939
func (r *Repository) BranchHeads() (*BranchHeads, error) {
4040
bh := newBranchHeads()
4141

42-
names := []string{"branchheads-served", "branchheads-base", "branchheads"}
42+
names := []string{
43+
// Original Mercurial branchheads
44+
"branchheads-served", "branchheads-base", "branchheads",
45+
46+
// branchheads -> branch2 as of
47+
// http://selenic.com/pipermail/mercurial-devel/2013-November/054749.html
48+
"branch2-served", "branch2-base", "branch2",
49+
}
4350
for _, name := range names {
4451
f, err := r.open(".hg/cache/" + name)
4552
if os.IsNotExist(err) {
@@ -73,11 +80,11 @@ func (bh *BranchHeads) parseFile(r io.Reader) error {
7380
// first line is current numbered, don't include
7481
continue
7582
}
76-
branch := strings.SplitN(strings.TrimSpace(line), " ", 2)
77-
if len(branch) != 2 {
83+
branch := strings.SplitN(strings.TrimSpace(line), " ", 3)
84+
if len(branch) != 2 && len(branch) != 3 {
7885
continue
7986
}
80-
m[branch[1]] = branch[0]
87+
m[branch[len(branch)-1]] = branch[0]
8188
}
8289
// unify
8390
for name, id := range m {

0 commit comments

Comments
 (0)