signoff.py: A Mercurial hook to automatically add a “Signed-off-by:” tag line below your commit message

The openATTIC project is currently transitioning to adapting the patch contribution signoff process initially established by the Linux Kernel developers, in which every commit message is “signed” with a special Signed-off-by: tag line, that certifies that the patch contribution meets certain criteria with regards to ownership/copyright and licensing.

The git distributed revision control system (DVCS) used by the Linux Kernel and many other projects actually provides an option --sign that can be passed to the git commit command, which will add the Signed-off-by: line at the end of the commit log message automatically.

However, the openATTIC code base is managed using the Mercurial DVCS, which currently does not offer the same functionality out of the box. Fortunately, Mercurial is written in Python and is very extensible: it is possible to extend its functionality and modify the workflows via Hooks and Extensions.

Much to my surprise, I was not able to find an existing plugin or extension that provides this functionality. So I took this opportunity to hone my Python skills and wrote one myself – signoff.py is a simple Mercurial hook, that will automatically add the signoff tag line below the commit message. Currently it is pretty rudimentary, I still need to read up on how to convert it into a proper Mercurial extension that extends the existing hg commit command, so the signoff process can be enabled by passing it as an option.

To enable it, dowmload the file and save it as signoff.py into the .hg directory of your Mercurial repository and add the following to .hg/hgrc:

[hooks]
precommit = python:.hg/signoff.py:sign_commit_message

If you have any suggestions or ideas on how to improve it, please let me know!