Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • How to Hide Inactive Branches by Default with Mercurial

    mercurial usually shows inactive branches when running "hg branches" but that's kind of annoying if you have lots of old inactive branches. So I recently set up my personal .hgrc to hide inactive branches by creating an alias.

    [alias]
    branches = branches -a
    

    Normally you get this kind of output.

    ian@laptop:~/src/prj$ hg branches
    default                     1662:1fa310d3052a
    hoge                        1661:62d737e7146e
    hoge_inactive               1623:ba27ba59a257 (inactive)
    hoge_closed                 670:1c3134ca4a95 (closed)
    

    But after setting up the alias inactive branches aren't shown.

    ian@laptop:~/src/prj$ hg branches
    default                     1662:1fa310d3052a
    hoge                        1661:62d737e7146e
    

    This way though there isn't a good way to show all branches if you have set up an alias so you might want to give the alias a different name like "abranches" for "active branches" so that you can show all branches by using "hg branches".

    Send feedback   このエントリーを含むはてなブックマーク はてなブックマーク - How to Hide Inactive Branches by Default with Mercurial
  • Importing an svn repository into mercurial

    Recently I've been forking svn repositories by converting them to mercurial repositories and uploading them to bitbucket. It's fairly easy with the mercurial convert extension. Convert is distributed with mercurial so if you have a recent version all you should have to do is put the following in your hgrc.

    [extensions]
    hgext.convert=
    

    Converting a repository over http by running convert using the repository url can be very slow so it's generally much faster to sync the svn repository locally and then convert it to hg. First you need to use svnsync to copy the repository.

    $ svnadmin create foomirror
    $ echo '#!/bin/sh' > foomirror/hooks/pre-revprop-change   # make insecure dummy hook
    $ chmod +x foomirror/hooks/pre-revprop-change
    $ svnsync init --username svnsync file://`pwd`/foomirror https://foo.svn.sourceforge.net/svnroot/foo
    Copied properties for revision 0.
    $ svnsync sync file://`pwd`/foomirror
    Committed revision 1.
    Copied properties for revision 1.
    Committed revision 2.
    Copied properties for revision 2.
    ...
    

    Once the mirror is set up you can run hg convert on the local mirror. This turns out to be much faster than trying to convert the svn repository remotely.

    $ hg convert foomirror   # convert directly from repo mirror to foomirror-hg
    ...
    
    Send feedback   このエントリーを含むはてなブックマーク はてなブックマーク - Importing an svn repository into mercurial
  • Using Mercurial MQ

    I recently started using mercurial's mq extension at work as I found myself switching between changes a lot. I often had to set changes I was currently working on aside to do a merge or fix something that was more urgent. The mq extension makes that possible by managing patches and allowing you to put away changes into the patch queue.

    mq is included in mercurial's distribution by default but you need to enable it in your .hgrc

    [extensions]
    mq =
    

    Ok, so now I'll run through the most used commands.

    hg qinit
    

    When you want to create a new patch you use the qnew command.

    hg qnew
    

    My original use case for mq was as a place to put my current changes so I could do back to a normal state and do some work without actually having to commit it to the repository. Originally I thought that because qnew spit out errors when I tried to create a new patch, I figured I would have do the following in order to get it back to a normal state and create my patch.

    hg diff -U > my.diff
    hg revert --all
    hg qnew mypatch
    patch -p1 < my.diff
    

    But a friend informed me that the -f option to qnew does exactly what I needed. It takes your current changes and then rolls them into the new patch.

    hg qnew -f mypatch
    

    The patch shows in your revision history while it's applied but it's not really committed.

    After you make some more changes you can update the patch by running qrefresh.

    hg qrefresh
    

    You run qrefresh with the -e option to set the commit message that is used later when you actually commit to the repository.

    hg qrefresh -e
    

    Once you set it you can just run qrefresh without the -e and it will retain the message.

    Here's the fun part. If you need to put the changes away you can unapply them off by running qpop with the name of your patch

    hg qpop mypatch
    

    or qpop -a which unapplies all the patches.

    hg qpop -a
    

    This will bring you back to the normal repository version. You can then merge or fix a bug or do what you need to do. After you are done and you want to work on your changes again you can reapply them with qpush.

    hg qpush mypatch
    

    or

    hg qpush -a
    

    Mq doesn't care about the revision history so you can try to apply the patch anywhere in the revision history. Be careful though since the patch might not apply if there were changes to the files updated by the patch.

    Once you are done with all your changes you can run qfinish to commit them to the regular repository.

    hg qfinish mypatch
    

    You can call it with a range also. MQ gives you qbase and qtip labels which are attached to the base patch and the tip patch. This effectively finishes all the patches.

    hg qfinish qbase:qtip
    

    That's it!

    Send feedback   このエントリーを含むはてなブックマーク はてなブックマーク - Using Mercurial MQ
  • hg email and gmail

    I just set up my e-mail settings with Mercurial so that I can e-mail patches via my Gmail account. I have Debian installed on my machine which has exim installed by default so it was pretty easy to set up. I'm not terribly versed at setting up mailing agents so I basically followed these instructions on the Debian Wiki. After getting that set up it's easy to set up Mercurial to use exim4 since it's a drop in replacement for sendmail.

    To set up Mercurial to use exim I followed the instructions on the Mercurial Wiki:

    email::
    ...
    method;;
    Optional. Method to use to send email messages. If value is
    "smtp" (default), use SMTP (see section "[smtp]" for
    configuration). Otherwise, use as name of program to run that
    acts like sendmail (takes "-f" option for sender, list of
    recipients on command line, message on stdin). Normally, setting
    this to "sendmail" or "/usr/sbin/sendmail" is enough to use
    sendmail to send messages.

    Email example:

    [email]
    from = Joseph User <joe.user@example.com>
    method = /usr/sbin/sendmail

    So here is my very simple ~/.hgrc file:

    [ui]
    username = Ian Lewis <IxxMLxxxx@gmail.com>
    [email]
    from = Ian Lewis <IxxMLxxxx@gmail.com>
    method = /usr/sbin/exim4

    Simple. Now I just enable POP for my gmail and I can use hg email and it will go through my gmail account. Now only if the Mercurial guys would fix this issue so I can send the patch email with the correct encoding.

    Send feedback   このエントリーを含むはてなブックマーク はてなブックマーク - hg email and gmail