Use a single format string to format output.
Expand width allowed for refname to make total output width 79 characters.

(If the refname is too long, it is still shown in full.)  The
increased width allows wider refnames to be handled without messing up
the column alignment.
Remove the feature that branch names can be abbreviated in the output.

It turned out to be too easy to use parentheses in the regexp for
other purposes, inadvertently causing only part of the reference name
to be output and making the results very confusing.  The abbreviation
feature might be reintroduced later, but in a more explicit form that
is harder to trigger accidentally.
Consider also annotated tags when matching reference name patterns.

It is silly to consider references pointing at commits but not at
annotated tags.  (If we really wanted to exclude tags, it would be
better to exclude the namespace 'refs/tags' or to include only
'refs/heads' and 'refs/remotes', but there doesn't seem to be a reason
to do so.)
Make commit designators in examples look more like SHA1s.

The old value, "abcd", looked too much like a branch name.
Extract a function iter_commit_refs().

Also rename iter_refs() to iter_matching_refs().
Do not schlepp around (branch, abbrev) in main program.

They are always equal now.
Remove the "abbrev" argument to find_merge().
Sort output by branch name and eliminate duplicates.
Extract a function matches_any().
Use any() in definition of matches_any().
Inline function iter_matching_refs().
Add a Python version check.
Display the reference referred to be HEAD (unless HEAD is detached).
Add license information.
Import and use subprocess.check_output().

Try to import subprocess.check_output().  If it is not available (it
was added only in Python 2.7) then define it using the definition from
Python 2.7.  Use this function where appropriate instead of
manipulating processes directly.
Allow SHA1s in output to be abbreviated.

Add new options --abbrev=N and --no-abbrev and configuration setting
whenmerged.abbrev to allow Git SHA1s to be abbreviated in the output.
By default, output the full SHA1s.
Display BRANCH arguments in canonical form in output.

* If an abbreviated reference name (e.g., "master"), output the full
  branch name (e.g., "refs/heads/master").

* If a symbolic ref, display the full name of the branch referred to.