hg qimport my-bugzilla-patch redux

written 02 Jun 2009
Some of you may remember my previous post about a little script that will import patches from Bugzilla into your local queue. I haven't worked on it much since October. Yesterday I took a look into converting it into an extension and you can now see the results. Usage is simpler than before: hg qimportbz 418454 should be all you need to type in most cases. Most of the command line options have been removed and some have been replaced with Mercurial configuration options. Two still remain for the command line: -r and -n (dry run and patch name) and there is a new one -p (preview) which lets you edit the patch before it gets put on your queue. This lets you fix the commit message and author if need be and ensure that everything looks right before hg sees it. Installation is simple. Clone the repository to somewhere in your file system. Then edit an hgrc to reference the extension; you can find/create an hgrc in your Mercurial install directory, in your home directory and in a repository's .hg directory. Under [extensions], you'll need to add something along the lines of qimportbz = C:\Users\Rob\qimportbz and now you've installed the extension. I found that relative paths did not work; Mercurial would only load the extension with an absolute path. You can run hg help qimportbz to see all the options. There are some optional hgrc configuration options for the extension. Create a [qimportbz] section. The default values are: bugzilla = $BUGZILLA if set else bugzilla.mozilla.org patch_format = bug-%%(bugnum)s msg_format = Bug %%(bugnum)s - "%%(title)s" [%%(flags)s] The formats for patch_format and msg_format are the usual python formatting string format when a dictionary is used to supply the data; you will need to escape any % characters though since Python's configuration parser tries to be smart and interpret them on its own. There are 5 pieces of patch metadata available for use: "bugnum" : the bug number "id" : the patch id (internal bugzilla number) "title" : the bug title "desc" : the patch description "flags" : all the flags Hopefully everything will work...I've only tested this on Windows with Mercurial 1.0.1 (which shipped with the MozillaBuild 1.3 environment). All patches are converted to utf-8 which should hopefully alleviate past woes when importing patches with non-ascii characters. Feedback is welcome! Please let me know if there's a feature you would like to me to add or if I removed a feature you really liked. Edit: Thanks to Jason Orendorff for solving the format string issue.