Based on the darcs patch from Greg Wright in #4828.
mentioned in issue #4828 (closed)
mentioned in commit c937dc7d