> > === modified file 'lib/lp/code/model/branchjob.py'
> > --- lib/lp/code/model/branchjob.py 2009-10-20 06:03:46 +0000
> > +++ lib/lp/code/model/branchjob.py 2009-10-22 00:05:29 +0000
> > @@ -11,12 +11,15 @@
> > import os
> > import shutil
> > from StringIO import StringIO
> > +import tempfile
> >
> > +from bzrlib.branch import Branch as BzrBranch
> > from bzrlib.bzrdir import BzrDirMetaFormat1
> > from bzrlib.log import log_formatter, show_log
> > from bzrlib.diff import show_diff_trees
> > from bzrlib.revision import NULL_REVISION
> > from bzrlib.revisionspec import RevisionInfo, RevisionSpec
> > +from bzrlib.transport import get_transport
> > from bzrlib.upgrade import upgrade
> >
> > from lazr.enum import DBEnumeratedType, DBItem
> > @@ -252,16 +255,30 @@
> >
> > def run(self):
> > """See `IBranchUpgradeJob`."""
> > - self._prepare_upgrade()
> > - self._upgrade()
> > -
> > - def _prepare_upgrade(self):
> > - """Prepares the branch for upgrade."""
> > - self._upgrade_branch = self.branch.getBzrBranch()
> > -
> > - def _upgrade(self):
> > - """Performs the upgrade of the branch."""
> > - upgrade(self._upgrade_branch.base, self.upgrade_format)
> > + # Set up the new branch structure
> > + upgrade_branch_path = tempfile.mkdtemp()
>
> Everything in this method after this point should be in a try:finally:
> that blows away this directory.
Done.
>
> > + upgrade_transport = get_transport(upgrade_branch_path)
> > + source_branch = self.branch.getBzrBranch()
>
> There's a problem here, which is that getBzrBranch opens the branch in
> the mirrored area, not the hosted area.
>
Yea, fixed this.
> > + source_branch_transport = source_branch.bzrdir.root_transport
>
> I think
>
> source_branch_transport = get_transport(self.branch.getPullURL())
>
> is what you want; it gets a transport to the hosted area of the
> branch, and is less effort than opening the branch just to get the
> transport out of it. Once the copy in the hosted area is upgraded,
> the puller will take care of propagating the new format into the
> mirrored area.
>
> (The names of the methods/properties are completely ridiculous, no
> argument about that).
>
Well, I still need the source_branch to pull from later, but I can get that with Branch.open_from_transport
> > + source_branch_transport.copy_tree_to_transport(upgrade_transport)
> > + upgrade_branch = BzrBranch.open(upgrade_transport.base)
> > +
> > + # Perform the upgrade.
> > + upgrade(upgrade_branch.base, self.upgrade_format)
> > +
> > + # Re-open the branch, since its format has changed.
> > + upgrade_branch = BzrBranch.open(upgrade_transport.base)
> > + upgrade_branch.pull(source_branch)
> > + upgrade_branch.fetch(source_branch)
> > +
> > + # Move the branch in the old format to backup.bzr
>
> I think you should try to write lock the branch before doing this move
> to prevent confusion if someone is pushing to the branch right at this
> moment.
>
> > + source_branch_transport.rename('.bzr', 'backup.bzr')
>
> b = Branch.open_from_transport(source_branch_transport)
> b.lock_write()
>
> I don't know what will happen when bzr notices that the underlying
> branch has gone away from this lock though -- something to experiment
> with I guess!
>
So it looks like we lock for the pull and fetch, than unlock right before we move.
> > + upgrade_transport.delete_tree('backup.bzr')
> > + upgrade_transport.copy_tree_to_transport(source_branch_transport)
> > +
> > + # Clean up the temporary directory.
> > + upgrade_transport.delete_tree('.bzr')
> > + os.rmdir(upgrade_branch_path)
>
> I think a shutil.rmtree(upgrade_branch_path) rather than the
> two delete_tree()s then the rmdir makes more sense.
>
> I can't think of a sane way to test any of these changes I'm proposing
> :(
>
Me neither. However, I take solace in the fact that we're actually testing the functionality we want.
> > === modified file 'lib/lp/ code/model/ branchjob. py' code/model/ branchjob. py 2009-10-20 06:03:46 +0000 code/model/ branchjob. py 2009-10-22 00:05:29 +0000 Job`."" " upgrade( ) upgrade( self): branch = self.branch. getBzrBranch( ) self._upgrade_ branch. base, self.upgrade_ format)
> > --- lib/lp/
> > +++ lib/lp/
> > @@ -11,12 +11,15 @@
> > import os
> > import shutil
> > from StringIO import StringIO
> > +import tempfile
> >
> > +from bzrlib.branch import Branch as BzrBranch
> > from bzrlib.bzrdir import BzrDirMetaFormat1
> > from bzrlib.log import log_formatter, show_log
> > from bzrlib.diff import show_diff_trees
> > from bzrlib.revision import NULL_REVISION
> > from bzrlib.revisionspec import RevisionInfo, RevisionSpec
> > +from bzrlib.transport import get_transport
> > from bzrlib.upgrade import upgrade
> >
> > from lazr.enum import DBEnumeratedType, DBItem
> > @@ -252,16 +255,30 @@
> >
> > def run(self):
> > """See `IBranchUpgrade
> > - self._prepare_
> > - self._upgrade()
> > -
> > - def _prepare_
> > - """Prepares the branch for upgrade."""
> > - self._upgrade_
> > -
> > - def _upgrade(self):
> > - """Performs the upgrade of the branch."""
> > - upgrade(
> > + # Set up the new branch structure
> > + upgrade_branch_path = tempfile.mkdtemp()
>
> Everything in this method after this point should be in a try:finally:
> that blows away this directory.
Done.
> upgrade_ branch_ path) getBzrBranch( )
> > + upgrade_transport = get_transport(
> > + source_branch = self.branch.
>
> There's a problem here, which is that getBzrBranch opens the branch in
> the mirrored area, not the hosted area.
>
Yea, fixed this.
> > + source_ branch_ transport = source_ branch. bzrdir. root_transport branch_ transport = get_transport( self.branch. getPullURL( ))
>
> I think
>
> source_
>
> is what you want; it gets a transport to the hosted area of the
> branch, and is less effort than opening the branch just to get the
> transport out of it. Once the copy in the hosted area is upgraded,
> the puller will take care of propagating the new format into the
> mirrored area.
>
> (The names of the methods/properties are completely ridiculous, no
> argument about that).
>
Well, I still need the source_branch to pull from later, but I can get that with Branch. open_from_ transport
> > + source_ branch_ transport. copy_tree_ to_transport( upgrade_ transport) open(upgrade_ transport. base) upgrade_ branch. base, self.upgrade_ format) open(upgrade_ transport. base) branch. pull(source_ branch) branch. fetch(source_ branch) branch_ transport. rename( '.bzr', 'backup.bzr') open_from_ transport( source_ branch_ transport)
> > + upgrade_branch = BzrBranch.
> > +
> > + # Perform the upgrade.
> > + upgrade(
> > +
> > + # Re-open the branch, since its format has changed.
> > + upgrade_branch = BzrBranch.
> > + upgrade_
> > + upgrade_
> > +
> > + # Move the branch in the old format to backup.bzr
>
> I think you should try to write lock the branch before doing this move
> to prevent confusion if someone is pushing to the branch right at this
> moment.
>
> > + source_
>
> b = Branch.
> b.lock_write()
>
> I don't know what will happen when bzr notices that the underlying
> branch has gone away from this lock though -- something to experiment
> with I guess!
>
So it looks like we lock for the pull and fetch, than unlock right before we move.
> > + upgrade_ transport. delete_ tree('backup. bzr') transport. copy_tree_ to_transport( source_ branch_ transport) transport. delete_ tree('. bzr') upgrade_ branch_ path) rmtree( upgrade_ branch_ path) rather than the
> > + upgrade_
> > +
> > + # Clean up the temporary directory.
> > + upgrade_
> > + os.rmdir(
>
> I think a shutil.
> two delete_tree()s then the rmdir makes more sense.
>
> I can't think of a sane way to test any of these changes I'm proposing
> :(
>
Me neither. However, I take solace in the fact that we're actually testing the functionality we want.
> > @property format( self): code/model/ tests/test_ branchjob. py' code/model/ tests/test_ branchjob. py 2009-10-05 14:18:33 +0000 code/model/ tests/test_ branchjob. py 2009-10-22 00:05:29 +0000 ssLayer tKnitPack6 set_branch_ format( branch_ format( )) _set_repository _format( repo_format( )) branchjob( self): branch_ and_tree( format= 'knit') branch_ format = BranchFormat. BZR_BRANCH_ 5 repository_ format = RepositoryForma t.BZR_KNIT_ 1 b.create( db_branch)
> > def upgrade_
>
> > === modified file 'lib/lp/
> > --- lib/lp/
> > +++ lib/lp/
> > @@ -183,6 +183,25 @@
> >
> > layer = LaunchpadZopele
> >
> > + def make_format(self, branch_format=None, repo_format=None):
> > + # Return a Bzr MetaDir format with the provided branch and
> repository
> > + # formats.
> > + if branch_format is None:
> > + branch_format = BzrBranchFormat7
> > + if repo_format is None:
> > + repo_format = RepositoryForma
> > + format = BzrDirMetaFormat1()
> > + format.
> > + format.
> > + return format
> > +
> > + def make_upgrade_
> > + db_branch, tree = self.create_
> > + db_branch.
> > + db_branch.
> > + job = BranchUpgradeJo
> > + return db_branch, job
>
> It doesn't seem that this helper is actually used.
>
Ah, that's from the old code where there were more tests.
Here's the incremental diff:
=== modified file 'lib/lp/ code/model/ branchjob. py' code/model/ branchjob. py 2009-10-21 23:34:08 +0000 code/model/ branchjob. py 2009-10-22 04:22:18 +0000 Job`."" "
upgrade_ branch_ path = tempfile.mkdtemp() upgrade_ branch_ path) getBzrBranch( ) branch_ transport = source_ branch. bzrdir. root_transport branch_ transport. copy_tree_ to_transport( upgrade_ transport) open(upgrade_ transport. base) upgrade_ branch. base, self.upgrade_ format) open(upgrade_ transport. base) branch. pull(source_ branch) branch. fetch(source_ branch) branch_ transport. rename( '.bzr', 'backup.bzr') transport. delete_ tree('backup. bzr') transport. copy_tree_ to_transport( source_ branch_ transport) transport. delete_ tree('. bzr') upgrade_ branch_ path) upgrade_ branch_ path) branch_ transport = get_transport( self.branch. getPullURL( )) branch_ transport. copy_tree_ to_transport( upgrade_ transport) open(upgrade_ transport. base) upgrade_ branch. base, self.upgrade_ format) open_from_ transport( open_from_ transport( branch_ transport) branch. lock_write( ) branch. pull(source_ branch) branch. fetch(source_ branch) branch. unlock( ) branch_ transport. rename( '.bzr', 'backup.bzr') transport. delete_ tree('backup. bzr') transport. copy_tree_ to_transport( source_ branch_ transport) rmtree( upgrade_ branch_ path)
--- lib/lp/
+++ lib/lp/
@@ -257,28 +257,32 @@
"""See `IBranchUpgrade
# Set up the new branch structure
- upgrade_transport = get_transport(
- source_branch = self.branch.
- source_
- source_
- upgrade_branch = BzrBranch.
-
- # Perform the upgrade.
- upgrade(
-
- # Re-open the branch, since its format has changed.
- upgrade_branch = BzrBranch.
- upgrade_
- upgrade_
-
- # Move the branch in the old format to backup.bzr
- source_
- upgrade_
- upgrade_
-
- # Clean up the temporary directory.
- upgrade_
- os.rmdir(
+ try:
+ upgrade_transport = get_transport(
+ source_
+ source_
+ upgrade_branch = BzrBranch.
+
+ # Perform the upgrade.
+ upgrade(
+
+ # Re-open the branch, since its format has changed.
+ upgrade_branch = BzrBranch.
+ upgrade_transport)
+ source_branch = BzrBranch.
+ source_
+
+ source_
+ upgrade_
+ upgrade_
+ source_
+
+ # Move the branch in the old format to backup.bzr
+ source_
+ upgrade_
+ upgrade_
+ finally:
+ shutil.
@property format( self):
def upgrade_
=== modified file 'lib/lp/ code/model/ tests/test_ branchjob. py' code/model/ tests/test_ branchjob. py 2009-10-21 22:01:23 +0000 code/model/ tests/test_ branchjob. py 2009-10-22 04:31:06 +0000
format. _set_repository _format( repo_format( ))
--- lib/lp/
+++ lib/lp/
@@ -195,13 +195,6 @@
return format
- def make_upgrade_ branchjob( self): branch_ and_tree( format= 'knit') branch_ format = BranchFormat. BZR_BRANCH_ 5 repository_ format = RepositoryForma t.BZR_KNIT_ 1 b.create( db_branch) terface( self): ob.""" makeAnyBranch( ) branch( self):
self. useBzrBranches( ) branch_ and_tree( format= 'knit') branch_ and_tree(
db_branch. branch_ format = BranchFormat. BZR_BRANCH_ 5
db_branch. repository_ format = RepositoryForma t.BZR_KNIT_ 1
self. assertEqual(
- db_branch, tree = self.create_
- db_branch.
- db_branch.
- job = BranchUpgradeJo
- return db_branch, job
-
def test_providesIn
"""Ensure that BranchUpgradeJob implements IBranchUpgradeJ
branch = self.factory.
@@ -211,7 +204,8 @@
def test_upgrades_
"""Ensure that a branch with an outdated format is upgraded."""
- db_branch, tree = self.create_
+ db_branch, tree = self.create_
+ hosted=True, format='knit')