Permalink
Browse files

Fixed various bugs that resulted in exceptions or incorrect behaviour

  • Loading branch information...
1 parent 0f0a672 commit 17a99ee04f60cf7ee3b0f79e5f90eba1f644e886 @simplyarjen committed Dec 22, 2011
Showing with 74 additions and 45 deletions.
  1. +74 −45 loglinear.py
View
@@ -26,7 +26,16 @@
def loglinear(ui, repo, *args, **opts):
'''Linear log
'''
- cl = repo.changelog
+ revs, merge, limit, depth, branches = parseopts(opts)
+ sub = findsub(repo, revs, merge)
+ if sub.isempty():
+ raise util.Abort(_("empty revision set"))
+ ctx = repo[sub.max()]
+ if ctx.branch() not in branches:
+ branches.add(ctx.branch())
+ printrecursive(ui, repo, sub, limit, depth, branches, emptyrevorder(), '')
+
+def parseopts(opts):
revs = opts.get('rev')
merge = opts.get('merge')
if (revs and merge):
@@ -50,6 +59,10 @@ def _nopt(name):
if not depth:
depth = 1
branches = set(opts.get('branch'))
+ return revs, merge, limit, depth, branches
+
+def findsub(repo, revs, merge):
+ cl = repo.changelog
single = False
if len(revs) == 1:
try:
@@ -67,21 +80,15 @@ def _nopt(name):
raise util.Abort(_('non-merge revision specified for --merge'))
main = pickparent(repo, rev, *pars)
other = [x for x in pars if x != main][0]
- sub = findmerged(repo, other, main, set(cl.ancestors(rev)))
- try:
- sub.max()
- except StopIteration:
- raise util.Abort(_("empty revision set"))
- ctx = repo[max(sub)]
- if ctx.branch() not in branches:
- branches.add(ctx.branch())
- printrecursive(ui, repo, sub, limit, depth, branches, seqrevorder([]), '')
+ sub = seqrevorder(findmerged(repo, other, main, ancestors(repo, rev)))
+ return sub
def printrecursive(ui, repo, sub, limit, depth, branches, main, prefix):
line = findline(repo, sub, branches)
cl = repo.changelog
pars = []
- for rev in line:
+ lineiter = iter(line)
+ for rev in lineiter:
if limit >= 0:
if limit == 0:
break
@@ -95,7 +102,7 @@ def printrecursive(ui, repo, sub, limit, depth, branches, main, prefix):
for par in pars[:]:
if line.has(par):
continue
- if line.islast(rev) and main.has(par):
+ if not lineiter.hasnext() and main.has(par):
continue
pctx = repo[par]
branch = None
@@ -108,7 +115,7 @@ def printrecursive(ui, repo, sub, limit, depth, branches, main, prefix):
if (not branch or branch in branches) and merged and depth > 1:
limit = printrecursive(ui, repo,
seqrevorder(merged), limit, depth - 1, branches,
- jointorder(main, line), prefix + ' ')
+ jointrevorder(main, ancestors(repo, other)), prefix + ' ')
else:
printmerged(ui, pctx, branch, merged, prefix)
pars.remove(par)
@@ -194,18 +201,28 @@ def __init__(self, iter):
self._set = set()
self._list = []
self._found = None
- def _ensure(self, val):
- if not self._found >= 0:
- self._take()
- while val < self._found:
- self._take()
+
def _take(self):
next = self._iter.next()
if next == -1:
raise StopIteration
self._set.add(next)
self._list.append(next)
self._found = next
+
+ def _ensure(self, val):
+ while self._found == None or val < self._found:
+ self._take()
+
+ def isempty(self):
+ if self._found >= 0:
+ return False
+ try:
+ self._take()
+ except StopIteration:
+ return True
+ return False
+
def has(self, val):
if val == -1:
return False
@@ -214,34 +231,39 @@ def has(self, val):
except StopIteration:
return False
return val in self._set
+
def max(self):
if not self._found >= 0:
- self._take()
+ try:
+ self._take()
+ except StopIteration:
+ raise ValueError('max called for empty revorder')
return self._list[0]
- def islast(self, val):
- if not self.has(val):
- raise util.Abort(_('loglinear is confused'))
- if self._list[-1] < val:
- return False
- try:
- self._take()
- except StopIteration:
- return True
- return False
+
def __iter__(self):
return revorderiter(self)
class revorderiter:
def __init__(self, order):
self._order = order
self._index = 0
+
def __iter__(self):
return self
+
def next(self):
while self._index >= len(self._order._list):
self._order._take()
self._index += 1
return self._order._list[self._index - 1]
+
+ def hasnext(self):
+ try:
+ self.next()
+ except StopIteration:
+ return False
+ self._index -= 1
+ return True
def ancestors(repo, rev):
parents = repo.changelog.parentrevs
@@ -263,24 +285,31 @@ def seqrevorder(value):
src.reverse()
return revorder(iter(src))
-def jointorder(a, b):
- x = iter(a)
- y = iter(b)
+def emptyrevorder():
+ return seqrevorder([])
+
+def jointrevorder(a, b):
def enum():
- pending = set([])
+ pit = iter(a)
+ ait = iter(b)
+ try:
+ pval = pit.next()
+ except StopIteration:
+ for aval in ait:
+ yield aval
+ return
while True:
- while pending:
- next = max(pending)
- yield next
- pending.remove(next)
try:
- pending.add(x.next())
+ aval = ait.next()
except StopIteration:
- pass
- try:
- pending.add(y.next())
- except StopIteration:
- pass
- if not pending:
- break
+ yield pval
+ for pval in pit:
+ yield pval
+ return
+ if aval > pval:
+ yield aval
+ if aval < pval:
+ yield pval
+ pval = aval
+ pit, ait = ait, pit
return revorder(enum())

0 comments on commit 17a99ee

Please sign in to comment.