Changes between Version 12 and Version 13 of MercurialBranches

12/03/2010 06:04:26 PM (8 years ago)
Russell Keith-Magee

Added my own variant on the backport script.


  • MercurialBranches

    v12 v13  
    7373   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.
     75=== An alternate approach ===
     77Another way of doing the same thing: Use the --filter option to the transplant extension. This requires the use of a Python script. Put the following in, and stick it in a tools directory somewhere:
     81import os
     82import sys
     84msg = sys.argv[1]
     85patch = sys.argv[2]
     88msg_file = open(msg, 'r')
     89outlines = []
     90firstline = True
     91for raw_line in msg_file:
     92    line = raw_line.strip()
     93    if firstline:
     94        if line.startswith('#'):
     95            outlines.append(line)
     96        else:
     97            firstline = False
     98            print 'MERGING: %s' % line
     99            outlines.append('[1.2.X] %s' % line)
     100    else:
     101        outlines.append(line)
     104svn_revision = os.environ.get('SVNMERGE_REVISION',None)
     105if svn_revision is None:
     106    svn_revision = raw_input('SVN Revision: ')
     108    print "SVN Revision:", svn_revision
     110outlines.append('Backport of r%s from trunk.' % svn_revision)
     112# And write the updated message file.
     113msg_file = open(msg,'w')
     114for line in outlines:
     115    print >> msg_file, line
     118# In case of a clash, write the filename of the message file
     119print "Log message written to",msg
     122Then, use the following shell script to do the actual backport:
     126export SVNMERGE_REVISION=`hg svn info -r $1 | egrep '^Revision' | cut -f 2 -d ' '`
     127hg transplant $1 --filter /path/to/
     131If you call this script 'hg_backport', then
     133The command line is like:
     136hg_backport 13643
     138Any hg revision ID can be used as the argument; since the most common usage pattern is to backport the most recent svn commit on trunk, you can use 'tip':
     141hg_backport tip
     144This script needs to be manually updated after every release, because the [1.2.X] string is hardcoded. This is mostly due to my (Russell's) own laziness -- it would be trivial to update the script to pull the branch identifier from the output of `hg branch`.
    75146=== Gotchas ===
    77148If 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!
Back to Top