Update dist-git fedmsg hook after discussion and review.

See https://github.com/fedora-infra/fedmsg/pull/322
This commit is contained in:
Ralph Bean 2015-02-23 15:58:02 +00:00
parent 3e28d0f04d
commit eb2fbbf303

View file

@ -26,30 +26,35 @@ config['active'] = True
config['endpoints']['relay_inbound'] = config['relay_inbound'] config['endpoints']['relay_inbound'] = config['relay_inbound']
fedmsg.init(name='relay_inbound', cert_prefix='scm', **config) fedmsg.init(name='relay_inbound', cert_prefix='scm', **config)
def revs_between(head, base, seen=None): def revs_between(head, ancestors):
""" Yield revisions between HEAD and BASE. """ Yield revisions between HEAD and any of the ancestors. """
Detect if a revision appears multiple times and stop recursion. # For each of my parents
""" for parent in head.parents:
# If it is not one of the known ancestors
if not parent.id in ancestors:
# Then yield all of its history, meeting the same conditions
for rev in revs_between(parent, ancestors):
yield rev
if not head.id in ancestors:
yield head.id
def gather_ancestors(commit, seen=None):
""" Yield all ancestors commits of a given commit. """
seen = seen or [] seen = seen or []
rev = unicode(head.id) idx = commit.id
bail = False if not idx in seen:
if not rev in seen: seen.append(idx)
seen.append(rev)
yield rev
for parent in head.parents: for parent in commit.parents:
if parent.id == base.id: for revid in gather_ancestors(parent, seen=seen):
bail = True yield revid
else:
bail = True
if not bail: yield idx
for parent in head.parents:
for rev in revs_between(parent, base, seen=seen):
yield rev
def build_stats(commit): def build_stats(commit):
@ -92,12 +97,13 @@ for line in lines:
try: try:
base = repo.revparse_single(base) base = repo.revparse_single(base)
revs = revs_between(head, base) ancestors = list(gather_ancestors(base))
revs = revs_between(head, ancestors)
except KeyError: except KeyError:
revs = [unicode(head.id)] revs = [head.id]
def _build_commit(rev): def _build_commit(rev):
commit = repo.revparse_single(rev) commit = repo.revparse_single(unicode(rev))
# Tags are a little funny, and vary between versions of pygit2, so we'll # Tags are a little funny, and vary between versions of pygit2, so we'll
# just ignore them as far as fedmsg is concerned. # just ignore them as far as fedmsg is concerned.
@ -116,7 +122,7 @@ for line in lines:
files=files, files=files,
total=total, total=total,
), ),
rev=rev, rev=unicode(rev),
path=abspath, path=abspath,
repo=repo_name, repo=repo_name,
branch=branch, branch=branch,
@ -125,6 +131,7 @@ for line in lines:
commits = map(_build_commit, revs) commits = map(_build_commit, revs)
print "* Publishing information for %i commits" % len(commits)
for commit in commits: for commit in commits:
if commit is None: if commit is None: