Commits

Bryan O'Sullivan committed cafd8a8

util: subclass deque for Python 2.4 backwards compatibility

It turns out that Python 2.4's deque type is lacking a remove method.
We can't implement remove in terms of find, because it doesn't have
find either.

  • Participants
  • Parent commits 7b460b4

Comments (0)

Files changed (7)

File mercurial/hbisect.py

 import os, error
 from i18n import _
 from node import short, hex
-import collections, util
+import util
 
 def bisect(changelog, state):
     """find the next node (if any) for testing during a bisect search.
 
     # build children dict
     children = {}
-    visit = collections.deque([badrev])
+    visit = util.deque([badrev])
     candidates = []
     while visit:
         rev = visit.popleft()

File mercurial/patch.py

 from i18n import _
 from node import hex, nullid, short
 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
-import collections, context
+import context
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
 
 
     def lrugetfilectx():
         cache = {}
-        order = collections.deque()
+        order = util.deque()
         def getfilectx(f, ctx):
             fctx = ctx.filectx(f, filelog=cache.get(f))
             if f not in cache:

File mercurial/revlog.py

 from node import bin, hex, nullid, nullrev
 from i18n import _
 import ancestor, mdiff, parsers, error, util, dagutil
-import struct, zlib, errno, collections
+import struct, zlib, errno
 
 _pack = struct.pack
 _unpack = struct.unpack
         """return the set of all nodes ancestral to a given node, including
          the node itself, stopping when stop is matched"""
         reachable = set((node,))
-        visit = collections.deque([node])
+        visit = util.deque([node])
         if stop:
             stopn = self.rev(stop)
         else:
         an ancestor of itself.  Results are in breadth-first order:
         parents of each rev in revs, then parents of those, etc.  Result
         does not include the null revision."""
-        visit = collections.deque(revs)
+        visit = util.deque(revs)
         seen = set([nullrev])
         while visit:
             for parent in self.parentrevs(visit.popleft()):
 
         # take all ancestors from heads that aren't in has
         missing = set()
-        visit = collections.deque(r for r in heads if r not in has)
+        visit = util.deque(r for r in heads if r not in has)
         while visit:
             r = visit.popleft()
             if r in missing:

File mercurial/revset.py

 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import re, collections
+import re
 import parser, util, error, discovery, hbisect, phases
 import node
 import bookmarks as bookmarksmod
     """Like revlog.ancestors(), but supports followfirst."""
     cut = followfirst and 1 or None
     cl = repo.changelog
-    visit = collections.deque(revs)
+    visit = util.deque(revs)
     seen = set([node.nullrev])
     while visit:
         for parent in cl.parentrevs(visit.popleft())[:cut]:

File mercurial/setdiscovery.py

 
 from node import nullid
 from i18n import _
-import random, collections, util, dagutil
+import random, util, dagutil
 import phases
 
 def _updatesample(dag, nodes, sample, always, quicksamplesize=0):
     else:
         heads = dag.heads()
     dist = {}
-    visit = collections.deque(heads)
+    visit = util.deque(heads)
     seen = set()
     factor = 1
     while visit:

File mercurial/treediscovery.py

 
 from node import nullid, short
 from i18n import _
-import util, error, collections
+import util, error
 
 def findcommonincoming(repo, remote, heads=None, force=False):
     """Return a tuple (common, fetch, heads) used to identify the common
     # a 'branch' here is a linear segment of history, with four parts:
     # head, root, first parent, second parent
     # (a branch always has two parents (or none) by definition)
-    unknown = collections.deque(remote.branches(unknown))
+    unknown = util.deque(remote.branches(unknown))
     while unknown:
         r = []
         while unknown:

File mercurial/util.py

 
     return f
 
+try:
+    collections.deque.remove
+    deque = collections.deque
+except AttributeError:
+    # python 2.4 lacks deque.remove
+    class deque(collections.deque):
+        def remove(self, val):
+            for i, v in enumerate(self):
+                if v == val:
+                    del self[i]
+                    break
+
 def lrucachefunc(func):
     '''cache most recent results of function calls'''
     cache = {}
-    order = collections.deque()
+    order = deque()
     if func.func_code.co_argcount == 1:
         def f(arg):
             if arg not in cache:
         Returns less than L bytes if the iterator runs dry."""
         left = l
         buf = ''
-        queue = collections.deque(self._queue)
+        queue = deque(self._queue)
         while left > 0:
             # refill the queue
             if not queue: