largefiles: remove pre-1.9 code from extension first bundled with 1.9
authorNa'Tosha Bard <natosha@unity3d.com>
Tue, 11 Oct 2011 10:42:56 +0200
changeset 15224 7c604d8c7e83
parent 15223 fc035e5370ca
child 15225 b450a4d427ef
largefiles: remove pre-1.9 code from extension first bundled with 1.9
hgext/largefiles/lfcommands.py
hgext/largefiles/lfutil.py
hgext/largefiles/overrides.py
hgext/largefiles/proto.py
hgext/largefiles/reposetup.py
--- a/hgext/largefiles/lfcommands.py	Tue Oct 11 23:16:05 2011 -0500
+++ b/hgext/largefiles/lfcommands.py	Tue Oct 11 10:42:56 2011 +0200
@@ -466,12 +466,7 @@
     elif state == 'a':
         lfdirstate.add(lfile)
     elif state == '?':
-        try:
-            # Mercurial >= 1.9
-            lfdirstate.drop(lfile)
-        except AttributeError:
-            # Mercurial <= 1.8
-            lfdirstate.forget(lfile)
+        lfdirstate.drop(lfile)
     return ret
 
 # -- hg commands declarations ------------------------------------------------
--- a/hgext/largefiles/lfutil.py	Tue Oct 11 23:16:05 2011 -0500
+++ b/hgext/largefiles/lfutil.py	Tue Oct 11 10:42:56 2011 +0200
@@ -10,13 +10,11 @@
 
 import os
 import errno
-import inspect
 import shutil
 import stat
 import hashlib
 
-from mercurial import cmdutil, dirstate, httpconnection, match as match_, \
-        url as url_, util
+from mercurial import dirstate, httpconnection, match as match_, util
 from mercurial.i18n import _
 
 try:
@@ -30,74 +28,38 @@
 
 # -- Portability wrappers ----------------------------------------------
 
-if 'subrepos' in inspect.getargspec(dirstate.dirstate.status)[0]:
-    # for Mercurial >= 1.5
-    def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
-        return dirstate.walk(matcher, [], unknown, ignored)
-else:
-    # for Mercurial <= 1.4
-    def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
-        return dirstate.walk(matcher, unknown, ignored)
+def dirstate_walk(dirstate, matcher, unknown=False, ignored=False):
+    return dirstate.walk(matcher, [], unknown, ignored)
 
 def repo_add(repo, list):
-    try:
-        # Mercurial <= 1.5
-        add = repo.add
-    except AttributeError:
-        # Mercurial >= 1.6
-        add = repo[None].add
+    add = repo[None].add
     return add(list)
 
 def repo_remove(repo, list, unlink=False):
-    try:
-        # Mercurial <= 1.5
-        remove = repo.remove
-    except AttributeError:
-        # Mercurial >= 1.6
+    def remove(list, unlink):
+        wlock = repo.wlock()
         try:
-            # Mercurial <= 1.8
-            remove = repo[None].remove
-        except AttributeError:
-            # Mercurial >= 1.9
-            def remove(list, unlink):
-                wlock = repo.wlock()
-                try:
-                    if unlink:
-                        for f in list:
-                            try:
-                                util.unlinkpath(repo.wjoin(f))
-                            except OSError, inst:
-                                if inst.errno != errno.ENOENT:
-                                    raise
-                    repo[None].forget(list)
-                finally:
-                    wlock.release()
-
+            if unlink:
+                for f in list:
+                    try:
+                        util.unlinkpath(repo.wjoin(f))
+                    except OSError, inst:
+                        if inst.errno != errno.ENOENT:
+                            raise
+            repo[None].forget(list)
+        finally:
+            wlock.release()
     return remove(list, unlink=unlink)
 
 def repo_forget(repo, list):
-    try:
-        # Mercurial <= 1.5
-        forget = repo.forget
-    except AttributeError:
-        # Mercurial >= 1.6
-        forget = repo[None].forget
+    forget = repo[None].forget
     return forget(list)
 
 def findoutgoing(repo, remote, force):
-    # First attempt is for Mercurial <= 1.5 second is for >= 1.6
-    try:
-        return repo.findoutgoing(remote)
-    except AttributeError:
-        from mercurial import discovery
-        try:
-            # Mercurial <= 1.8
-            return discovery.findoutgoing(repo, remote, force=force)
-        except AttributeError:
-            # Mercurial >= 1.9
-            common, _anyinc, _heads = discovery.findcommonincoming(repo,
-                remote, force=force)
-            return repo.changelog.findmissing(common)
+    from mercurial import discovery
+    common, _anyinc, _heads = discovery.findcommonincoming(repo,
+        remote, force=force)
+    return repo.changelog.findmissing(common)
 
 # -- Private worker functions ------------------------------------------
 
@@ -155,12 +117,7 @@
     repo root, but it is saved in .hg/largefiles/dirstate.
     '''
     admin = repo.join(longname)
-    try:
-        # Mercurial >= 1.9
-        opener = scmutil.opener(admin)
-    except ImportError:
-        # Mercurial <= 1.8
-        opener = util.opener(admin)
+    opener = scmutil.opener(admin)
     if util.safehasattr(repo.dirstate, '_validate'):
         lfdirstate = largefiles_dirstate(opener, ui, repo.root,
             repo.dirstate._validate)
@@ -286,12 +243,7 @@
     '''Wrapper around scmutil.match() that adds showbad: if false, neuter
     the match object\'s bad() method so it does not print any warnings
     about missing files or directories.'''
-    try:
-        # Mercurial >= 1.9
-        match = scmutil.match(repo[None], pats, opts)
-    except ImportError:
-        # Mercurial <= 1.8
-        match = cmdutil.match(repo, pats, opts)
+    match = scmutil.match(repo[None], pats, opts)
 
     if not showbad:
         match.bad = lambda f, msg: None
@@ -462,16 +414,7 @@
     return h.hexdigest()
 
 def httpsendfile(ui, filename):
-    try:
-        # Mercurial >= 1.9
-        return httpconnection.httpsendfile(ui, filename, 'rb')
-    except ImportError:
-        if 'ui' in inspect.getargspec(url_.httpsendfile.__init__)[0]:
-            # Mercurial == 1.8
-            return url_.httpsendfile(ui, filename, 'rb')
-        else:
-            # Mercurial <= 1.7
-            return url_.httpsendfile(filename, 'rb')
+    return httpconnection.httpsendfile(ui, filename, 'rb')
 
 # Convert a path to a unix style path. This is used to give a
 # canonical path to the lfdirstate.
--- a/hgext/largefiles/overrides.py	Tue Oct 11 23:16:05 2011 -0500
+++ b/hgext/largefiles/overrides.py	Tue Oct 11 10:42:56 2011 +0200
@@ -43,19 +43,9 @@
     oldmatch = installmatchfn(override_match)
 
 def installmatchfn(f):
-    try:
-        # Mercurial >= 1.9
-        oldmatch = scmutil.match
-    except ImportError:
-        # Mercurial <= 1.8
-        oldmatch = cmdutil.match
+    oldmatch = scmutil.match
     setattr(f, 'oldmatch', oldmatch)
-    try:
-        # Mercurial >= 1.9
-        scmutil.match = f
-    except ImportError:
-        # Mercurial <= 1.8
-        cmdutil.match = f
+    scmutil.match = f
     return oldmatch
 
 def restorematchfn():
@@ -64,12 +54,7 @@
 
     Note that n calls to installnormalfilesmatchfn will require n calls to
     restore matchfn to reverse'''
-    try:
-        # Mercurial >= 1.9
-        scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
-    except ImportError:
-        # Mercurial <= 1.8
-        cmdutil.match = getattr(cmdutil.match, 'oldmatch', cmdutil.match)
+    scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
 
 # -- Wrappers: modify existing commands --------------------------------
 
@@ -98,12 +83,7 @@
             lfmatcher = match_.match(repo.root, '', list(lfpats))
 
     lfnames = []
-    try:
-        # Mercurial >= 1.9
-        m = scmutil.match(repo[None], pats, opts)
-    except ImportError:
-        # Mercurial <= 1.8
-        m = cmdutil.match(repo, pats, opts)
+    m = scmutil.match(repo[None], pats, opts)
     m.bad = lambda x, y: None
     wctx = repo[None]
     for f in repo.walk(m):
@@ -165,12 +145,7 @@
     after, force = opts.get('after'), opts.get('force')
     if not pats and not after:
         raise util.Abort(_('no files specified'))
-    try:
-        # Mercurial >= 1.9
-        m = scmutil.match(repo[None], pats, opts)
-    except ImportError:
-        # Mercurial <= 1.8
-        m = cmdutil.match(repo, pats, opts)
+    m = scmutil.match(repo[None], pats, opts)
     try:
         repo.lfstatus = True
         s = repo.status(match=m, clean=True)
@@ -332,21 +307,11 @@
         return orig(ui, repo, pats, opts, rename)
 
     def makestandin(relpath):
-        try:
-            # Mercurial >= 1.9
-            path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
-        except ImportError:
-            # Mercurial <= 1.8
-            path = util.canonpath(repo.root, repo.getcwd(), relpath)
+        path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
         return os.path.join(os.path.relpath('.', repo.getcwd()),
             lfutil.standin(path))
 
-    try:
-        # Mercurial >= 1.9
-        fullpats = scmutil.expandpats(pats)
-    except ImportError:
-        # Mercurial <= 1.8
-        fullpats = cmdutil.expandpats(pats)
+    fullpats = scmutil.expandpats(pats)
     dest = fullpats[-1]
 
     if os.path.isdir(dest):
@@ -520,13 +485,8 @@
                 m.matchfn = matchfn
                 return m
             oldmatch = installmatchfn(override_match)
-            try:
-                # Mercurial >= 1.9
-                scmutil.match
-                matches = override_match(repo[None], pats, opts)
-            except ImportError:
-                # Mercurial <= 1.8
-                matches = override_match(repo, pats, opts)
+            scmutil.match
+            matches = override_match(repo[None], pats, opts)
             orig(ui, repo, *pats, **opts)
         finally:
             restorematchfn()
@@ -547,12 +507,7 @@
             standin = lfutil.standin(lfile)
             if standin not in ctx and (standin in matches or opts.get('all')):
                 if lfile in lfdirstate:
-                    try:
-                        # Mercurial >= 1.9
-                        lfdirstate.drop(lfile)
-                    except AttributeError:
-                        # Mercurial <= 1.8
-                        lfdirstate.forget(lfile)
+                    lfdirstate.drop(lfile)
                 util.unlinkpath(repo.wjoin(standin))
         lfdirstate.write()
     finally:
@@ -586,12 +541,7 @@
                  ui.debug('--update and --rebase are not compatible, ignoring '
                           'the update flag\n')
             del opts['rebase']
-            try:
-                # Mercurial >= 1.9
-                cmdutil.bailifchanged(repo)
-            except AttributeError:
-                # Mercurial <= 1.8
-                cmdutil.bail_if_changed(repo)
+            cmdutil.bailifchanged(repo)
             revsprepull = len(repo)
             origpostincoming = commands.postincoming
             def _dummy(*args, **kwargs):
@@ -635,37 +585,22 @@
 
     ctx = repo[node]
 
-    # In Mercurial <= 1.5 the prefix is passed to the archiver so try that
-    # if that doesn't work we are probably in Mercurial >= 1.6 where the
-    # prefix is not handled by the archiver
-    try:
-        archiver = archival.archivers[kind](dest, prefix, mtime or \
-                ctx.date()[0])
+    if kind == 'files':
+        if prefix:
+            raise util.Abort(
+                _('cannot give prefix when archiving to files'))
+    else:
+        prefix = archival.tidyprefix(dest, kind, prefix)
 
-        def write(name, mode, islink, getdata):
-            if matchfn and not matchfn(name):
-                return
-            data = getdata()
-            if decode:
-                data = repo.wwritedata(name, data)
-            archiver.addfile(name, mode, islink, data)
-    except TypeError:
-        if kind == 'files':
-            if prefix:
-                raise util.Abort(
-                    _('cannot give prefix when archiving to files'))
-        else:
-            prefix = archival.tidyprefix(dest, kind, prefix)
+    def write(name, mode, islink, getdata):
+        if matchfn and not matchfn(name):
+            return
+        data = getdata()
+        if decode:
+            data = repo.wwritedata(name, data)
+        archiver.addfile(prefix + name, mode, islink, data)
 
-        def write(name, mode, islink, getdata):
-            if matchfn and not matchfn(name):
-                return
-            data = getdata()
-            if decode:
-                data = repo.wwritedata(name, data)
-            archiver.addfile(prefix + name, mode, islink, data)
-
-        archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
+    archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
 
     if repo.ui.configbool("ui", "archivemeta", True):
         def metadata():
@@ -739,12 +674,7 @@
     installnormalfilesmatchfn(repo[None].manifest())
     orig(ui, repo, *pats, **opts)
     restorematchfn()
-    try:
-        # Mercurial >= 1.9
-        m = scmutil.match(repo[None], pats, opts)
-    except ImportError:
-        # Mercurial <= 1.8
-        m = cmdutil.match(repo, pats, opts)
+    m = scmutil.match(repo[None], pats, opts)
 
     try:
         repo.lfstatus = True
@@ -787,11 +717,7 @@
     if revs:
         revs = [repo.lookup(rev) for rev in revs]
 
-    # Mercurial <= 1.5 had remoteui in cmdutil, then it moved to hg
-    try:
-        remoteui = cmdutil.remoteui
-    except AttributeError:
-        remoteui = hg.remoteui
+    remoteui = hg.remoteui
 
     try:
         remote = hg.repository(remoteui(repo, opts), dest)
--- a/hgext/largefiles/proto.py	Tue Oct 11 23:16:05 2011 -0500
+++ b/hgext/largefiles/proto.py	Tue Oct 11 10:42:56 2011 +0200
@@ -140,11 +140,7 @@
 
 def heads(repo, proto):
     if lfutil.islfilesrepo(repo):
-        try:
-            # Mercurial >= f4522df38c65
-            return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
-        except AttributeError:
-            return proto.refuseclient(LARGEFILES_REQUIRED_MSG)
+        return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
     return wireproto.heads(repo, proto)
 
 def sshrepo_callstream(self, cmd, **args):
--- a/hgext/largefiles/reposetup.py	Tue Oct 11 23:16:05 2011 -0500
+++ b/hgext/largefiles/reposetup.py	Tue Oct 11 10:42:56 2011 +0200
@@ -267,12 +267,7 @@
                     for lfile in lfdirstate:
                         if not os.path.exists(
                                 repo.wjoin(lfutil.standin(lfile))):
-                            try:
-                                # Mercurial >= 1.9
-                                lfdirstate.drop(lfile)
-                            except AttributeError:
-                                # Mercurial <= 1.8
-                                lfdirstate.forget(lfile)
+                            lfdirstate.drop(lfile)
                     lfdirstate.write()
 
                     return orig(text=text, user=user, date=date, match=match,
@@ -306,12 +301,7 @@
                         lfutil.updatestandin(self, standin)
                         lfdirstate.normal(lfile)
                     else:
-                        try:
-                            # Mercurial >= 1.9
-                            lfdirstate.drop(lfile)
-                        except AttributeError:
-                            # Mercurial <= 1.8
-                            lfdirstate.forget(lfile)
+                        lfdirstate.drop(lfile)
                 lfdirstate.write()
 
                 # Cook up a new matcher that only matches regular files or
@@ -386,12 +376,8 @@
                     toupload = toupload.union(set([ctx[f].data().strip() for f\
                         in files if lfutil.isstandin(f) and f in ctx]))
                 lfcommands.uploadlfiles(ui, self, remote, toupload)
-            # Mercurial >= 1.6 takes the newbranch argument, try that first.
-            try:
-                return super(lfiles_repo, self).push(remote, force, revs,
-                    newbranch)
-            except TypeError:
-                return super(lfiles_repo, self).push(remote, force, revs)
+            return super(lfiles_repo, self).push(remote, force, revs,
+                newbranch)
 
     repo.__class__ = lfiles_repo