Monday, September 20, 2010

Testing patches from Bugzilla

I just started using MQ (Mercurial Queues). Now that I've tried it I can't imagine ever using a mercurial repo without it! I know that sounds a bit cliche, like something out of a commercial, but it's true!

Here's how to test patches from bugzilla. With MQ you can apply the patches, test them and then remove them with ease if you want to revert back to trunk code. Well the main purpose of MQ is to help with code development so that you can write new patches, edit, update, and remove when needed. But there is also times you want to test someone else's patches, for example from a bug on Bugzilla, in this case too MQ can help.

How to test patches using MQ.. (updated 23.09.2010)

- First make sure you have MQ installed. MQ is a Mercurial extension. Make sure you have MQ setup by following the Mozilla MQ guide ( https://developer.mozilla.org/en/Mercurial_Queues ).

- Now you can use either method 1 or method 2 below to import the patches to MQ..

Mtd 1:

hg qimport -n name-of-patch patch-url
(patch-url will be the atachment url from bugzilla)

Mtd2:

A more convenient method is to use the qimportbz extension which will allow you to import patches directly from the Bug# http://robarnold.org/hg-qimport-my-bugzilla-patch-redux/

After setting up qimportbz extension do:

hg qimport bz://xxxxxx
(xxxxxx is the bug number on bugzilla)

When a list of patches is displayed enter the numbers of the patches you want with a space in between. The first patch applied will be named with the bugnumber (you can rename this later in the .hg/patches folder). The qimport extension will attempt to name all the following patches with the same name and give the error..

A patch file named 'bug-xxxxxx.diff' already exists in your patch directory. Rename patch 'abcdef' (yyyyyy) (r)/overwrite (o)?

Hit enter and give a new name for the patch. Continue for all the remaining patches until importing is complete.

-After importing the patch(es)..

hg qpush name-of-patch
(apply the patch to MQ. you can use -a option to apply all the patches at once)

Test the patch(es)

hg qpop
(removes patches from the top of the queue)

For a quick lookat MQ commands see http://mercurial.selenic.com/wiki/MqExtension

4 comments:

  1. A cool thing is to just do

    hg qimport https://bugzilla.mozilla.org/attachment.cgi?id=xxxxx

    That will directly import the patch from that bug attachment into a mq patch.

    ReplyDelete
  2. The problem with "patch -p1" is that it can handle only simply text changes, no file renames, binary files like images etc. Use the command KaiRo suggested, or "git apply -v -p1" instead (unfortunately "git" doesn't come with MozillaBuild on Windows but you can install it through Cygwin and add it to your PATH).

    ReplyDelete
  3. kairo - thank you! i installed the qimportbz extension to get the patches from the bug number itself.

    Jens - yes, that explains the missing images!

    ReplyDelete
  4. I used mq for a while but switched over to pbranch...much nicer for my workflow.

    ReplyDelete