Avoid infinite recursion in the dist-git fedmsg hook.

This commit is contained in:
Ralph Bean 2015-02-22 18:08:19 +00:00
parent f44c9a29de
commit 638a0c41a1

View file

@ -26,18 +26,29 @@ config['active'] = True
config['endpoints']['relay_inbound'] = config['relay_inbound']
fedmsg.init(name='relay_inbound', cert_prefix='scm', **config)
def revs_between(head, base):
def revs_between(head, base, seen=None):
""" Yield revisions between HEAD and BASE.
Detect if a revision appears multiple times and stop recursion.
"""
seen = seen or []
rev = unicode(head.id)
bail = False
if not rev in seen:
seen.append(rev)
yield rev
yield unicode(head.id)
for parent in head.parents:
if parent.id == base.id:
bail = True
for parent in head.parents:
if parent.id == base.id:
bail = True
else:
bail = True
if not bail:
for parent in head.parents:
for rev in revs_between(parent, base):
for rev in revs_between(parent, base, seen=seen):
yield rev