Rev 3881: (Jelmer) Add BzrDir.backup_bzrdir(). in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Dec 5 17:21:40 GMT 2008


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

------------------------------------------------------------
revno: 3881
revision-id: pqm at pqm.ubuntu.com-20081205172136-vccv8ynqac6sxr5s
parent: pqm at pqm.ubuntu.com-20081205161407-zulgn2hssd85nsdk
parent: jelmer at samba.org-20081205024239-n9o1ezqlz6bmdc36
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-12-05 17:21:36 +0000
message:
  (Jelmer) Add BzrDir.backup_bzrdir().
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
  bzrlib/upgrade.py              history2weaves.py-20050818063535-e7d319791c19a8b2
    ------------------------------------------------------------
    revno: 3872.3.3
    revision-id: jelmer at samba.org-20081205024239-n9o1ezqlz6bmdc36
    parent: jelmer at samba.org-20081205014155-y7sf11idc86fpsrw
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: backup-bzrdir
    timestamp: Fri 2008-12-05 03:42:39 +0100
    message:
      Add test for backup_bzrdir.
    modified:
      bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
    ------------------------------------------------------------
    revno: 3872.3.2
    revision-id: jelmer at samba.org-20081205014155-y7sf11idc86fpsrw
    parent: jelmer at samba.org-20081129151331-99uadxvmyt3ku0ly
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: backup-bzrdir
    timestamp: Fri 2008-12-05 02:41:55 +0100
    message:
      make backup_bzrdir determine the name for the backup files.
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/upgrade.py              history2weaves.py-20050818063535-e7d319791c19a8b2
    ------------------------------------------------------------
    revno: 3872.3.1
    revision-id: jelmer at samba.org-20081129151331-99uadxvmyt3ku0ly
    parent: pqm at pqm.ubuntu.com-20081128071639-usprv2emoq2mgxnw
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: bzr.dev
    timestamp: Sat 2008-11-29 16:13:31 +0100
    message:
      Allow BzrDir implementation to implement backing up of control directory.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/upgrade.py              history2weaves.py-20050818063535-e7d319791c19a8b2
=== modified file 'NEWS'
--- a/NEWS	2008-12-05 15:34:02 +0000
+++ b/NEWS	2008-12-05 17:21:36 +0000
@@ -15,6 +15,9 @@
   IMPROVEMENTS:
 
   BUG FIXES:
+  
+   * Allow BzrDir implementation to implement backing up of 
+     control directory. (#139691)
 
     * Fix SystemError in ``_patiencediff_c`` module by calling
       PyErr_NoMemory() before returning NULL in PatienceSequenceMatcher_new.

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2008-12-01 19:07:21 +0000
+++ b/bzrlib/bzrdir.py	2008-12-05 17:21:36 +0000
@@ -516,6 +516,15 @@
         """
         raise NotImplementedError(self.create_workingtree)
 
+    def backup_bzrdir(self):
+        """Backup this bzr control directory.
+        
+        :return: Tuple with old path name and new path name
+        """
+        self.root_transport.copy_tree('.bzr', 'backup.bzr')
+        return (self.root_transport.abspath('.bzr'),
+                self.root_transport.abspath('backup.bzr'))
+
     def retire_bzrdir(self, limit=10000):
         """Permanently disable the bzrdir.
 

=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py	2008-08-28 20:51:27 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py	2008-12-05 02:42:39 +0000
@@ -28,11 +28,13 @@
     bzrdir,
     errors,
     lockdir,
+    osutils,
     repository,
     revision as _mod_revision,
     transactions,
     transport,
     ui,
+    urlutils,
     workingtree,
     )
 from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
@@ -1476,6 +1478,27 @@
                 format=dir._format), bzrdir.Converter))
         dir.needs_format_conversion(None)
 
+    def test_backup_copies_existing(self):
+        tree = self.make_branch_and_tree('test')
+        self.build_tree(['test/a'])
+        tree.add(['a'], ['a-id'])
+        tree.commit('some data to be copied.')
+        old_url, new_url = tree.bzrdir.backup_bzrdir()
+        old_path = urlutils.local_path_from_url(old_url)
+        new_path = urlutils.local_path_from_url(new_url)
+        self.failUnlessExists(old_path)
+        self.failUnlessExists(new_path)
+        for (((dir_relpath1, _), entries1), 
+             ((dir_relpath2, _), entries2)) in izip(
+                osutils.walkdirs(old_path), 
+                osutils.walkdirs(new_path)):
+            self.assertEquals(dir_relpath1, dir_relpath2)
+            for f1, f2 in zip(entries1, entries2):
+                self.assertEquals(f1[0], f2[0])
+                self.assertEquals(f1[2], f2[2])
+                if f1[2] == "file":
+                    osutils.compare_files(open(f1[4]), open(f2[4]))
+
     def test_upgrade_new_instance(self):
         """Does an available updater work?"""
         dir = self.make_bzrdir('.')

=== modified file 'bzrlib/upgrade.py'
--- a/bzrlib/upgrade.py	2008-08-07 00:25:38 +0000
+++ b/bzrlib/upgrade.py	2008-12-05 01:41:55 +0000
@@ -75,10 +75,8 @@
 
     def _backup_control_dir(self):
         self.pb.note('making backup of tree history')
-        self.transport.copy_tree('.bzr', 'backup.bzr')
-        self.pb.note('%s.bzr has been backed up to %sbackup.bzr',
-             self.transport.base,
-             self.transport.base)
+        old_path, new_path = self.bzrdir.backup_bzrdir()
+        self.pb.note('%s has been backed up to %s', old_path, new_path)
         self.pb.note('if conversion fails, you can move this directory back to .bzr')
         self.pb.note('if it succeeds, you can remove this directory if you wish')
 




More information about the bazaar-commits mailing list