Fix bug in new follow_branch functions.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 26 Dec 2006 23:37:35 +0000 (00:37 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 26 Dec 2006 23:37:35 +0000 (00:37 +0100)
logwalker.py
repository.py
tests/test_logwalker.py
tests/test_repos.py
transport.py

index 04ff1e2cb95a7c2747a51473ee1127223a26ddbd..acd981ca7697e817736ff2780f332eee3b7c8d3e 100644 (file)
@@ -130,8 +130,7 @@ class LogWalker(object):
         pool = Pool()
         try:
             try:
-                mutter('getting log %r:%r' % (self.saved_revnum, to_revnum))
-                self.transport.get_log(["/"], self.saved_revnum, to_revnum, 
+                self.transport.get_log("/", self.saved_revnum, to_revnum, 
                                0, True, True, rcvr, pool)
             finally:
                 pb.clear()
@@ -161,26 +160,24 @@ class LogWalker(object):
 
         path = path.strip("/")
 
-        i = revnum
-        while i > 0:
-            revpaths = self.get_revision_paths(i, path)
-            yield (path, revpaths, i)
-
-            if (revpaths.has_key(path) and
-                revpaths[path][0] in ('A', 'R') and
-                revpaths[path][1] is None):
-               # this path didn't exist before this revision
-               return
-
-            if (not path is None and 
-                path in revpaths and 
-                not revpaths[path][1] is None):
-                # In this revision, this path was copied from 
-                # somewhere else
-                i = revpaths[path][2]
-                path = revpaths[path][1]
-            else:
-                i-=1
+        while revnum > 0:
+            revpaths = self.get_revision_paths(revnum, path)
+
+            if revpaths != {}:
+                yield (path, revpaths, revnum)
+
+            if revpaths.has_key(path):
+                if revpaths[path][1] is None:
+                    if revpaths[path][0] in ('A', 'R'):
+                        # this path didn't exist before this revision
+                        return
+                else:
+                    # In this revision, this path was copied from 
+                    # somewhere else
+                    revnum = revpaths[path][2]
+                    path = revpaths[path][1]
+                    continue
+            revnum-=1
 
     def get_revision_paths(self, revnum, path=None):
         """Obtain dictionary with all the changes in a particular revision.
index 154c82b906d3c2eaf904dc105df5cbcd78161a52..d4b66cd14db26c61e3f0689e2b08766be3b3e88f 100644 (file)
@@ -513,6 +513,7 @@ class SvnRepository(Repository):
                     # 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 originated here.
+                    mutter('breaking off "split"')
                     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)
index 59fe772d0be91f3189dc24cbd0813457f7f54778..33516930e8701e31dcbd5dde66a2f4892f1bdc17 100644 (file)
@@ -65,7 +65,6 @@ class TestLogWalker(TestCaseWithSubversionRepository):
         self.assertRaises(NoSuchRevision, list, 
                           walker.follow_path("/", 20))
 
-
     def test_branch_log_all(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/trunk/file': "data", "dc/foo/file":"data"})
@@ -93,6 +92,26 @@ class TestLogWalker(TestCaseWithSubversionRepository):
         self.assertEqual(1, len(list(walker.follow_path("branches/brancha",
             1))))
 
+    def test_follow_path_ignore_unchanged(self):
+        repos_url = self.make_client("a", "dc")
+        self.build_tree({'dc/branches': None})
+        self.client_add("dc/branches")
+        self.build_tree({
+            'dc/branches/brancha': None,
+            'dc/branches/branchab': None,
+            'dc/branches/brancha/data': "data", 
+            "dc/branches/branchab/data":"data"})
+        self.client_add("dc/branches/brancha")
+        self.client_commit("dc", "My Message")
+
+        self.client_add("dc/branches/branchab")
+        self.client_commit("dc", "My Message2")
+
+        walker = logwalker.LogWalker(transport=SvnRaTransport(repos_url))
+
+        self.assertEqual(1, len(list(walker.follow_path("branches/brancha",
+            2))))
+
     def test_find_latest_none(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/branches': None})
@@ -239,7 +258,9 @@ class TestLogWalker(TestCaseWithSubversionRepository):
         walker = logwalker.LogWalker(transport=SvnRaTransport(repos_url))
 
         items = list(walker.follow_path("branches/abranch", 2))
-        self.assertEqual(2, len(items))
+        self.assertEqual([('branches/abranch', {'branches/abranch': ('A', 'trunk', 1)}, 2), 
+                          ('trunk', {'trunk/afile': ('A', None, -1), 
+                                     'trunk': (u'A', None, -1)}, 1)], items)
 
     def test_touches_path(self):
         repos_url = self.make_client("a", "dc")
index 46d70498ab5b1a264bcb01f54778e0fc14891a6f..e101d7e01669c5eeb45d011544bb5a8caf5088a6 100644 (file)
@@ -78,6 +78,24 @@ class TestSubversionRepositoryWorks(TestCaseWithSubversionRepository):
 
         self.assertEqual(1, len(list(repos.follow_history(1))))
 
+    def test_follow_history_follow(self):
+        repos_url = self.make_client("a", "dc")
+        self.build_tree({'dc/trunk/afile': "data", "dc/branches": None})
+        self.client_add("dc/trunk")
+        self.client_add("dc/branches")
+        self.client_commit("dc", "My Message")
+
+        self.client_copy("dc/trunk", "dc/branches/abranch")
+        self.client_commit("dc", "Create branch")
+
+        repos = Repository.open(repos_url)
+        repos.set_branching_scheme(TrunkBranchingScheme())
+
+        items = list(repos.follow_history(2))
+        self.assertEqual([('branches/abranch', {'branches/abranch': ('A', 'trunk', 1)}, 2), 
+                          ('trunk', {'trunk/afile': ('A', None, -1), 
+                                     'trunk': (u'A', None, -1)}, 1)], items)
+
     def test_branch_log_specific(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({
@@ -95,6 +113,27 @@ class TestSubversionRepositoryWorks(TestCaseWithSubversionRepository):
         self.assertEqual(1, len(list(repos.follow_branch_history("branches/brancha",
             1))))
 
+    def test_branch_log_specific_ignore(self):
+        repos_url = self.make_client("a", "dc")
+        self.build_tree({'dc/branches': None})
+        self.client_add("dc/branches")
+        self.build_tree({
+            'dc/branches/brancha': None,
+            'dc/branches/branchab': None,
+            'dc/branches/brancha/data': "data", 
+            "dc/branches/branchab/data":"data"})
+        self.client_add("dc/branches/brancha")
+        self.client_commit("dc", "My Message")
+
+        self.client_add("dc/branches/branchab")
+        self.client_commit("dc", "My Message2")
+
+        repos = Repository.open(repos_url)
+        repos.set_branching_scheme(TrunkBranchingScheme())
+
+        self.assertEqual(1, len(list(repos.follow_branch_history("branches/brancha",
+            2))))
+
     def test_find_branches_no(self):
         repos_url = self.make_client("a", "dc")
 
index 8d3336b54e6d4dd365edce9d4e536cfa2768db9e..efea713a3ad15afbc0ac42129240bd6661b31074 100644 (file)
@@ -142,15 +142,17 @@ class SvnRaTransport(Transport):
 
     @need_lock
     def get_uuid(self):
+        mutter('svn get-uuid')
         return svn.ra.get_uuid(self._ra)
 
     @need_lock
     def get_repos_root(self):
+        mutter("svn get-repos-root")
         return svn.ra.get_repos_root(self._ra)
 
     @need_lock
     def get_latest_revnum(self):
-        mutter("svn latest-revnum")
+        mutter("svn get-latest-revnum")
         return svn.ra.get_latest_revnum(self._ra)
 
     @need_lock
@@ -159,8 +161,9 @@ class SvnRaTransport(Transport):
         return svn.ra.do_switch(self._ra, switch_rev, switch_target, *args, **kwargs)
 
     @need_lock
-    def get_log(self, *args, **kwargs):
-        return svn.ra.get_log(self._ra, *args, **kwargs)
+    def get_log(self, path, from_revnum, to_revnum, *args, **kwargs):
+        mutter('svn log %r:%r %r' % (from_revnum, to_revnum, path))
+        return svn.ra.get_log(self._ra, [path], from_revnum, to_revnum, *args, **kwargs)
 
     @need_lock
     def reparent(self, url):
@@ -170,6 +173,7 @@ class SvnRaTransport(Transport):
         self.base = url
         self.svn_url = url
         if hasattr(svn.ra, 'reparent'):
+            mutter('svn reparent %r' % url)
             svn.ra.reparent(self._ra, url, self.pool)
         else:
             self._ra = svn.client.open_ra_session(self.svn_url.encode('utf8'),