Code

Changes between Version 21 and Version 22 of MercurialBranches


Ignore:
Timestamp:
06/16/12 04:47:58 (2 years ago)
Author:
lukeplant
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MercurialBranches

    v21 v22  
    11= Mercurial Branches = 
    22 
    3 This page documents how to use Mercurial, rather than Subversion, to hack on Django. See also DjangoBranches. 
    4  
    5 == Core developers == 
    6  
    7 For people who are core committers, and want to use Mercurial rather than Subversion as their client: 
    8  
    9  1. Install the [http://mercurial.selenic.com/wiki/HgSubversion hgsubversion] extension (and understand basically how it works). 
    10  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 [http://bitbucket.org/django/django/ official Django hg mirror]).: 
    11     {{{ 
    12 hg clone svn+http://code.djangoproject.com/svn/django/ django 
    13     }}} 
    14     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).[[BR]] 
    15     ALTERNATIVELY: 
    16     1. Clone the [http://bitbucket.org/django/django/ official Django hg mirror] in the normal way, using hg 1.5 or greater. 
    17     2. Edit .hg/hgrc to say: 
    18     {{{ 
    19 default = svn+http://code.djangoproject.com/svn/django/ 
    20     }}} 
    21     3. Do `hg svn rebuildmeta`.  This works because the official Django mirror was created by hgsubversion, and is updated only by hgsubversion. 
    22  
    23  3. 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`. 
    24  
    25 === Tips === 
    26  
    27  * Use the [http://mercurial.selenic.com/wiki/BookmarksExtension 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. 
    28  * Alternatively, use the [http://mercurial.selenic.com/wiki/MqExtension queues] extension to manage long lived patches. 
    29  * To collapse several commits into a single commit before pushing back to svn, use the [http://mercurial.selenic.com/wiki/HisteditExtension histedit] extension. 
    30  * 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`). 
    31  
    32  
    33 === Backporting === 
    34  
    35 To backport a changeset from trunk, use the [http://mercurial.selenic.com/wiki/TransplantExtension 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: 
    36  
    37 {{{ 
    38 #!sh 
    39 #!/bin/sh 
    40 CURRENT_BRANCH=`hg branch | cut -f 2 -d '/'` 
    41 SVN_REV=`hg svn info -r $HGREVISION | egrep '^Revision' | cut -f 2 -d ' '` 
    42 SOURCE_BRANCH=`hg log --template "{branch}" -r $HGREVISION` 
    43 if [ "x$SOURCE_BRANCH" = "xdefault" ] 
    44 then 
    45     SOURCE_BRANCH=trunk 
    46 fi 
    47  
    48 sed -nie '1 p;2 p;3 p' "$1" 
    49 hg log -r $HGREVISION --template "[$CURRENT_BRANCH] {desc}\n\nBackport of [$SVN_REV] from $SOURCE_BRANCH.\n" >> "$1" 
    50 }}} 
    51  
    52 Then, on the branch you want to backport to: 
    53 {{{ 
    54 #!sh 
    55  
    56 hg transplant --filter ~/bin/django_backport_filter <hg revision number of changeset to backport> 
    57 }}} 
    58 (Older revisions of this wiki page have methods that work for older versions of Mercurial, but they are suboptimal - upgrading hg is preferred). 
    59  
    60 === Gotchas === 
    61  
    62 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! 
     3This page is outdated since the move to Git.