summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalph Bean <rbean@redhat.com>2015-02-23 15:58:02 +0000
committerRalph Bean <rbean@redhat.com>2015-02-23 15:58:02 +0000
commiteb2fbbf30351b522493ee56699caece99d1a603e (patch)
treeeade6ad1c26b9f51cdc94409a142d60420755a63
parent3e28d0f04d42103481679c2ff4ed763f59ae8e6d (diff)
downloadansible-eb2fbbf30351b522493ee56699caece99d1a603e.tar.gz
ansible-eb2fbbf30351b522493ee56699caece99d1a603e.tar.xz
ansible-eb2fbbf30351b522493ee56699caece99d1a603e.zip
Update dist-git fedmsg hook after discussion and review.
See https://github.com/fedora-infra/fedmsg/pull/322
-rw-r--r--roles/git/hooks/files/post-receive-fedmsg57
1 files changed, 32 insertions, 25 deletions
diff --git a/roles/git/hooks/files/post-receive-fedmsg b/roles/git/hooks/files/post-receive-fedmsg
index edc945a9d..0276c9932 100644
--- a/roles/git/hooks/files/post-receive-fedmsg
+++ b/roles/git/hooks/files/post-receive-fedmsg
@@ -26,30 +26,35 @@ config['active'] = True
config['endpoints']['relay_inbound'] = config['relay_inbound']
fedmsg.init(name='relay_inbound', cert_prefix='scm', **config)
-def revs_between(head, base, seen=None):
- """ Yield revisions between HEAD and BASE.
+def revs_between(head, ancestors):
+ """ Yield revisions between HEAD and any of the ancestors. """
+
+ # 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
- Detect if a revision appears multiple times and stop recursion.
- """
+
+def gather_ancestors(commit, seen=None):
+ """ Yield all ancestors commits of a given commit. """
seen = seen or []
- rev = unicode(head.id)
-
- bail = False
- if not rev in seen:
- seen.append(rev)
- yield rev
-
- 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, seen=seen):
- yield rev
+ idx = commit.id
+
+ if not idx in seen:
+ seen.append(idx)
+
+ for parent in commit.parents:
+ for revid in gather_ancestors(parent, seen=seen):
+ yield revid
+
+ yield idx
def build_stats(commit):
@@ -92,12 +97,13 @@ for line in lines:
try:
base = repo.revparse_single(base)
- revs = revs_between(head, base)
+ ancestors = list(gather_ancestors(base))
+ revs = revs_between(head, ancestors)
except KeyError:
- revs = [unicode(head.id)]
+ revs = [head.id]
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
# just ignore them as far as fedmsg is concerned.
@@ -116,7 +122,7 @@ for line in lines:
files=files,
total=total,
),
- rev=rev,
+ rev=unicode(rev),
path=abspath,
repo=repo_name,
branch=branch,
@@ -125,6 +131,7 @@ for line in lines:
commits = map(_build_commit, revs)
+ print "* Publishing information for %i commits" % len(commits)
for commit in commits:
if commit is None: