needs_upgrading = Attribute("Whether the branch needs to be upgraded.")
+ upgrade_pending = Attribute(
+ "Whether a branch has had an upgrade requested.")
def requestUpgrade():
"""Create an IBranchUpgradeJob to upgrade this branch."""
+ def test_needsUpgrading_already_requested(self):
+ # A branch has a needs_upgrading attribute that returns whether or not
+ # a branch needs to be upgraded or not. If the format is
+ # unrecognized, we don't try to upgrade it.
+ branch = self.factory.makePersonalBranch(
+ branch_format=BranchFormat.BZR_BRANCH_6,
+ repository_format=RepositoryFormat.BZR_CHK_2A)
+ branch.requestUpgrade()
+
+ self.assertFalse(branch.needs_upgrading)
+
def test_needsUpgrading_branch_format_unrecognized(self):
# A branch has a needs_upgrading attribute that returns whether or not
# a branch needs to be upgraded or not. If the format is
# unrecognized, we don't try to upgrade it.
branch = self.factory.makePersonalBranch(
- branch_format=BranchFormat.UNRECOGNIZED)
+ branch_format=BranchFormat.UNRECOGNIZED,
+ repository_format=RepositoryFormat.BZR_CHK_2A) self.assertFalse(branch.needs_upgrading)
def test_needsUpgrading_branch_format_upgrade_not_needed(self):
# A branch has a needs_upgrading attribute that returns whether or not
# a branch needs to be upgraded or not. If a branch is up to date, it
# doesn't need to be upgraded.
- #
- # XXX: JonathanLange 2009-06-06: This test needs to be changed every
- # time Bazaar adds a new branch format. Surely we can think of a
- # better way of testing this?
branch = self.factory.makePersonalBranch(
- branch_format=BranchFormat.BZR_BRANCH_8)
+ branch_format=BranchFormat.BZR_BRANCH_8,
+ repository_format=RepositoryFormat.BZR_CHK_2A) self.assertFalse(branch.needs_upgrading)
def test_needsUpgrading_branch_format_upgrade_needed(self):
@@ -340,7 +349,8 @@
# a branch needs to be upgraded or not. If a branch doesn't support
# stacking, it needs to be upgraded.
branch = self.factory.makePersonalBranch(
- branch_format=BranchFormat.BZR_BRANCH_6)
+ branch_format=BranchFormat.BZR_BRANCH_6,
+ repository_format=RepositoryFormat.BZR_CHK_2A) self.assertTrue(branch.needs_upgrading)
def test_needsUpgrading_repository_format_unrecognized(self):
@@ -348,6 +358,7 @@
# a branch needs to be upgraded or not. In the repo format is
# unrecognized, we don't try to upgrade it.
branch = self.factory.makePersonalBranch(
+ branch_format=BranchFormat.BZR_BRANCH_8, repository_format=RepositoryFormat.UNRECOGNIZED) self.assertFalse(branch.needs_upgrading)
@@ -356,6 +367,7 @@
# branch needs to be upgraded or not. If the repo format is up to
# date, there's no need to upgrade it.
branch = self.factory.makePersonalBranch(
+ branch_format=BranchFormat.BZR_BRANCH_8, repository_format=RepositoryFormat.BZR_KNITPACK_6) self.assertFalse(branch.needs_upgrading)
@@ -364,6 +376,7 @@
# branch needs to be upgraded or not. If the format doesn't support
# stacking, it needs to be upgraded.
branch = self.factory.makePersonalBranch(
+ branch_format=BranchFormat.BZR_BRANCH_8, repository_format=RepositoryFormat.BZR_REPOSITORY_4) self.assertTrue(branch.needs_upgrading)
@@ -378,6 +391,37 @@
jobs, [job,])
+ def test_requestUpgrade_no_upgrade_needed(self):
+ # If a branch doesn't need to be upgraded, requestUpgrade raises an
+ # AssertionError.
+ branch = self.factory.makeAnyBranch(
+ branch_format=BranchFormat.BZR_BRANCH_8,
+ repository_format=RepositoryFormat.BZR_CHK_2A)
+ self.assertRaises(AssertionError, branch.requestUpgrade)
+
+ def test_requestUpgrade_upgrade_pending(self):
+ # If there is a pending upgrade already requested, requestUpgrade
+ # raises an AssertionError.
+ branch = self.factory.makeAnyBranch(
+ branch_format=BranchFormat.BZR_BRANCH_6)
+ branch.requestUpgrade()
+
+ self.assertRaises(AssertionError, branch.requestUpgrade)
+
+ def test_upgradePending(self):
+ # If there is a BranchUpgradeJob pending for the branch, return True.
+ branch = self.factory.makeAnyBranch(
+ branch_format=BranchFormat.BZR_BRANCH_6)
+ branch.requestUpgrade()
+
+ self.assertTrue(branch.upgrade_pending)
+
+ def test_upgradePending_no_upgrade_requested(self):
+ # If the branch never had an upgrade requested, return False.
+ branch = self.factory.makeAnyBranch()
+
+ self.assertFalse(branch.upgrade_pending)
+
class TestBzrIdentity(TestCaseWithFactory):
"""Test IBranch.bzr_identity."""
Hrm, this diff seems confused. It has this branch's changes as well as the next branch's changes... Here's the real diff:
=== modified file 'lib/lp/ code/bzr. py' mat', FORMAT_ UPGRADE_ PATH', rmat', BRANCH_ FORMATS' , REPOSITORY_ FORMATS' , yFormat' , Y_FORMAT_ UPGRADE_ PATH',
--- lib/lp/code/bzr.py 2009-06-30 16:56:07 +0000
+++ lib/lp/code/bzr.py 2010-01-16 07:38:47 +0000
@@ -8,6 +8,8 @@
'BranchFor
'BRANCH_
'ControlFo
+ 'CURRENT_
+ 'CURRENT_
'Repositor
'REPOSITOR
]
@@ -222,6 +224,36 @@
BZR_METADIR_1 = _format_enum(1, BzrDirMetaFormat1)
+# A tuple of branch formats that should not suggest upgrading. BRANCH_ FORMATS = ( UNRECOGNIZED, BRANCH_ REFERENCE, BZR_BRANCH_ 8, BZR_LOOM_ 1, BZR_LOOM_ 2, BZR_LOOM_ 3, REPOSITORY_ FORMATS = ( t.UNRECOGNIZED, t.BZR_KNITPACK_ 3, t.BZR_KNITPACK_ 5, t.BZR_KNITPACK_ 5_RR, t.BZR_KNITPACK_ 6, t.BZR_KNITPACK_ 6_RR, t.BZR_PACK_ DEV_0, t.BZR_PACK_ DEV_0_SUBTREE, t.BZR_DEV_ 1, t.BZR_DEV_ 1_SUBTREE, t.BZR_DEV_ 2, t.BZR_DEV_ 2_SUBTREE, t.BZR_CHK1, t.BZR_CHK2, t.BZR_CHK_ 2A FORMAT_ UPGRADE_ PATH = { at.UNRECOGNIZED : None, at.BRANCH_ REFERENCE: None,
+CURRENT_
+ BranchFormat.
+ BranchFormat.
+ BranchFormat.
+ BranchFormat.
+ BranchFormat.
+ BranchFormat.
+)
+
+# A tuple of repository formats that should not suggest upgrading.
+CURRENT_
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+ RepositoryForma
+
+)
+
BRANCH_
BranchForm
BranchForm
=== modified file 'lib/lp/ code/configure. zcml' code/configure. zcml 2010-01-06 14:14:35 +0000 code/configure. zcml 2010-01-18 01:19:38 +0000
pending_ writes
commitsForDays
needs_upgrading
requestUpgrade
getUpgradeForma t
isBranchMergeab le
--- lib/lp/
+++ lib/lp/
@@ -487,6 +487,7 @@
+ upgrade_pending
=== modified file 'lib/lp/ code/interfaces /branch. py' code/interfaces /branch. py 2010-01-06 12:15:42 +0000 code/interfaces /branch. py 2010-01-18 01:19:39 +0000
--- lib/lp/
+++ lib/lp/
@@ -1057,6 +1057,8 @@
"""
needs_ upgrading = Attribute("Whether the branch needs to be upgraded.")
+ upgrade_pending = Attribute(
+ "Whether a branch has had an upgrade requested.")
def requestUpgrade():
"""Create an IBranchUpgradeJob to upgrade this branch."""
=== modified file 'lib/lp/ code/model/ branch. py' code/model/ branch. py 2009-12-11 00:56:16 +0000 code/model/ branch. py 2010-01-19 21:57:57 +0000 ctor, MAIN_STORE, SLAVE_FLAVOR)
--- lib/lp/
+++ lib/lp/
@@ -42,7 +42,8 @@
IStoreSele
from lp.code.bzr import ( FORMAT_ UPGRADE_ PATH, ControlFormat, RepositoryFormat, FORMAT_ UPGRADE_ PATH, ControlFormat, BRANCH_ FORMATS, CURRENT_ REPOSITORY_ FORMATS, RepositoryFormat, _FORMAT_ UPGRADE_ PATH) cycleStatus, BranchMergeCont rolStatus, (self): FORMAT_ UPGRADE_ PATH.get( self.repository _format, None) FORMAT_ UPGRADE_ PATH.get( self.branch_ format, None)): pending: BRANCH_ FORMATS and _format in CURRENT_ REPOSITORY_ FORMATS) pending( self): model.branchjob import BranchJob, BranchJobType UPGRADE_ BRANCH)
- BranchFormat, BRANCH_
+ BranchFormat, BRANCH_
+ CURRENT_
REPOSITORY
from lp.code.enums import (
BranchLife
@@ -991,10 +992,22 @@
@property
def needs_upgrading
"""See `IBranch`."""
- if (REPOSITORY_
- or BRANCH_
- return True
- return False
+ if self.upgrade_
+ return False
+ return not (
+ self.branch_format in CURRENT_
+ self.repository
+
+ @property
+ def upgrade_
+ """See `IBranch`."""
+ from lp.code.
+ store = Store.of(self)
+ jobs = store.find(
+ BranchJob,
+ BranchJob.branch == self,
+ BranchJob.job_type == BranchJobType.
+ return jobs.count() > 0
def requestUpgrade( self):
"""See `IBranch`."""
=== modified file 'lib/lp/ code/model/ branchjob. py' code/model/ branchjob. py 2010-01-15 01:20:20 +0000 code/model/ branchjob. py 2010-01-16 08:33:16 +0000 JobSource` .""" needs_upgrading : 'Branch does not need upgrading.') upgrade_ pending: 'Branch already has upgrade pending.') UPGRADE_ BRANCH, {})
--- lib/lp/
+++ lib/lp/
@@ -264,6 +264,8 @@
"""See `IBranchUpgrade
if not branch.
raise AssertionError(
+ if branch.
+ raise AssertionError(
branch_job = BranchJob(branch, BranchJobType.
return cls(branch_job)
=== modified file 'lib/lp/ code/model/ tests/test_ branch. py' code/model/ tests/test_ branch. py 2010-01-07 06:37:14 +0000 code/model/ tests/test_ branch. py 2010-01-19 22:00:02 +0000
SourcePac kage(branch. sourcepackagena me, branch. distroseries) ,
branch. sourcepackage)
--- lib/lp/
+++ lib/lp/
@@ -315,24 +315,33 @@
+ def test_needsUpgra ding_already_ requested( self): makePersonalBra nch( format= BranchFormat. BZR_BRANCH_ 6, format= RepositoryForma t.BZR_CHK_ 2A) requestUpgrade( ) e(branch. needs_upgrading ) ding_branch_ format_ unrecognized( self): makePersonalBra nch( format= BranchFormat. UNRECOGNIZED) format= BranchFormat. UNRECOGNIZED, format= RepositoryForma t.BZR_CHK_ 2A)
self. assertFalse( branch. needs_upgrading )
+ # A branch has a needs_upgrading attribute that returns whether or not
+ # a branch needs to be upgraded or not. If the format is
+ # unrecognized, we don't try to upgrade it.
+ branch = self.factory.
+ branch_
+ repository_
+ branch.
+
+ self.assertFals
+
def test_needsUpgra
# A branch has a needs_upgrading attribute that returns whether or not
# a branch needs to be upgraded or not. If the format is
# unrecognized, we don't try to upgrade it.
branch = self.factory.
- branch_
+ branch_
+ repository_
def test_needsUpgra ding_branch_ format_ upgrade_ not_needed( self): makePersonalBra nch( format= BranchFormat. BZR_BRANCH_ 8) format= BranchFormat. BZR_BRANCH_ 8, format= RepositoryForma t.BZR_CHK_ 2A)
self. assertFalse( branch. needs_upgrading )
# A branch has a needs_upgrading attribute that returns whether or not
# a branch needs to be upgraded or not. If a branch is up to date, it
# doesn't need to be upgraded.
- #
- # XXX: JonathanLange 2009-06-06: This test needs to be changed every
- # time Bazaar adds a new branch format. Surely we can think of a
- # better way of testing this?
branch = self.factory.
- branch_
+ branch_
+ repository_
def test_needsUpgra ding_branch_ format_ upgrade_ needed( self): makePersonalBra nch( format= BranchFormat. BZR_BRANCH_ 6) format= BranchFormat. BZR_BRANCH_ 6, format= RepositoryForma t.BZR_CHK_ 2A)
self. assertTrue( branch. needs_upgrading )
@@ -340,7 +349,8 @@
# a branch needs to be upgraded or not. If a branch doesn't support
# stacking, it needs to be upgraded.
branch = self.factory.
- branch_
+ branch_
+ repository_
def test_needsUpgra ding_repository _format_ unrecognized( self): makePersonalBra nch( format= BranchFormat. BZR_BRANCH_ 8,
repositor y_format= RepositoryForma t.UNRECOGNIZED)
self. assertFalse( branch. needs_upgrading )
@@ -348,6 +358,7 @@
# a branch needs to be upgraded or not. In the repo format is
# unrecognized, we don't try to upgrade it.
branch = self.factory.
+ branch_
@@ -356,6 +367,7 @@ makePersonalBra nch( format= BranchFormat. BZR_BRANCH_ 8,
repositor y_format= RepositoryForma t.BZR_KNITPACK_ 6)
self. assertFalse( branch. needs_upgrading )
# branch needs to be upgraded or not. If the repo format is up to
# date, there's no need to upgrade it.
branch = self.factory.
+ branch_
@@ -364,6 +376,7 @@ makePersonalBra nch( format= BranchFormat. BZR_BRANCH_ 8,
repositor y_format= RepositoryForma t.BZR_REPOSITOR Y_4)
self. assertTrue( branch. needs_upgrading )
# branch needs to be upgraded or not. If the format doesn't support
# stacking, it needs to be upgraded.
branch = self.factory.
+ branch_
@@ -378,6 +391,37 @@
[ job,])
jobs,
+ def test_requestUpg rade_no_ upgrade_ needed( self): makeAnyBranch( format= BranchFormat. BZR_BRANCH_ 8, format= RepositoryForma t.BZR_CHK_ 2A) es(AssertionErr or, branch. requestUpgrade) rade_upgrade_ pending( self): makeAnyBranch( format= BranchFormat. BZR_BRANCH_ 6) requestUpgrade( ) es(AssertionErr or, branch. requestUpgrade) ding(self) : makeAnyBranch( format= BranchFormat. BZR_BRANCH_ 6) requestUpgrade( ) (branch. upgrade_ pending) ding_no_ upgrade_ requested( self): makeAnyBranch( ) e(branch. upgrade_ pending)
+ # If a branch doesn't need to be upgraded, requestUpgrade raises an
+ # AssertionError.
+ branch = self.factory.
+ branch_
+ repository_
+ self.assertRais
+
+ def test_requestUpg
+ # If there is a pending upgrade already requested, requestUpgrade
+ # raises an AssertionError.
+ branch = self.factory.
+ branch_
+ branch.
+
+ self.assertRais
+
+ def test_upgradePen
+ # If there is a BranchUpgradeJob pending for the branch, return True.
+ branch = self.factory.
+ branch_
+ branch.
+
+ self.assertTrue
+
+ def test_upgradePen
+ # If the branch never had an upgrade requested, return False.
+ branch = self.factory.
+
+ self.assertFals
+
class TestBzrIdentity (TestCaseWithFa ctory): bzr_identity. """
"""Test IBranch.