changeset 1039:3df6ed4e7561

drop support for pre-2.0 versions of Mercurial
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Mon, 05 Aug 2013 20:49:53 +0200
parents aa043f64d8b7
children ada2400241c4
files README hgsubversion/editor.py hgsubversion/svncommands.py hgsubversion/util.py hgsubversion/verify.py hgsubversion/wrappers.py tests/test_fetch_branches.py
diffstat 7 files changed, 26 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/README
+++ b/README
@@ -16,7 +16,7 @@ Installation
 ------------
 You need to have either have Subversion 1.5 (or later) installed along with
 either Subvertpy 0.7.4 (or later) or the Subversion SWIG Python bindings. You
-need Mercurial 1.3 or later.
+need Mercurial 2.0 or later.
 
 .. _mercurial: http://selenic.com/repo/hg
 .. _mercurial-stable: http://selenic.com/repo/hg-stable
--- a/hgsubversion/editor.py
+++ b/hgsubversion/editor.py
@@ -191,7 +191,7 @@ class HgEditor(svnwrap.Editor):
         # A mapping of file paths to batons
         self._openpaths = {}
         self._deleted = set()
-        self._getctx = util.lrucachefunc(self.repo.changectx, 3)
+        self._getctx = hgutil.lrucachefunc(self.repo.changectx)
         # A stack of opened directory (baton, path) pairs.
         self._opendirs = []
         self._missing = set()
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -135,7 +135,7 @@ def _buildmeta(ui, repo, args, partial=F
     # of the repository instead. During this traversal, we find all converted
     # changesets that close a branch, and store their first parent
     for rev in xrange(startrev, len(repo)):
-        util.progress(ui, 'prepare', rev - startrev, total=numrevs)
+        ui.progress('prepare', rev - startrev, total=numrevs)
         try:
             ctx = repo[rev]
         except error.RepoError:
@@ -165,10 +165,10 @@ def _buildmeta(ui, repo, args, partial=F
                 closed.add(parentctx.rev())
 
     lastpulled.write(str(youngest) + '\n')
-    util.progress(ui, 'prepare', None, total=numrevs)
+    ui.progress('prepare', None, total=numrevs)
 
     for rev in xrange(startrev, len(repo)):
-        util.progress(ui, 'rebuild', rev-startrev, total=numrevs)
+        ui.progress('rebuild', rev-startrev, total=numrevs)
         try:
             ctx = repo[rev]
         except error.RepoError:
@@ -300,7 +300,7 @@ def _buildmeta(ui, repo, args, partial=F
                                   int(parentrev),
                                   revision)
 
-    util.progress(ui, 'rebuild', None, total=numrevs)
+    ui.progress('rebuild', None, total=numrevs)
 
     # save off branch info
     branchinfofile = open(os.path.join(svnmetadir, 'branch_info'), 'w')
--- a/hgsubversion/util.py
+++ b/hgsubversion/util.py
@@ -148,16 +148,6 @@ def pickle_atomic(data, file_path):
     else:
         f.close()
 
-# TODO remove when we drop 1.3 support
-def progress(ui, *args, **kwargs):
-    if getattr(ui, 'progress', False):
-        return ui.progress(*args, **kwargs)
-
-# TODO remove when we drop 1.5 support
-remoteui = getattr(cmdutil, 'remoteui', getattr(hg, 'remoteui', False))
-if not remoteui:
-    raise ImportError('Failed to import remoteui')
-
 def parseurl(url, heads=[]):
     parsed = hg.parseurl(url, heads)
     if len(parsed) == 3:
@@ -373,35 +363,6 @@ def getfilestoresize(ui):
         size = -1
     return size
 
-# Copy-paste from mercurial.util to avoid having to deal with backward
-# compatibility, plus the cache size is configurable.
-def lrucachefunc(func, size):
-    '''cache most recent results of function calls'''
-    cache = {}
-    order = deque()
-    if func.func_code.co_argcount == 1:
-        def f(arg):
-            if arg not in cache:
-                if len(cache) > size:
-                    del cache[order.popleft()]
-                cache[arg] = func(arg)
-            else:
-                order.remove(arg)
-            order.append(arg)
-            return cache[arg]
-    else:
-        def f(*args):
-            if args not in cache:
-                if len(cache) > size:
-                    del cache[order.popleft()]
-                cache[args] = func(*args)
-            else:
-                order.remove(args)
-            order.append(args)
-            return cache[args]
-
-    return f
-
 def parse_revnum(svnrepo, r):
     try:
         return int(r or 0)
@@ -409,5 +370,4 @@ def parse_revnum(svnrepo, r):
         if isinstance(r, str) and r.lower() in ('head', 'tip'):
             return svnrepo.last_changed_rev
         else:
-            # TODO: use error.RepoLookupError when we drop 1.3?
-            raise hgutil.Abort("unknown Subversion revision %r" % r)
+            raise error.RepoLookupError("unknown Subversion revision %r" % r)
--- a/hgsubversion/verify.py
+++ b/hgsubversion/verify.py
@@ -59,7 +59,7 @@ def verify(ui, repo, args=None, **opts):
 
         svndata = svn.list_files(branchpath, srev)
         for i, (fn, type) in enumerate(svndata):
-            util.progress(ui, 'verify', i, total=len(hgfiles))
+            ui.progress('verify', i, total=len(hgfiles))
 
             if type != 'f':
                 continue
@@ -90,7 +90,7 @@ def verify(ui, repo, args=None, **opts):
                 ui.write('missing file: %s\n' % f)
             result = 1
 
-        util.progress(ui, 'verify', None, total=len(hgfiles))
+        ui.progress('verify', None, total=len(hgfiles))
 
     else:
         class VerifyEditor(svnwrap.Editor):
@@ -132,7 +132,7 @@ def verify(ui, repo, args=None, **opts):
                     self.props = None
 
                 self.seen += 1
-                util.progress(self.ui, 'verify', self.seen, total=self.total)
+                self.ui.progress('verify', self.seen, total=self.total)
 
             def open_file(self, path, base_revnum):
                 raise NotImplementedError()
@@ -191,7 +191,7 @@ def verify(ui, repo, args=None, **opts):
                 raise NotImplementedError()
 
             def check(self):
-                util.progress(self.ui, 'verify', None, total=self.total)
+                self.ui.progress('verify', None, total=self.total)
 
                 for f in self.unexpected:
                     self.ui.warn('unexpected file: %s\n' % f)
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -1,11 +1,7 @@
 from hgext import rebase as hgrebase
 
 from mercurial import cmdutil
-try:
-    from mercurial import discovery
-    discovery.nullid  # force demandimport to import the module
-except ImportError:
-    discovery = None
+from mercurial import discovery
 from mercurial import patch
 from mercurial import hg
 from mercurial import util as hgutil
@@ -13,6 +9,8 @@ from mercurial import node
 from mercurial import i18n
 from mercurial import extensions
 from mercurial import repair
+from mercurial import revset
+from mercurial import scmutil
 
 import layouts
 import os
@@ -23,12 +21,6 @@ import svnwrap
 import svnrepo
 import util
 
-try:
-    from mercurial import scmutil
-    revpair = scmutil.revpair
-except ImportError:
-    revpair = cmdutil.revpair
-
 pullfuns = {
     True: replay.convert_rev,
     False: stupidmod.convert_rev,
@@ -128,11 +120,10 @@ def findcommonoutgoing(repo, other, only
     parent = repo.parents()[0].node()
     hashes = meta.revmap.hashes()
     common, heads = util.outgoing_common_and_heads(repo, hashes, parent)
-    if discovery is not None:
-        outobj = getattr(discovery, 'outgoing', None)
-        if outobj is not None:
-            # Mercurial 2.1 and later
-            return outobj(repo.changelog, common, heads)
+    outobj = getattr(discovery, 'outgoing', None)
+    if outobj is not None:
+        # Mercurial 2.1 and later
+        return outobj(repo.changelog, common, heads)
     # Mercurial 2.0 and earlier
     return common, heads
 
@@ -163,7 +154,7 @@ def diff(orig, ui, repo, *args, **opts):
         if o_r:
             parent = repo[o_r[-1]].parents()[0]
         opts['rev'] = ['%s:.' % node.hex(parent.node()), ]
-    node1, node2 = revpair(repo, opts['rev'])
+    node1, node2 = scmutil.revpair(repo, opts['rev'])
     baserev, _junk = hashes.get(node1, (-1, 'junk'))
     newrev, _junk = hashes.get(node2, (-1, 'junk'))
     it = patch.diff(repo, node1, node2,
@@ -181,11 +172,7 @@ def push(repo, dest, force, revs):
     """push revisions starting at a specified head back to Subversion.
     """
     assert not revs, 'designated revisions for push remains unimplemented.'
-    if hasattr(cmdutil, 'bail_if_changed'):
-        cmdutil.bail_if_changed(repo)
-    else:
-        # Since 1.9 (d68ddccf276b)
-        cmdutil.bailifchanged(repo)
+    cmdutil.bailifchanged(repo)
     checkpush = getattr(repo, 'checkpush', None)
     if checkpush:
         checkpush(force, revs)
@@ -328,7 +315,8 @@ def push(repo, dest, force, revs):
                 parent = repo[None].p1()
                 if parent.node() in temporary_commits:
                     hg.update(repo, parent.p1().node())
-                repair.strip(ui, repo, temporary_commits, backup=None)
+                for n in temporary_commits:
+                    repair.strip(ui, repo, n, backup=None)
         finally:
             util.swap_out_encoding(old_encoding)
     return 1 # so we get a sane exit status, see hg's commands.push
@@ -429,7 +417,7 @@ def pull(repo, source, heads=[], force=F
                             w = hgutil.termwidth()
                         bits = (r.revnum, r.author, msg)
                         ui.status(('[r%d] %s: %s' % bits)[:w] + '\n')
-                        util.progress(ui, 'pull', r.revnum - start, total=total)
+                        ui.progress('pull', r.revnum - start, total=total)
 
                         meta.save_tbdelta(tbdelta)
                         close = pullfuns[have_replay](ui, meta, svn, r, tbdelta,
@@ -464,7 +452,7 @@ def pull(repo, source, heads=[], force=F
             ui.traceback()
     finally:
         if total is not None:
-            util.progress(ui, 'pull', None, total=total)
+            ui.progress('pull', None, total=total)
         util.swap_out_encoding(old_encoding)
 
     if lastpulled is not None:
--- a/tests/test_fetch_branches.py
+++ b/tests/test_fetch_branches.py
@@ -2,9 +2,9 @@ import test_util
 
 import unittest
 
+from mercurial import error
 from mercurial import hg
 from mercurial import node
-from mercurial import util as hgutil
 
 class TestFetchBranches(test_util.TestBase):
     def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor):
@@ -108,7 +108,7 @@ class TestFetchBranches(test_util.TestBa
         self.test_branch_tip_update_to_default(True)
 
     def test_branch_pull_anchor(self):
-        self.assertRaises(hgutil.Abort,
+        self.assertRaises(error.RepoLookupError,
                           self._load_fixture_and_fetch_with_anchor,
                           'unorderedbranch.svndump', 'NaN')
         repo = self._load_fixture_and_fetch_with_anchor(