##// END OF EJS Templates
util: subclass deque for Python 2.4 backwards compatibility...
Bryan O'Sullivan -
r16834:cafd8a8f default
parent child Browse files
Show More
@@ -11,7 +11,7 b''
11 import os, error
11 import os, error
12 from i18n import _
12 from i18n import _
13 from node import short, hex
13 from node import short, hex
14 import collections, util
14 import util
15
15
16 def bisect(changelog, state):
16 def bisect(changelog, state):
17 """find the next node (if any) for testing during a bisect search.
17 """find the next node (if any) for testing during a bisect search.
@@ -69,7 +69,7 b' def bisect(changelog, state):'
69
69
70 # build children dict
70 # build children dict
71 children = {}
71 children = {}
72 visit = collections.deque([badrev])
72 visit = util.deque([badrev])
73 candidates = []
73 candidates = []
74 while visit:
74 while visit:
75 rev = visit.popleft()
75 rev = visit.popleft()
@@ -12,7 +12,7 b' import tempfile, zlib, shutil'
12 from i18n import _
12 from i18n import _
13 from node import hex, nullid, short
13 from node import hex, nullid, short
14 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
14 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
15 import collections, context
15 import context
16
16
17 gitre = re.compile('diff --git a/(.*) b/(.*)')
17 gitre = re.compile('diff --git a/(.*) b/(.*)')
18
18
@@ -1597,7 +1597,7 b' def diff(repo, node1=None, node2=None, m'
1597
1597
1598 def lrugetfilectx():
1598 def lrugetfilectx():
1599 cache = {}
1599 cache = {}
1600 order = collections.deque()
1600 order = util.deque()
1601 def getfilectx(f, ctx):
1601 def getfilectx(f, ctx):
1602 fctx = ctx.filectx(f, filelog=cache.get(f))
1602 fctx = ctx.filectx(f, filelog=cache.get(f))
1603 if f not in cache:
1603 if f not in cache:
@@ -15,7 +15,7 b' and O(changes) merge between branches.'
15 from node import bin, hex, nullid, nullrev
15 from node import bin, hex, nullid, nullrev
16 from i18n import _
16 from i18n import _
17 import ancestor, mdiff, parsers, error, util, dagutil
17 import ancestor, mdiff, parsers, error, util, dagutil
18 import struct, zlib, errno, collections
18 import struct, zlib, errno
19
19
20 _pack = struct.pack
20 _pack = struct.pack
21 _unpack = struct.unpack
21 _unpack = struct.unpack
@@ -362,7 +362,7 b' class revlog(object):'
362 """return the set of all nodes ancestral to a given node, including
362 """return the set of all nodes ancestral to a given node, including
363 the node itself, stopping when stop is matched"""
363 the node itself, stopping when stop is matched"""
364 reachable = set((node,))
364 reachable = set((node,))
365 visit = collections.deque([node])
365 visit = util.deque([node])
366 if stop:
366 if stop:
367 stopn = self.rev(stop)
367 stopn = self.rev(stop)
368 else:
368 else:
@@ -389,7 +389,7 b' class revlog(object):'
389 an ancestor of itself. Results are in breadth-first order:
389 an ancestor of itself. Results are in breadth-first order:
390 parents of each rev in revs, then parents of those, etc. Result
390 parents of each rev in revs, then parents of those, etc. Result
391 does not include the null revision."""
391 does not include the null revision."""
392 visit = collections.deque(revs)
392 visit = util.deque(revs)
393 seen = set([nullrev])
393 seen = set([nullrev])
394 while visit:
394 while visit:
395 for parent in self.parentrevs(visit.popleft()):
395 for parent in self.parentrevs(visit.popleft()):
@@ -447,7 +447,7 b' class revlog(object):'
447
447
448 # take all ancestors from heads that aren't in has
448 # take all ancestors from heads that aren't in has
449 missing = set()
449 missing = set()
450 visit = collections.deque(r for r in heads if r not in has)
450 visit = util.deque(r for r in heads if r not in has)
451 while visit:
451 while visit:
452 r = visit.popleft()
452 r = visit.popleft()
453 if r in missing:
453 if r in missing:
@@ -5,7 +5,7 b''
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import re, collections
8 import re
9 import parser, util, error, discovery, hbisect, phases
9 import parser, util, error, discovery, hbisect, phases
10 import node
10 import node
11 import bookmarks as bookmarksmod
11 import bookmarks as bookmarksmod
@@ -17,7 +17,7 b' def _revancestors(repo, revs, followfirs'
17 """Like revlog.ancestors(), but supports followfirst."""
17 """Like revlog.ancestors(), but supports followfirst."""
18 cut = followfirst and 1 or None
18 cut = followfirst and 1 or None
19 cl = repo.changelog
19 cl = repo.changelog
20 visit = collections.deque(revs)
20 visit = util.deque(revs)
21 seen = set([node.nullrev])
21 seen = set([node.nullrev])
22 while visit:
22 while visit:
23 for parent in cl.parentrevs(visit.popleft())[:cut]:
23 for parent in cl.parentrevs(visit.popleft())[:cut]:
@@ -8,7 +8,7 b''
8
8
9 from node import nullid
9 from node import nullid
10 from i18n import _
10 from i18n import _
11 import random, collections, util, dagutil
11 import random, util, dagutil
12 import phases
12 import phases
13
13
14 def _updatesample(dag, nodes, sample, always, quicksamplesize=0):
14 def _updatesample(dag, nodes, sample, always, quicksamplesize=0):
@@ -18,7 +18,7 b' def _updatesample(dag, nodes, sample, al'
18 else:
18 else:
19 heads = dag.heads()
19 heads = dag.heads()
20 dist = {}
20 dist = {}
21 visit = collections.deque(heads)
21 visit = util.deque(heads)
22 seen = set()
22 seen = set()
23 factor = 1
23 factor = 1
24 while visit:
24 while visit:
@@ -7,7 +7,7 b''
7
7
8 from node import nullid, short
8 from node import nullid, short
9 from i18n import _
9 from i18n import _
10 import util, error, collections
10 import util, error
11
11
12 def findcommonincoming(repo, remote, heads=None, force=False):
12 def findcommonincoming(repo, remote, heads=None, force=False):
13 """Return a tuple (common, fetch, heads) used to identify the common
13 """Return a tuple (common, fetch, heads) used to identify the common
@@ -56,7 +56,7 b' def findcommonincoming(repo, remote, hea'
56 # a 'branch' here is a linear segment of history, with four parts:
56 # a 'branch' here is a linear segment of history, with four parts:
57 # head, root, first parent, second parent
57 # head, root, first parent, second parent
58 # (a branch always has two parents (or none) by definition)
58 # (a branch always has two parents (or none) by definition)
59 unknown = collections.deque(remote.branches(unknown))
59 unknown = util.deque(remote.branches(unknown))
60 while unknown:
60 while unknown:
61 r = []
61 r = []
62 while unknown:
62 while unknown:
@@ -202,10 +202,22 b' def cachefunc(func):'
202
202
203 return f
203 return f
204
204
205 try:
206 collections.deque.remove
207 deque = collections.deque
208 except AttributeError:
209 # python 2.4 lacks deque.remove
210 class deque(collections.deque):
211 def remove(self, val):
212 for i, v in enumerate(self):
213 if v == val:
214 del self[i]
215 break
216
205 def lrucachefunc(func):
217 def lrucachefunc(func):
206 '''cache most recent results of function calls'''
218 '''cache most recent results of function calls'''
207 cache = {}
219 cache = {}
208 order = collections.deque()
220 order = deque()
209 if func.func_code.co_argcount == 1:
221 if func.func_code.co_argcount == 1:
210 def f(arg):
222 def f(arg):
211 if arg not in cache:
223 if arg not in cache:
@@ -865,7 +877,7 b' class chunkbuffer(object):'
865 Returns less than L bytes if the iterator runs dry."""
877 Returns less than L bytes if the iterator runs dry."""
866 left = l
878 left = l
867 buf = ''
879 buf = ''
868 queue = collections.deque(self._queue)
880 queue = deque(self._queue)
869 while left > 0:
881 while left > 0:
870 # refill the queue
882 # refill the queue
871 if not queue:
883 if not queue:
General Comments 0
You need to be logged in to leave comments. Login now