Version 21 (modified by Luke Plant, 13 years ago) ( diff )

--

Mercurial Branches

This page documents how to use Mercurial, rather than Subversion, to hack on Django. See also DjangoBranches.

Core developers

For people who are core committers, and want to use Mercurial rather than Subversion as their client:

  1. Install the hgsubversion extension (and understand basically how it works).
  2. Clone the Subversion repository (do this using hg version 1.5 or higher, or else the changeset hashes generated by hgsubversion will be incompatible with those from repos generated using newer hg versions, including the official Django hg mirror).:
    hg clone svn+http://code.djangoproject.com/svn/django/ django
    
    This will take a Good While (lots of hours), and in some cases can take a Very Long Time for just one changeset (I gave up on r11505).
    ALTERNATIVELY:
    1. Clone the official Django hg mirror in the normal way, using hg 1.5 or greater.
    2. Edit .hg/hgrc to say:
      default = svn+http://code.djangoproject.com/svn/django/
      
    3. Do hg svn rebuildmeta. This works because the official Django mirror was created by hgsubversion, and is updated only by hgsubversion.
  1. Use normal hg commands to make commits, switch branches, push back to the subversion repository etc. Remember to use hg rebase --svn, and not hg merge.

Tips

  • Use the bookmarks extension for git-style local feature branches, or named branches for feature branches that you need other people to see. Note that this will effectively block you from pushing any changes back to Subversion until you have merged the branch and linearised your history, since hgsubversion doesn't support selective pushing of revisions, and, worse, appears to push changes on newly created branches back to trunk, rather than creating new subversion branches.
  • Alternatively, use the queues extension to manage long lived patches.
  • To collapse several commits into a single commit before pushing back to svn, use the histedit extension.
  • Use the 'svnrev' revset specifier to find info about a revision using SVN rev numbers (e.g. hg log -r 'svnrev(12345)'. Use the 'svn info' command to go the other way around (e.g. hg svn info -r 12155).

Backporting

To backport a changeset from trunk, use the transplant extension. From Mercurial 1.9 onwards, you can use the 'filter' feature of transplant to create the commit message for you. Save the following script as ~/bin/django_backport_filter (for example) and make it executable:

#!/bin/sh
CURRENT_BRANCH=`hg branch | cut -f 2 -d '/'`
SVN_REV=`hg svn info -r $HGREVISION | egrep '^Revision' | cut -f 2 -d ' '`
SOURCE_BRANCH=`hg log --template "{branch}" -r $HGREVISION`
if [ "x$SOURCE_BRANCH" = "xdefault" ]
then
    SOURCE_BRANCH=trunk
fi

sed -nie '1 p;2 p;3 p' "$1"
hg log -r $HGREVISION --template "[$CURRENT_BRANCH] {desc}\n\nBackport of [$SVN_REV] from $SOURCE_BRANCH.\n" >> "$1"

Then, on the branch you want to backport to:

hg transplant --filter ~/bin/django_backport_filter <hg revision number of changeset to backport>

(Older revisions of this wiki page have methods that work for older versions of Mercurial, but they are suboptimal - upgrading hg is preferred).

Gotchas

If you make two commits, and only want to push the first, you will have some trouble, since the HgSubversion extensions doesn't support specifying revisions with the hg push command when pushing to a Subversion repository. Nice solutions to this welcome!

Note: See TracWiki for help on using the wiki.
Back to Top