Rev 309: Rather than bailing out on dir upgrades, simply cut off history for now. in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Tue Dec 26 21:09:31 GMT 2006


------------------------------------------------------------
revno: 309
revision-id: jelmer at samba.org-20061226210852-oo9vf8m883pb5wka
parent: jelmer at samba.org-20061226195841-9zmend5nbjy6hn5v
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Tue 2006-12-26 22:08:52 +0100
message:
  Rather than bailing out on dir upgrades, simply cut off history for now.
modified:
  fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  logwalker.py                   logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  tests/test_repos.py            test_repos.py-20060508151940-ddc49a59257ca712
=== modified file 'fetch.py'
--- a/fetch.py	2006-12-26 16:12:40 +0000
+++ b/fetch.py	2006-12-26 21:08:52 +0000
@@ -285,8 +285,11 @@
         needed = []
         parents = {}
         prev_revid = None
-        for (branch, changes, revnum) in \
-            self.source.follow_history(path, until_revnum):
+        if path is None:
+            it = self.source.follow_history(until_revnum)
+        else:
+            it = self.source.follow_branch_history(path, until_revnum)
+        for (branch, changes, revnum) in it:
             revid = self.source.generate_revision_id(revnum, branch)
 
             if prev_revid is not None:

=== modified file 'fileids.py'
--- a/fileids.py	2006-12-26 19:58:41 +0000
+++ b/fileids.py	2006-12-26 21:08:52 +0000
@@ -126,7 +126,7 @@
         todo = []
         next_parent_revs = []
         map = {"": (ROOT_ID, None)} # No history -> empty map
-        for (bp, paths, rev) in self.repos.follow_history(branch, revnum):
+        for (bp, paths, rev) in self.repos.follow_branch_history(branch, revnum):
             revid = generate_svn_revision_id(uuid, rev, bp)
             map = self.load(revid)
             if map != {}:
@@ -193,7 +193,6 @@
                     mutter('%r:%s copied from %r:%s' % (p, revid, data[1], data[2]))
                     assert find_children is not None, 'incomplete data for %r' % p
                     for c in find_children(data[1], data[2]):
-                        mutter('replacing %r with %r' % (data[1], p))
                         path = c.replace(data[1], p+"/", 1).replace("//", "/")
                         map[path] = generate_file_id(revid, c), revid
                         mutter('added mapping %r -> %r' % (path, map[path]))

=== modified file 'logwalker.py'
--- a/logwalker.py	2006-12-26 19:58:41 +0000
+++ b/logwalker.py	2006-12-26 21:08:52 +0000
@@ -83,6 +83,7 @@
           create table if not exists revision(revno integer unique, author text, message text, date text);
           create unique index if not exists revision_revno on revision (revno);
           create table if not exists changed_path(rev integer, action text, path text, copyfrom_path text, copyfrom_rev integer);
+          create index if not exists path_rev on changed_path(rev);
           create index if not exists path_rev_path on changed_path(rev, path);
         """)
         self.db.commit()
@@ -175,7 +176,7 @@
 
             continue_revnum = None
 
-            revpaths = self.get_revision_paths(i)
+            revpaths = self.get_revision_paths(i, branch_path)
             yield (branch_path, revpaths, i)
 
             if (not branch_path is None and 
@@ -192,10 +193,11 @@
                 continue_revnum = revpaths[branch_path][2]
                 branch_path = revpaths[branch_path][1]
 
-    def get_revision_paths(self, revnum):
+    def get_revision_paths(self, revnum, path=None):
         """Obtain dictionary with all the changes in a particular revision.
 
         :param revnum: Subversion revision number
+        :param path: optional path under which to return all entries
         :returns: dictionary with paths as keys and 
                   (action, copyfrom_path, copyfrom_rev) as values.
         """
@@ -203,8 +205,14 @@
         if revnum > self.saved_revnum:
             self.fetch_revisions(revnum)
 
+        query = "select path, action, copyfrom_path, copyfrom_rev from changed_path where rev="+str(revnum)
+        if path is not None and path != "":
+            query += " and (path='%s' or path like '%s/%%')" % (path, path)
+
+        mutter('query: %r' % query)
+
         paths = {}
-        for p, act, cf, cr in self.db.execute("select path, action, copyfrom_path, copyfrom_rev from changed_path where rev="+str(revnum)):
+        for p, act, cf, cr in self.db.execute(query):
             paths[p] = (act, cf, cr)
         return paths
 

=== modified file 'repository.py'
--- a/repository.py	2006-12-26 19:58:41 +0000
+++ b/repository.py	2006-12-26 21:08:52 +0000
@@ -496,30 +496,20 @@
         return osutils.sha_string(self.get_revision_xml(revision_id))
 
     def follow_branch(self, branch_path, revnum):
-        for (bp, _, rev) in self.follow_history(branch_path, revnum):
+        for (bp, _, rev) in self.follow_branch_history(branch_path, revnum):
             yield (bp, rev)
 
-    def follow_history(self, branch_path, revnum):
-        if not branch_path is None and not self.scheme.is_branch(branch_path):
-            raise errors.NotSvnBranchPath(branch_path, revnum)
-
-        for (branch_path, paths, revnum) in self._log.follow_history(branch_path, revnum):
+    def follow_history(self, revnum):
+        for (branch_path, paths, revnum) in self._log.follow_history(None, revnum):
             changed_paths = {}
             for p in paths:
-                if (branch_path is None or 
-                    p == branch_path or
-                    branch_path == "" or
-                    p.startswith(branch_path+"/")):
-
-                    try:
-                        (bp, rp) = self.scheme.unprefix(p)
-                        if not changed_paths.has_key(bp):
-                            changed_paths[bp] = {}
-                        changed_paths[bp][p] = paths[p]
-                    except NotBranchError:
-                        pass
-
-            assert branch_path is None or len(changed_paths) <= 1
+                try:
+                    (bp, rp) = self.scheme.unprefix(p)
+                    if not changed_paths.has_key(bp):
+                        changed_paths[bp] = {}
+                    changed_paths[bp][p] = paths[p]
+                except NotBranchError:
+                    pass
 
             for bp in changed_paths:
                 if (changed_paths[bp].has_key(bp) and 
@@ -527,9 +517,41 @@
                     not self.scheme.is_branch(changed_paths[bp][bp][1])):
                     # FIXME: if copyfrom_path is not a branch path, 
                     # should simulate a reverse "split" of a branch
-                    raise errors.DirUpgrade((changed_paths[bp][bp][1], changed_paths[bp][bp][2]), (bp, revnum))
+                    # for now, just make it look like the branch ended here
+                    for c in self._log.find_children(changed_paths[bp][bp][1], changed_paths[bp][bp][2]):
+                        path = c.replace(changed_paths[bp][bp][1], bp+"/", 1).replace("//", "/")
+                        changed_paths[bp][path] = ('A', None, -1)
+                    changed_paths[bp][bp] = ('A', None, -1)
+
                 yield (bp, changed_paths[bp], revnum)
 
+    def follow_branch_history(self, branch_path, revnum):
+        assert branch_path is not None
+        if not self.scheme.is_branch(branch_path):
+            raise errors.NotSvnBranchPath(branch_path, revnum)
+
+        for (bp, paths, revnum) in self._log.follow_history(branch_path, revnum):
+            changed_paths = {}
+            for p in paths:
+                (bp_, _) = self.scheme.unprefix(p)
+                assert bp_ == bp
+                changed_paths[p] = paths[p]
+
+            if (changed_paths.has_key(bp) and 
+                changed_paths[bp][1] is not None and
+                not self.scheme.is_branch(changed_paths[bp][1])):
+                # FIXME: if copyfrom_path is not a branch path, 
+                # should simulate a reverse "split" of a branch
+                # for now, just make it look like the branch ended here
+                for c in self._log.find_children(changed_paths[bp][1], changed_paths[bp][2]):
+                    path = c.replace(changed_paths[bp][1], bp+"/", 1).replace("//", "/")
+                    changed_paths[path] = ('A', None, -1)
+                changed_paths[bp] = ('A', None, -1)
+
+                yield (bp, changed_paths, revnum)
+                return
+                     
+            yield (bp, changed_paths, revnum)
 
     def has_signature_for_revision_id(self, revision_id):
         # TODO: Retrieve from SVN_PROP_BZR_SIGNATURE 

=== modified file 'tests/test_repos.py'
--- a/tests/test_repos.py	2006-12-26 19:58:41 +0000
+++ b/tests/test_repos.py	2006-12-26 21:08:52 +0000
@@ -14,6 +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.branch import Branch
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import NoSuchRevision, BzrError
 from bzrlib.inventory import Inventory
@@ -66,7 +67,7 @@
         self.assertRaises(NoSuchRevision, list, 
                           repos.follow_branch("/", 20))
 
-    def test_branch_log_all(self):
+    def test_history_all(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/trunk/file': "data", "dc/foo/file":"data"})
         self.client_add("dc/trunk")
@@ -75,7 +76,7 @@
 
         repos = Repository.open(repos_url)
 
-        self.assertEqual(1, len(list(repos.follow_branch(None, 1))))
+        self.assertEqual(1, len(list(repos.follow_history(1))))
 
     def test_branch_log_specific(self):
         repos_url = self.make_client("a", "dc")
@@ -1151,14 +1152,11 @@
         oldrepos.set_branching_scheme(TrunkBranchingScheme())
         dir = BzrDir.create("f")
         newrepos = dir.create_repository()
-        self.assertRaises(BzrError, oldrepos.copy_content_into, newrepos)
-        try:
-            oldrepos.copy_content_into(newrepos)
-        except BzrError, e:
-            self.assertEqual("trunk/lib", e.from_path)
-            self.assertEqual(1, e.from_revnum)
-            self.assertEqual("branches/mybranch", e.to_path)
-            self.assertEqual(2, e.to_revnum)
+        oldrepos.copy_content_into(newrepos)
+
+        branch = Branch.open("%s/branches/mybranch" % repos_url)
+        self.assertEqual(['svn-v%d:2@%s-branches%%2fmybranch' % (MAPPING_VERSION, oldrepos.uuid)], 
+                         branch.revision_history())
 
 
     def test_fetch_branch_downgrade(self):




More information about the bazaar-commits mailing list