Version 11 (modified by Ramiro Morales, 14 years ago) ( diff )

hg_backport script: Modified hg log invocation so the commit message obtained is the right one.

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 been 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.
  • 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
  • To backport a changeset from trunk, use the transplant extension. Or use this handy script which will generate the commit message for you:
    #!/bin/bash
    
    function usage {
        echo "Usage: hg_backport <branch> <hgrevision>";
    }
    
    if [ $# -ne 2 ]
    then
            usage;
            exit 1;
    fi
    
    SHORTBRANCH="$1"
    BRANCH="releases/$SHORTBRANCH" # we only backport to release branches.
    HGREV="$2"
    
    hg st -a -r -m | grep '' > /dev/null && { echo "Working directory not clean - exiting" > /dev/stderr; exit 1; }
    
    SVNREV=`hg svn info -r $HGREV | egrep '^Revision' | cut -f 2 -d ' '`
    if [ "x$SVNREV" = "x" ]
    then
            echo "Can't find svn rev";
            exit 1;
    fi
    
    echo "Backporting Subversion revision $SVNREV"
    hg update $BRANCH || exit 1;
    # Make a commit message first in case the transplant fails.
    hg log -r $HGREV --template "[$SHORTBRANCH] {desc}\n\nBackport of [$SVNREV] from trunk\n" > hg-commit-message.txt || exit 1
    hg transplant $HGREV || exit 1;
    # Modify the commit message
    hg rollback > /dev/null || exit 1
    hg commit -l hg-commit-message.txt || exit 1
    echo "Backport committed."
    
    The command line is like:
    hg_backport 1.2.X 13643
    
    where 1.2.X is a directory under 'releases/' in the Subversion repo, and 13643 is a hg revision ID. The change is already committed to the local repo, but not 'pushed', so you can still rollback if changes need to be made.

Gotchas

If you make two commits, and only want to push the first, you will have some trouble, since the hg push command doesn't support specifying revisions. Nice solutions to this welcome! - use hg push -r rev ?

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