changeset 1103:6e1dbf6cbc92

compathacks: new module to collect hacks to work around hg internals changing This includes branchset(), which provides a portable way to get the set of branches present in a repository.
author Augie Fackler <raf@durin42.com>
date Mon, 03 Feb 2014 01:55:56 -0500
parents 7635d30effa7
children 7d47a0f73135
files hgsubversion/compathacks.py hgsubversion/replay.py hgsubversion/stupid.py tests/comprehensive/test_rebuildmeta.py tests/test_fetch_branches.py tests/test_single_dir_clone.py tests/test_single_dir_push.py tests/test_tags.py
diffstat 8 files changed, 37 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/hgsubversion/compathacks.py
@@ -0,0 +1,11 @@
+"""Functions to work around API changes inside Mercurial."""
+
+def branchset(repo):
+  """Return the set of branches present in a repo.
+
+  Works around branchtags() vanishing between 2.8 and 2.9.
+  """
+  try:
+    return set(repo.branchmap())
+  except AttributeError:
+    return set(repo.branchtags())
--- a/hgsubversion/replay.py
+++ b/hgsubversion/replay.py
@@ -6,6 +6,7 @@ from mercurial import node
 from mercurial import context
 from mercurial import util as hgutil
 
+import compathacks
 import svnexternals
 import util
 
@@ -133,7 +134,7 @@ def _convert_rev(ui, meta, svn, r, tbdel
             tag = meta.get_path_tag(meta.remotename(branch))
             if (tag and tag not in meta.tags
                 and branch not in meta.branches
-                and branch not in meta.repo.branchtags()
+                and branch not in compathacks.branchset(meta.repo)
                 and not files):
                 continue
 
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -8,6 +8,7 @@ from mercurial import patch
 from mercurial import revlog
 from mercurial import util as hgutil
 
+import compathacks
 import svnwrap
 import svnexternals
 import util
@@ -773,7 +774,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
             # svnmeta.committag(), we can skip the whole branch for now
             if (tag and tag not in meta.tags and
                 b not in meta.branches
-                and b not in meta.repo.branchtags()
+                and b not in compathacks.branchset(meta.repo)
                 and not files_touched):
                 continue
 
--- a/tests/comprehensive/test_rebuildmeta.py
+++ b/tests/comprehensive/test_rebuildmeta.py
@@ -16,6 +16,7 @@ from mercurial import extensions
 from mercurial import hg
 from mercurial import ui
 
+from hgsubversion import compathacks
 from hgsubversion import svncommands
 from hgsubversion import svnmeta
 
@@ -119,7 +120,11 @@ def _run_assertions(self, name, single, 
                                 'rebuildmeta unexpected match on youngest rev!')
             continue
         self.assertMultiLineEqual(old, new, tf + ' differs')
-        self.assertEqual(src.branchtags(), dest.branchtags())
+        try:
+          self.assertEqual(src.branchmap(), dest.branchmap())
+        except AttributeError:
+          # hg 2.8 and earlier
+          self.assertEqual(src.branchtags(), dest.branchtags())
     srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info')))
     destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info')))
     self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys()))
--- a/tests/test_fetch_branches.py
+++ b/tests/test_fetch_branches.py
@@ -6,6 +6,8 @@ from mercurial import error
 from mercurial import hg
 from mercurial import node
 
+from hgsubversion import compathacks
+
 class TestFetchBranches(test_util.TestBase):
     stupid_mode_tests = True
 
@@ -88,7 +90,7 @@ class TestFetchBranches(test_util.TestBa
                           'unorderedbranch.svndump', 'NaN')
         repo = self._load_fixture_and_fetch_with_anchor(
             'unorderedbranch.svndump', '4')
-        self.assertTrue('c' not in repo.branchtags())
+        self.assertTrue('c' not in compathacks.branchset(repo))
 
     def test_branches_weird_moves(self):
         repo = self._load_fixture_and_fetch('renamedproject.svndump',
--- a/tests/test_single_dir_clone.py
+++ b/tests/test_single_dir_clone.py
@@ -10,6 +10,8 @@ from mercurial import hg
 from mercurial import node
 from mercurial import ui
 
+from hgsubversion import compathacks
+
 class TestSingleDirClone(test_util.TestBase):
     stupid_mode_tests = True
 
@@ -17,7 +19,8 @@ class TestSingleDirClone(test_util.TestB
         repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
                                             layout='single',
                                             subdir='')
-        self.assertEqual(repo.branchtags().keys(), ['default'])
+        self.assertEqual(compathacks.branchset(repo),
+                         set(['default']))
         self.assertEqual(repo['tip'].manifest().keys(),
                          ['trunk/beta',
                           'tags/copied_tag/alpha',
@@ -31,8 +34,8 @@ class TestSingleDirClone(test_util.TestB
     def test_auto_detect_single(self):
         repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
                                             layout='auto')
-        self.assertEqual(repo.branchtags().keys(), ['default',
-                                                    'branch_from_tag'])
+        self.assertEqual(compathacks.branchset(repo),
+                         set(['default', 'branch_from_tag']))
         oldmanifest = test_util.filtermanifest(repo['default'].manifest().keys())
         # remove standard layout
         shutil.rmtree(self.wc_path)
@@ -40,7 +43,7 @@ class TestSingleDirClone(test_util.TestB
         repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
                                             layout='auto',
                                             subdir='trunk')
-        self.assertEqual(repo.branchtags().keys(), ['default', ])
+        self.assertEqual(compathacks.branchset(repo), set(['default', ]))
         self.assertEqual(repo['default'].manifest().keys(), oldmanifest)
 
     def test_clone_subdir_is_file_prefix(self):
@@ -48,7 +51,7 @@ class TestSingleDirClone(test_util.TestB
         repo = self._load_fixture_and_fetch(FIXTURE,
                                             layout='single',
                                             subdir=test_util.subdir[FIXTURE])
-        self.assertEqual(repo.branchtags().keys(), ['default'])
+        self.assertEqual(compathacks.branchset(repo), set(['default']))
         self.assertEqual(repo['tip'].manifest().keys(), ['flaf.txt'])
 
     def test_externals_single(self):
--- a/tests/test_single_dir_push.py
+++ b/tests/test_single_dir_push.py
@@ -10,6 +10,8 @@ from mercurial import hg
 from mercurial import node
 from mercurial import ui
 
+from hgsubversion import compathacks
+
 class TestSingleDirPush(test_util.TestBase):
     stupid_mode_tests = True
     obsolete_mode_tests = True
@@ -149,7 +151,7 @@ class TestSingleDirPush(test_util.TestBa
         self.pushrevisions()
         repo = self.repo # repo is outdated after the rebase happens, refresh
         self.assertTrue('foo' in test_util.svnls(repo_path, ''))
-        self.assertEqual(repo.branchtags().keys(), ['default'])
+        self.assertEqual(compathacks.branchset(repo), set(['default']))
         # Have to cross to another branch head, so hg.update doesn't work
         commands.update(ui.ui(),
                         self.repo,
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -8,6 +8,7 @@ from mercurial import hg
 from mercurial import node
 from mercurial import ui
 
+from hgsubversion import compathacks
 from hgsubversion import svncommands
 from hgsubversion import svnrepo
 
@@ -47,7 +48,7 @@ rename a tag
 
     def test_branch_from_tag(self):
         repo = self._load_fixture_and_fetch('branch_from_tag.svndump')
-        self.assert_('branch_from_tag' in repo.branchtags())
+        self.assert_('branch_from_tag' in compathacks.branchset(repo))
         self.assertEqual(repo[1], repo['tag_r3'])
         self.assertEqual(repo['branch_from_tag'].parents()[0], repo['copied_tag'])