localrepo: set heads and branchheads to be closed=False by default
The heads(...) and branchheads(...) functions will now only return closed
heads when explicitly asked for them. This will cause 'hg merge' to have
better behavior in the presence of a branch that has closed heads when no
explicit rev is passed.
--- a/mercurial/localrepo.py Mon Jun 01 17:12:42 2009 +0200
+++ b/mercurial/localrepo.py Wed Jun 03 13:42:55 2009 +0200
@@ -1113,7 +1113,7 @@
finally:
wlock.release()
- def heads(self, start=None, closed=True):
+ def heads(self, start=None, closed=False):
heads = self.changelog.heads(start)
def display(head):
if closed:
@@ -1124,7 +1124,7 @@
heads = [(-self.changelog.rev(h), h) for h in heads if display(h)]
return [n for (r, n) in sorted(heads)]
- def branchheads(self, branch=None, start=None, closed=True):
+ def branchheads(self, branch=None, start=None, closed=False):
if branch is None:
branch = self[None].branch()
branches = self.branchmap()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-merge-closedheads Wed Jun 03 13:42:55 2009 +0200
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+hgcommit() {
+ hg commit -u user -d '0 0' "$@"
+}
+
+hg init clhead
+cd clhead
+
+
+touch foo && hg add && hgcommit -m 'foo'
+touch bar && hg add && hgcommit -m 'bar'
+touch baz && hg add && hgcommit -m 'baz'
+
+echo "flub" > foo
+hgcommit -m "flub"
+echo "nub" > foo
+hgcommit -m "nub"
+
+hg up -C 2
+
+echo "c1" > c1
+hg add c1
+hgcommit -m "c1"
+echo "c2" > c1
+hgcommit -m "c2"
+
+hg up -C 2
+
+echo "d1" > d1
+hg add d1
+hgcommit -m "d1"
+echo "d2" > d1
+hgcommit -m "d2"
+hg tag -l good
+
+echo '% fail with three heads'
+hg up -C good
+hg merge
+
+echo '% close one of the heads'
+hg up -C 6
+hgcommit -m 'close this head' --close-branch
+
+echo '% succeed with two open heads'
+hg up -C good
+hg up -C good
+hg merge
+hgcommit -m 'merged heads'
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-merge-closedheads.out Wed Jun 03 13:42:55 2009 +0200
@@ -0,0 +1,17 @@
+adding foo
+adding bar
+adding baz
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+created new head
+% fail with three heads
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+abort: branch 'default' has 3 heads - please merge with an explicit rev
+% close one of the heads
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+% succeed with two open heads
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)