Rev 3380: Prevent losing data when reconfiguring to lightweight checkout in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Apr 24 19:57:30 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3380
revision-id:pqm at pqm.ubuntu.com-20080424185721-ukk0dncnc4xpqk5o
parent: pqm at pqm.ubuntu.com-20080424072816-jjx4v6pqude11ys2
parent: aaron at aaronbentley.com-20080424164423-i2wobvoi7xmzxnvc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-04-24 19:57:21 +0100
message:
  Prevent losing data when reconfiguring to lightweight checkout
  	(abentley)
modified:
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
  bzrlib/reconfigure.py          reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
  bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
    ------------------------------------------------------------
    revno: 3338.1.5
    revision-id:aaron at aaronbentley.com-20080424164423-i2wobvoi7xmzxnvc
    parent: aaron at aaronbentley.com-20080424053319-9a13fu46i2ameb5i
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: reconfigure-lightweight-check
    timestamp: Thu 2008-04-24 12:44:23 -0400
    message:
      Tweak text
    modified:
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
    ------------------------------------------------------------
    revno: 3338.1.4
    revision-id:aaron at aaronbentley.com-20080424053319-9a13fu46i2ameb5i
    parent: aaron at aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: reconfigure-lightweight-check
    timestamp: Thu 2008-04-24 01:33:19 -0400
    message:
      Add sync-for-reconfigure help topic
    modified:
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
    ------------------------------------------------------------
    revno: 3338.1.3
    revision-id:aaron at aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
    parent: aaron at aaronbentley.com-20080408055335-86c71v5wpx2p5gzv
    parent: pqm at pqm.ubuntu.com-20080422120059-sony5sthnlewabge
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: reconfigure-lightweight-check
    timestamp: Thu 2008-04-24 00:58:42 -0400
    message:
      Merge bzr.dev
    removed:
      bzrlib/xml6.py                 xml6.py-20060823042456-dbaaq4atrche7xy5-1
    added:
      bzrlib/xml5.py                 xml5.py-20080328030717-t9guwinq8hom0ar3-1
      bzrlib/xml6.py                 xml6.py-20080327235607-1skmbg4o9cd1o636-1
      doc/developers/integration.txt integration.txt-20080404022341-2lorxocp1in07zij-1
      doc/developers/plugin-api.txt  pluginapi.txt-20080229110225-q2j5y4agqhlkjn0s-1
      doc/developers/tortoise-strategy.txt tortoisestrategy.txt-20080403024510-2ahdqrvnwqrb5p5t-1
    renamed:
      bzrlib/xml5.py => bzrlib/xml8.py xml5.py-20050907032657-aac8f960815b66b1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/annotate.py             annotate.py-20050922133147-7c60541d2614f022
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
      bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
      bzrlib/multiparent.py          __init__.py-20070410133617-n1jdhcc1n1mibarp-1
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
      bzrlib/reconfigure.py          reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repofmt/weaverepo.py    presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/revisiontree.py         revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
      bzrlib/smart/branch.py         branch.py-20061124031907-mzh3pla28r83r97f-1
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/smart/protocol.py       protocol.py-20061108035435-ot0lstk2590yqhzr-1
      bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
      bzrlib/smart/server.py         server.py-20061110062051-chzu10y32vx8gvur-1
      bzrlib/store/revision/knit.py  knit.py-20060303020652-de5fa299e941a3c7
      bzrlib/store/versioned/__init__.py weavestore.py-20050907094258-88262e0434babab9
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_reconfigure.py test_reconfigure.py-20070908173426-khfo5fi2rgzgtwj3-1
      bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
      bzrlib/tests/bzrdir_implementations/__init__.py __init__.py-20060131065642-34c39b54f42dd048
      bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
      bzrlib/tests/intertree_implementations/__init__.py __init__.py-20060724101752-09ysswo1a92uqyoz-3
      bzrlib/tests/interversionedfile_implementations/__init__.py __init__.py-20060302012326-981af525594d02ed
      bzrlib/tests/repository_implementations/test_check_reconcile.py test_broken.py-20070928125406-62236394w0jpbpd6-2
      bzrlib/tests/repository_implementations/test_fetch.py test_fetch.py-20070814052151-5cxha9slx4c93uog-1
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
      bzrlib/tests/revisionstore_implementations/test_all.py test_all.py-20060303020702-9b2d4c1d75407f31
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_fetch.py     testfetch.py-20050825090644-f73e07e7dfb1765a
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
      bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
      bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
      bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/tests/test_store.py     teststore.py-20050826022702-f6caadb647395769
      bzrlib/tests/test_subsume.py   test_subsume.py-20060927040024-tsvh4pchajoayymg-1
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/tests/test_weave.py     testknit.py-20050627023648-9833cc5562ffb785
      bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
      bzrlib/tests/workingtree_implementations/__init__.py __init__.py-20060203003124-b2aa5aca21a8bfad
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
      bzrlib/transport/ssh.py        ssh.py-20060824042150-0s9787kng6zv1nwq-1
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/en/user-guide/controlling_registration.txt controlling_registra-20071121073725-0corxykv5irjal00-3
      bzrlib/xml8.py                 xml5.py-20050907032657-aac8f960815b66b1
    ------------------------------------------------------------
    revno: 3338.1.2
    revision-id:aaron at aaronbentley.com-20080408055335-86c71v5wpx2p5gzv
    parent: aaron at aaronbentley.com-20080406165435-cqhh3rg3gt1qzp11
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: reconfigure-lightweight-check
    timestamp: Tue 2008-04-08 01:53:35 -0400
    message:
      Split out tests even further
    modified:
      bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
    ------------------------------------------------------------
    revno: 3338.1.1
    revision-id:aaron at aaronbentley.com-20080406165435-cqhh3rg3gt1qzp11
    parent: pqm at pqm.ubuntu.com-20080406101328-z1x7a0hsejxblf39
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: reconfigure-lightweight-check
    timestamp: Sun 2008-04-06 12:54:35 -0400
    message:
      Raise an error when converting a branch to a lightweight checkout loses data
    modified:
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/reconfigure.py          reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
      bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2008-04-12 06:46:35 +0000
+++ b/bzrlib/errors.py	2008-04-24 16:44:23 +0000
@@ -2551,6 +2551,18 @@
         BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
 
+class UnsyncedBranches(BzrDirError):
+
+    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
+            " bzr help sync-for-reconfigure.")
+
+    def __init__(self, bzrdir, target_branch):
+        BzrDirError.__init__(self, bzrdir)
+        import bzrlib.urlutils as urlutils
+        self.target_url = urlutils.unescape_for_display(target_branch.base,
+                                                        'ascii')
+
+
 class AlreadyBranch(BzrDirError):
 
     _fmt = "'%(display_url)s' is already a branch."

=== modified file 'bzrlib/help_topics/__init__.py'
--- a/bzrlib/help_topics/__init__.py	2008-04-02 04:16:23 +0000
+++ b/bzrlib/help_topics/__init__.py	2008-04-24 05:33:19 +0000
@@ -605,6 +605,26 @@
 differences.
 """
 
+_branches_out_of_sync = """Branches out of sync
+
+When reconfiguring a checkout, tree or branch into a lightweight checkout,
+a local branch must be destroyed.  (For checkouts, this is the local branch
+that serves primarily as a cache.)  If the branch-to-be-destroyed does not
+have the same last revision as the new reference branch for the lightweight
+checkout, data could be lost, so Bazaar refuses.
+
+How you deal with this depends on *why* the branches are out of sync.
+
+If you have a checkout and have done local commits, you can get back in sync
+by running "bzr update" (and possibly "bzr commit").
+
+If you have a branch and the remote branch is out-of-date, you can push
+the local changes using "bzr push".  If the local branch is out of date, you
+can do "bzr pull".  If both branches have had changes, you can merge, commit
+and then push your changes.  If you decide that some of the changes aren't
+useful, you can "push --overwrite" or "pull --overwrite" instead.
+"""
+
 
 # Register help topics
 topic_registry.register("revisionspec", _help_on_revisionspec,
@@ -662,6 +682,8 @@
                         'Information on working trees', SECT_CONCEPT)
 topic_registry.register('criss-cross', _criss_cross,
                         'Information on criss-cross merging', SECT_CONCEPT)
+topic_registry.register('sync-for-reconfigure', _branches_out_of_sync,
+                        'Information on criss-cross merging', SECT_CONCEPT)
 
 
 class HelpTopicIndex(object):

=== modified file 'bzrlib/reconfigure.py'
--- a/bzrlib/reconfigure.py	2008-04-12 05:48:07 +0000
+++ b/bzrlib/reconfigure.py	2008-04-24 04:58:42 +0000
@@ -203,6 +203,11 @@
             changes = self.tree.changes_from(self.tree.basis_tree())
             if changes.has_changed():
                 raise errors.UncommittedChanges(self.tree)
+        if self._create_reference and self.local_branch is not None:
+            reference_branch = branch.Branch.open(self._select_bind_location())
+            if (reference_branch.last_revision() !=
+                self.local_branch.last_revision()):
+                raise errors.UnsyncedBranches(self.bzrdir, reference_branch)
 
     def _select_bind_location(self):
         """Select a location to bind or create a reference to.

=== modified file 'bzrlib/tests/test_reconfigure.py'
--- a/bzrlib/tests/test_reconfigure.py	2008-04-12 06:37:15 +0000
+++ b/bzrlib/tests/test_reconfigure.py	2008-04-24 04:58:42 +0000
@@ -197,12 +197,25 @@
         self.assertRaises(errors.AlreadyCheckout,
                           reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
 
-    def test_checkout_to_lightweight(self):
+    def make_unsynced_checkout(self):
         parent = self.make_branch('parent')
         checkout = parent.create_checkout('checkout')
         checkout.commit('test', rev_id='new-commit', local=True)
+
+        # work around fetch bug 212908
+        checkout.commit('test2', local=True)
+        checkout.branch.set_last_revision_info(1, 'new-commit')
         reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
             checkout.bzrdir)
+        return checkout, parent, reconfiguration
+
+    def test_unsynced_checkout_to_lightweight(self):
+        checkout, parent, reconfiguration = self.make_unsynced_checkout()
+        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
+
+    def test_synced_checkout_to_lightweight(self):
+        checkout, parent, reconfiguration = self.make_unsynced_checkout()
+        parent.pull(checkout.branch)
         reconfiguration.apply()
         wt = checkout.bzrdir.open_workingtree()
         self.assertTrue(parent.repository.has_same_location(
@@ -215,6 +228,10 @@
         parent = self.make_branch('parent')
         child = parent.bzrdir.sprout('child').open_workingtree()
         child.commit('test', rev_id='new-commit')
+        parent.pull(child.branch)
+        # work around fetch bug 212908
+        child.commit('test', rev_id='new-commit2')
+        child.branch.set_last_revision_info(1, 'new-commit')
         child.bzrdir.destroy_workingtree()
         reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
             child.bzrdir)
@@ -352,3 +369,18 @@
         tree = self.make_branch_and_tree('tree')
         self.assertRaises(errors.AlreadyStandalone,
                           reconfigure.Reconfigure.to_standalone, tree.bzrdir)
+
+    def make_unsynced_branch_reconfiguration(self):
+        parent = self.make_branch_and_tree('parent')
+        parent.commit('commit 1')
+        child = parent.bzrdir.sprout('child').open_workingtree()
+        child.commit('commit 2')
+        return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
+
+    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
+        reconfiguration = self.make_unsynced_branch_reconfiguration()
+        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
+
+    def test_unsynced_branch_to_lightweight_checkout_forced(self):
+        reconfiguration = self.make_unsynced_branch_reconfiguration()
+        reconfiguration.apply(force=True)




More information about the bazaar-commits mailing list