[PATCH] largefiles: remove pre-1.9 code from extension first bundled with 1.9

Na'Tosha Bard natosha at unity3d.com
Tue Oct 11 07:04:17 CDT 2011


# HG changeset patch
# User Na'Tosha Bard <natosha at unity3d.com>
# Date 1318322576 -7200
# Node ID 9c45186be93e83b8cd466e65e9d55cda6a23595d
# Parent  c81dce8a7bb642248b787c3139409d94dbe998ab
largefiles: remove pre-1.9 code from extension first bundled with 1.9

diff -r c81dce8a7bb6 -r 9c45186be93e hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py	Mon Oct 10 17:57:40 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 ------------------------------------------------
diff -r c81dce8a7bb6 -r 9c45186be93e hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py	Mon Oct 10 17:57:40 2011 -0500
+++ b/hgext/largefiles/lfutil.py	Tue Oct 11 10:42:56 2011 +0200
@@ -30,74 +30,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 +119,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 +245,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 +416,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.
diff -r c81dce8a7bb6 -r 9c45186be93e hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py	Mon Oct 10 17:57:40 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)
diff -r c81dce8a7bb6 -r 9c45186be93e hgext/largefiles/proto.py
--- a/hgext/largefiles/proto.py	Mon Oct 10 17:57:40 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):
diff -r c81dce8a7bb6 -r 9c45186be93e hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py	Mon Oct 10 17:57:40 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
 


More information about the Mercurial-devel mailing list