Rev 1599: Remove branches removed in svn during svn-import. in http://people.samba.org/bzr/jelmer/bzr-svn/trunk

Jelmer Vernooij jelmer at samba.org
Fri Aug 22 16:47:04 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-svn/trunk

------------------------------------------------------------
revno: 1599
revision-id: jelmer at samba.org-20080822154702-khhrbp4xgdl7ve8d
parent: jelmer at samba.org-20080822150915-1dd2ufo5tu11j55m
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Fri 2008-08-22 17:47:02 +0200
message:
  Remove branches removed in svn during svn-import.
modified:
  NEWS                           news-20061231030336-h9fhq245ie0de8bs-1
  __init__.py                    __init__.py-20051008155114-eae558e6cf149e1d
  convert.py                     svn2bzr.py-20051018015439-cb4563bff29e632d
  mapping3/__init__.py           __init__.py-20080502174630-9324zh25kka98vlw-1
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  revids.py                      revids.py-20070416220458-36vfa0730cchevp1-1
  tests/test_convert.py          test_convert.py-20060705203611-b1l0bapeku6foco0-1
=== modified file 'NEWS'
--- a/NEWS	2008-08-22 10:08:07 +0000
+++ b/NEWS	2008-08-22 15:47:02 +0000
@@ -12,6 +12,11 @@
 
    * Parse http redirect errors in some non-English locales better.
 
+  FEATURES
+
+   * svn-import will now remove branches removed in Subversion. 
+     (#246243)
+
 bzr-svn 0.4.11~rc1	2008-08-08
 
   CHANGES

=== modified file '__init__.py'
--- a/__init__.py	2008-08-09 03:04:16 +0000
+++ b/__init__.py	2008-08-22 15:47:02 +0000
@@ -218,6 +218,8 @@
                      Option('scheme', type=get_scheme,
                          help='Branching scheme (none, trunk, etc). '
                               'Default: auto.'),
+                     Option('keep', 
+                            help="Don't delete branches removed in Subversion"),
                      Option('prefix', type=str, 
                          help='Only consider branches of which path starts '
                               'with prefix.')
@@ -225,7 +227,7 @@
 
     @display_command
     def run(self, from_location, to_location=None, trees=False, 
-            standalone=False, scheme=None, all=False, prefix=None):
+            standalone=False, scheme=None, all=False, prefix=None, keep=False):
         from bzrlib.branch import Branch
         from bzrlib.bzrdir import BzrDir
         from bzrlib.errors import BzrCommandError, NoRepositoryPresent, NotBranchError
@@ -285,7 +287,9 @@
                 return True
 
             convert_repository(from_repos, to_location, scheme, None, 
-                               not standalone, trees, all, filter_branch=filter_branch)
+                               not standalone, trees, all, 
+                               filter_branch=filter_branch,
+                               keep=keep)
 
             if tmp_repos is not None:
                 from bzrlib import osutils

=== modified file 'convert.py'
--- a/convert.py	2008-08-22 15:09:15 +0000
+++ b/convert.py	2008-08-22 15:47:02 +0000
@@ -14,7 +14,10 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Conversion of full repositories."""
-from bzrlib import ui, urlutils
+
+import os
+
+from bzrlib import osutils, ui, urlutils
 from bzrlib.bzrdir import BzrDir, Converter
 from bzrlib.errors import (BzrError, NotBranchError, NoSuchFile, 
                            NoRepositoryPresent, NoSuchRevision) 
@@ -23,6 +26,7 @@
 from bzrlib.transport import get_transport
 
 from bzrlib.plugins.svn import repos
+from bzrlib.plugins.svn.branch import SvnBranch
 from bzrlib.plugins.svn.core import SubversionException
 from bzrlib.plugins.svn.errors import ERR_STREAM_MALFORMED_DATA
 from bzrlib.plugins.svn.format import get_rich_root_format
@@ -82,7 +86,7 @@
 
 def convert_repository(source_repos, output_url, scheme=None, layout=None,
                        create_shared_repo=True, working_trees=False, all=False,
-                       format=None, filter_branch=None):
+                       format=None, filter_branch=None, keep=False):
     """Convert a Subversion repository and its' branches to a 
     Bazaar repository.
 
@@ -131,7 +135,20 @@
 
     source_repos.lock_read()
     try:
-        existing_branches = source_repos.find_branches(layout=layout)
+        from_revnum = 0
+        to_revnum = source_repos.get_latest_revnum()
+        changed_branches = source_repos.find_fileprop_branches(layout=layout, 
+            from_revnum=from_revnum, to_revnum=to_revnum, check_removed=True)
+        existing_branches = []
+        removed_branches = []
+        for (bp, revnum, exists) in changed_branches:
+            if not exists and not keep:
+                removed_branches.append((bp, revnum))
+            elif exists:
+                try:
+                    existing_branches.append(SvnBranch(source_repos, bp))
+                except NotBranchError: # Skip non-directories
+                    pass
         if filter_branch is not None:
             existing_branches = filter(filter_branch, existing_branches)
 
@@ -145,6 +162,15 @@
                   inter._supports_branches):
                 inter.fetch(branches=existing_branches)
 
+        # Remove removed branches
+        for (bp, revnum) in removed_branches:
+            # TODO: Perhaps check if path is a valid branch with the right last
+            # revid?
+            fullpath = to_transport.local_abspath(bp)
+            if not os.path.isdir(fullpath):
+                continue
+            osutils.rmtree(fullpath)
+
         source_graph = source_repos.get_graph()
         pb = ui.ui_factory.nested_progress_bar()
         try:

=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py	2008-08-22 14:20:19 +0000
+++ b/mapping3/__init__.py	2008-08-22 15:47:02 +0000
@@ -125,13 +125,13 @@
     def get_branch_path(self, name, project=""):
         return self.scheme.get_branch_path(name, project)
 
-    def is_branch_parent(self, path):
+    def is_branch_parent(self, path, project=None):
         # Na, na, na...
-        return self.scheme.is_branch_parent(path)
+        return self.scheme.is_branch_parent(path, project)
 
-    def is_tag_parent(self, path):
+    def is_tag_parent(self, path, project=None):
         # Na, na, na...
-        return self.scheme.is_tag_parent(path)
+        return self.scheme.is_tag_parent(path, project)
 
     def push_merged_revisions(self, project=""):
         try:

=== modified file 'repository.py'
--- a/repository.py	2008-08-22 14:20:19 +0000
+++ b/repository.py	2008-08-22 15:47:02 +0000
@@ -785,10 +785,7 @@
         pb = ui.ui_factory.nested_progress_bar()
         try:
             for project, bp, nick in layout.get_branches(self.get_latest_revnum(), pb=pb):
-                try:
-                    branches.append(SvnBranch(self, bp, _skip_check=True))
-                except NotBranchError: # Skip non-directories
-                    pass
+                branches.append(SvnBranch(self, bp, _skip_check=True))
         finally:
             pb.finished()
         return branches
@@ -909,15 +906,13 @@
                 timezone, committer, revprops, revision_id)
 
     def find_fileprop_branches(self, layout, from_revnum, to_revnum, 
-                               project=None):
-        reuse_policy = self.get_config().get_reuse_revisions()
-        if reuse_policy in ("other-branches", "none") or from_revnum == 0:
-            for (project, branch, nick) in layout.get_branches(to_revnum, project):
-                yield (branch, to_revnum)
-        elif reuse_policy in ("other-branches", "removed-branches", "none"):
+                               project=None, check_removed=False):
+        if not check_removed and from_revnum == 0:
+            for (project, branch, nick) in layout.get_branches(to_revnum, 
+                                                               project):
+                yield (branch, to_revnum, True)
+        else:
             for (branch, revno, exists) in self.find_branchpaths(layout, 
                 from_revnum, to_revnum, project):
-                yield (branch, revno)
-        else:
-            assert False
+                yield (branch, revno, exists)
 

=== modified file 'revids.py'
--- a/revids.py	2008-08-22 05:02:07 +0000
+++ b/revids.py	2008-08-22 15:47:02 +0000
@@ -69,7 +69,10 @@
         raise NoSuchRevision(self, revid)
 
     def discover_revids(self, layout, from_revnum, to_revnum, project=None):
-        for (branch, revno) in self.repos.find_fileprop_branches(layout, from_revnum, to_revnum, project):
+        reuse_policy = self.get_config().get_reuse_revisions()
+        assert reuse_policy in ("other-branches", "removed-branches", "none") 
+        check_removed = (reuse_policy == "removed-branches")
+        for (branch, revno, exists) in self.repos.find_fileprop_branches(layout, from_revnum, to_revnum, project, check_removed=check_removed):
             assert isinstance(branch, str)
             assert isinstance(revno, int)
             # Look at their bzr:revision-id-vX

=== modified file 'tests/test_convert.py'
--- a/tests/test_convert.py	2008-07-15 14:06:23 +0000
+++ b/tests/test_convert.py	2008-08-22 15:47:02 +0000
@@ -189,6 +189,21 @@
         convert_repository(Repository.open(self.repos_url), "e", 
                            TrunkBranchingScheme(), create_shared_repo=True)
 
+    def test_shared_import_remove_nokeep(self):
+        convert_repository(Repository.open(self.repos_url), "e", 
+                TrunkBranchingScheme(), create_shared_repo=True)
+
+        dc = self.get_commit_editor()
+        dc.delete("trunk")
+        dc.close()
+
+        self.assertTrue(os.path.exists("e/trunk"))
+
+        convert_repository(Repository.open(self.repos_url), "e", 
+                           TrunkBranchingScheme(), create_shared_repo=True)
+
+        self.assertFalse(os.path.exists("e/trunk"))
+
     def test_shared_import_continue_with_wt(self):
         convert_repository(Repository.open(self.repos_url), "e", 
                 TrunkBranchingScheme(), working_trees=True)




More information about the bazaar-commits mailing list