Rev 313: Supporting copying directories from non-branch paths. in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Wed Dec 27 00:28:07 GMT 2006


------------------------------------------------------------
revno: 313
revision-id: jelmer at samba.org-20061227002159-777owqcr37aji4kv
parent: jelmer at samba.org-20061226233735-g1nn2zjwz9kf2v3u
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Wed 2006-12-27 01:21:59 +0100
message:
  Supporting copying directories from non-branch paths.
modified:
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  tests/test_repos.py            test_repos.py-20060508151940-ddc49a59257ca712
=== modified file 'fileids.py'
--- a/fileids.py	2006-12-26 21:08:52 +0000
+++ b/fileids.py	2006-12-27 00:21:59 +0000
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from bzrlib.errors import RevisionNotPresent
+from bzrlib.errors import RevisionNotPresent, NotBranchError
 from bzrlib.inventory import ROOT_ID
 from bzrlib.knit import KnitVersionedFile
 from bzrlib.progress import ProgressBar
@@ -48,7 +48,7 @@
     return generate_svn_file_id(uuid, revnum, branch, path)
 
 
-def get_local_changes(paths, scheme, uuid):
+def get_local_changes(paths, scheme, uuid, find_children=None):
     new_paths = {}
     names = paths.keys()
     names.sort()
@@ -56,14 +56,23 @@
         data = paths[p]
         new_p = scheme.unprefix(p)[1]
         if data[1] is not None:
-            (cbp, crp) = scheme.unprefix(data[1])
+            try:
+                (cbp, crp) = scheme.unprefix(data[1])
 
-            # Branch copy
-            if (crp == "" and new_p == ""):
-                data = ('M', None, None)
-            else:
-                data = (data[0], crp, generate_svn_revision_id(
-                    uuid, data[2], cbp))
+                # Branch copy
+                if (crp == "" and new_p == ""):
+                    data = ('M', None, None)
+                else:
+                    data = (data[0], crp, generate_svn_revision_id(
+                        uuid, data[2], cbp))
+            except NotBranchError:
+                # Copied from outside of a known branch
+                # Make it look like the files were added in this revision
+                assert find_children is not None
+                for c in find_children(data[1], data[2]):
+                    mutter('oops: %r child %r' % (data[1], c))
+                    new_paths[(new_p+"/"+c[len(data[1]):].strip("/")).strip("/")] = (data[0], None, -1)
+                data = (data[0], None, -1)
 
         new_paths[new_p] = data
     return new_paths
@@ -109,7 +118,7 @@
         :param global_changes: Dict with global changes that happened
         """
         changes = get_local_changes(global_changes, self.repos.scheme,
-                                        uuid)
+                                        uuid, self.repos._log.find_children)
 
         def find_children(path, revid):
             (_, bp, revnum) = parse_svn_revision_id(revid)
@@ -146,7 +155,7 @@
         i = 0
         for (revid, global_changes) in todo:
             changes = get_local_changes(global_changes, self.repos.scheme,
-                                        uuid)
+                                        uuid, self.repos._log.find_children)
             mutter('generating file id map for %r' % revid)
             if pb is not None:
                 pb.update('generating file id map', i, len(todo))

=== modified file 'tests/test_repos.py'
--- a/tests/test_repos.py	2006-12-26 23:37:35 +0000
+++ b/tests/test_repos.py	2006-12-27 00:21:59 +0000
@@ -1197,6 +1197,71 @@
         self.assertEqual(['svn-v%d:2@%s-branches%%2fmybranch' % (MAPPING_VERSION, oldrepos.uuid)], 
                          branch.revision_history())
 
+    def test_fetch_file_from_non_branch(self):
+        repos_url = self.make_client('d', 'dc')
+
+        self.build_tree({'dc/old-trunk/lib/file': 'data'})
+        self.client_add("dc/old-trunk")
+        self.client_commit("dc", "trunk data")
+
+        self.build_tree({'dc/trunk/lib': None})
+        self.client_add("dc/trunk")
+        self.client_copy("dc/old-trunk/lib/file", "dc/trunk/lib/file")
+        self.client_commit("dc", "revive old trunk")
+
+        oldrepos = Repository.open(repos_url)
+        oldrepos.set_branching_scheme(TrunkBranchingScheme())
+        dir = BzrDir.create("f")
+        newrepos = dir.create_repository()
+        oldrepos.copy_content_into(newrepos)
+
+        branch = Branch.open("%s/trunk" % repos_url)
+        self.assertEqual(['svn-v%d:2@%s-trunk' % (MAPPING_VERSION, oldrepos.uuid)], 
+                         branch.revision_history())
+
+    def test_fetch_dir_from_non_branch(self):
+        repos_url = self.make_client('d', 'dc')
+
+        self.build_tree({'dc/old-trunk/lib/file': 'data'})
+        self.client_add("dc/old-trunk")
+        self.client_commit("dc", "trunk data")
+
+        self.build_tree({'dc/trunk': None})
+        self.client_add("dc/trunk")
+        self.client_copy("dc/old-trunk/lib", "dc/trunk")
+        self.client_commit("dc", "revive old trunk")
+
+        oldrepos = Repository.open(repos_url)
+        oldrepos.set_branching_scheme(TrunkBranchingScheme())
+        dir = BzrDir.create("f")
+        newrepos = dir.create_repository()
+        oldrepos.copy_content_into(newrepos)
+
+        branch = Branch.open("%s/trunk" % repos_url)
+        self.assertEqual(['svn-v%d:2@%s-trunk' % (MAPPING_VERSION, oldrepos.uuid)], 
+                         branch.revision_history())
+
+    def test_fetch_from_non_branch(self):
+        repos_url = self.make_client('d', 'dc')
+
+        self.build_tree({'dc/old-trunk/lib/file': 'data'})
+        self.client_add("dc/old-trunk")
+        self.client_commit("dc", "trunk data")
+
+        self.client_copy("dc/old-trunk", "dc/trunk")
+        self.client_commit("dc", "revive old trunk")
+
+        oldrepos = Repository.open(repos_url)
+        oldrepos.set_branching_scheme(TrunkBranchingScheme())
+        dir = BzrDir.create("f")
+        newrepos = dir.create_repository()
+        oldrepos.copy_content_into(newrepos)
+
+        branch = Branch.open("%s/trunk" % repos_url)
+        self.assertEqual(['svn-v%d:2@%s-trunk' % (MAPPING_VERSION, oldrepos.uuid)], 
+                         branch.revision_history())
+
+
 
     def test_fetch_branch_downgrade(self):
         repos_url = self.make_client('d', 'dc')




More information about the bazaar-commits mailing list