##// END OF EJS Templates
cleanup: use the deque type where appropriate...
Bryan O'Sullivan -
r16803:107a3270 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 util
14 import collections, 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,10 +69,10 b' def bisect(changelog, state):'
69
69
70 # build children dict
70 # build children dict
71 children = {}
71 children = {}
72 visit = [badrev]
72 visit = collections.deque([badrev])
73 candidates = []
73 candidates = []
74 while visit:
74 while visit:
75 rev = visit.pop(0)
75 rev = visit.popleft()
76 if ancestors[rev] == []:
76 if ancestors[rev] == []:
77 candidates.append(rev)
77 candidates.append(rev)
78 for prev in clparents(rev):
78 for prev in clparents(rev):
@@ -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 context
15 import collections, context
16
16
17 gitre = re.compile('diff --git a/(.*) b/(.*)')
17 gitre = re.compile('diff --git a/(.*) b/(.*)')
18
18
@@ -1588,12 +1588,12 b' def diff(repo, node1=None, node2=None, m'
1588
1588
1589 def lrugetfilectx():
1589 def lrugetfilectx():
1590 cache = {}
1590 cache = {}
1591 order = []
1591 order = collections.deque()
1592 def getfilectx(f, ctx):
1592 def getfilectx(f, ctx):
1593 fctx = ctx.filectx(f, filelog=cache.get(f))
1593 fctx = ctx.filectx(f, filelog=cache.get(f))
1594 if f not in cache:
1594 if f not in cache:
1595 if len(cache) > 20:
1595 if len(cache) > 20:
1596 del cache[order.pop(0)]
1596 del cache[order.popleft()]
1597 cache[f] = fctx.filelog()
1597 cache[f] = fctx.filelog()
1598 else:
1598 else:
1599 order.remove(f)
1599 order.remove(f)
@@ -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
18 import struct, zlib, errno, collections
19
19
20 _pack = struct.pack
20 _pack = struct.pack
21 _unpack = struct.unpack
21 _unpack = struct.unpack
@@ -362,13 +362,13 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 = [node]
365 visit = collections.deque([node])
366 if stop:
366 if stop:
367 stopn = self.rev(stop)
367 stopn = self.rev(stop)
368 else:
368 else:
369 stopn = 0
369 stopn = 0
370 while visit:
370 while visit:
371 n = visit.pop(0)
371 n = visit.popleft()
372 if n == stop:
372 if n == stop:
373 continue
373 continue
374 if n == nullid:
374 if n == nullid:
@@ -389,10 +389,10 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 = list(revs)
392 visit = collections.deque(revs)
393 seen = set([nullrev])
393 seen = set([nullrev])
394 while visit:
394 while visit:
395 for parent in self.parentrevs(visit.pop(0)):
395 for parent in self.parentrevs(visit.popleft()):
396 if parent not in seen:
396 if parent not in seen:
397 visit.append(parent)
397 visit.append(parent)
398 seen.add(parent)
398 seen.add(parent)
@@ -447,9 +447,9 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 = [r for r in heads if r not in has]
450 visit = collections.deque(r for r in heads if r not in has)
451 while visit:
451 while visit:
452 r = visit.pop(0)
452 r = visit.popleft()
453 if r in missing:
453 if r in missing:
454 continue
454 continue
455 else:
455 else:
@@ -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
8 import re, collections
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,10 +17,10 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 = list(revs)
20 visit = collections.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.pop(0))[:cut]:
23 for parent in cl.parentrevs(visit.popleft())[:cut]:
24 if parent not in seen:
24 if parent not in seen:
25 visit.append(parent)
25 visit.append(parent)
26 seen.add(parent)
26 seen.add(parent)
@@ -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
10 import util, error, collections
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,11 +56,11 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 = remote.branches(unknown)
59 unknown = collections.deque(remote.branches(unknown))
60 while unknown:
60 while unknown:
61 r = []
61 r = []
62 while unknown:
62 while unknown:
63 n = unknown.pop(0)
63 n = unknown.popleft()
64 if n[0] in seen:
64 if n[0] in seen:
65 continue
65 continue
66
66
@@ -14,7 +14,7 b' hide platform-specific details from the '
14 """
14 """
15
15
16 from i18n import _
16 from i18n import _
17 import error, osutil, encoding
17 import error, osutil, encoding, collections
18 import errno, re, shutil, sys, tempfile, traceback
18 import errno, re, shutil, sys, tempfile, traceback
19 import os, time, datetime, calendar, textwrap, signal
19 import os, time, datetime, calendar, textwrap, signal
20 import imp, socket, urllib
20 import imp, socket, urllib
@@ -205,12 +205,12 b' def cachefunc(func):'
205 def lrucachefunc(func):
205 def lrucachefunc(func):
206 '''cache most recent results of function calls'''
206 '''cache most recent results of function calls'''
207 cache = {}
207 cache = {}
208 order = []
208 order = collections.deque()
209 if func.func_code.co_argcount == 1:
209 if func.func_code.co_argcount == 1:
210 def f(arg):
210 def f(arg):
211 if arg not in cache:
211 if arg not in cache:
212 if len(cache) > 20:
212 if len(cache) > 20:
213 del cache[order.pop(0)]
213 del cache[order.popleft()]
214 cache[arg] = func(arg)
214 cache[arg] = func(arg)
215 else:
215 else:
216 order.remove(arg)
216 order.remove(arg)
@@ -220,7 +220,7 b' def lrucachefunc(func):'
220 def f(*args):
220 def f(*args):
221 if args not in cache:
221 if args not in cache:
222 if len(cache) > 20:
222 if len(cache) > 20:
223 del cache[order.pop(0)]
223 del cache[order.popleft()]
224 cache[args] = func(*args)
224 cache[args] = func(*args)
225 else:
225 else:
226 order.remove(args)
226 order.remove(args)
@@ -865,7 +865,7 b' class chunkbuffer(object):'
865 Returns less than L bytes if the iterator runs dry."""
865 Returns less than L bytes if the iterator runs dry."""
866 left = l
866 left = l
867 buf = ''
867 buf = ''
868 queue = self._queue
868 queue = collections.deque(self._queue)
869 while left > 0:
869 while left > 0:
870 # refill the queue
870 # refill the queue
871 if not queue:
871 if not queue:
@@ -878,13 +878,14 b' class chunkbuffer(object):'
878 if not queue:
878 if not queue:
879 break
879 break
880
880
881 chunk = queue.pop(0)
881 chunk = queue.popleft()
882 left -= len(chunk)
882 left -= len(chunk)
883 if left < 0:
883 if left < 0:
884 queue.insert(0, chunk[left:])
884 queue.appendleft(chunk[left:])
885 buf += chunk[:left]
885 buf += chunk[:left]
886 else:
886 else:
887 buf += chunk
887 buf += chunk
888 self._queue = list(queue)
888
889
889 return buf
890 return buf
890
891
General Comments 0
You need to be logged in to leave comments. Login now