comparison mercurial/revset.py @ 25144:81a395447b34

revset: use 'next()' to detect end of iteration in 'limit' The 'next()' built-in can return a default value, allow to get rid of the confusing try/except code flow.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 17 May 2015 17:58:39 -0700
parents 91c49621b2b8
children 3553163bb736
comparison
equal deleted inserted replaced
25143:91c49621b2b8 25144:81a395447b34
1143 ss = subset 1143 ss = subset
1144 os = getset(repo, fullreposet(repo), l[0]) 1144 os = getset(repo, fullreposet(repo), l[0])
1145 result = [] 1145 result = []
1146 it = iter(os) 1146 it = iter(os)
1147 for x in xrange(lim): 1147 for x in xrange(lim):
1148 try: 1148 y = next(it, None)
1149 y = it.next() 1149 if y is None:
1150 if y in ss:
1151 result.append(y)
1152 except (StopIteration):
1153 break 1150 break
1151 elif y in ss:
1152 result.append(y)
1154 return baseset(result) 1153 return baseset(result)
1155 1154
1156 def last(repo, subset, x): 1155 def last(repo, subset, x):
1157 """``last(set, [n])`` 1156 """``last(set, [n])``
1158 Last n members of set, defaulting to 1. 1157 Last n members of set, defaulting to 1.