~edwargix/git.sr.ht

1c87eb35c8918bcc3a26274c1224122f2d0180cb — Robin Krahl 7 years ago 8e9083c
Filter duplicate refs in gitsrht-update-hook

If multiple refs that point to the same commit are pushed with one
command, the girsrht-update-hook currently triggers multiple builds.  To
fix this, we check the object IDs of the Git references and skip
duplicates.  (We have to duplicate the checks as git_repo.get(ref)
returns a Git object and git_repo.lookup_reference(ref).target is an
object ID.)
1 files changed, 7 insertions(+), 0 deletions(-)

M gitsrht-update-hook
M gitsrht-update-hook => gitsrht-update-hook +7 -0
@@ 43,12 43,19 @@ if op == "hooks/post-update":
    db.session.commit()

    git_repo = GitRepository(repo.path)
    oids = set()
    for ref in refs:
        try:
            if re.match(r"^[0-9a-z]{40}$", ref): # commit
                ref = git_repo.get(ref)
                if ref.id in oids:
                    continue
                oids.add(ref.id)
            elif ref.startswith("refs/"): # ref
                ref = git_repo.lookup_reference(ref).target
                if ref in oids:
                    continue
                oids.add(ref)
            else:
                continue
        except: