The Mercurial The Definitive Guide, also known as the hg book, contains a section on writing extensions for Mercurial. The book is available for free viewing at http://hgbook.red-bean.com/ .
Edit: My apologies, the hg book only described the use of extensions not writing them. The section on writing hooks in a book can still be useful.
The best way to learn how to write an extension is probably to read the extension code. Pay most attention to extensions that perform functions similar to what you want to implement.
eg. If you are interested in moving from one SCM system to another, check out the hg-git extension.
source share