Changes between Version 12 and Version 13 of MercurialBranches


Ignore:
Timestamp:
12/03/10 18:04:26 (4 years ago)
Author:
russellm
Comment:

Added my own variant on the backport script.

Legend:

Unmodified
Added
Removed
Modified
  • 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.
    7474
     75=== An alternate approach ===
     76
     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 backport.py, and stick it in a tools directory somewhere:
     78{{{
     79#!python
     80#!/usr/bin/python
     81import os
     82import sys
     83
     84msg = sys.argv[1]
     85patch = sys.argv[2]
     86
     87print
     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)
     102msg_file.close()
     103
     104svn_revision = os.environ.get('SVNMERGE_REVISION',None)
     105if svn_revision is None:
     106    svn_revision = raw_input('SVN Revision: ')
     107else:
     108    print "SVN Revision:", svn_revision
     109outlines.append('')
     110outlines.append('Backport of r%s from trunk.' % svn_revision)
     111
     112# And write the updated message file.
     113msg_file = open(msg,'w')
     114for line in outlines:
     115    print >> msg_file, line
     116msg_file.close()
     117
     118# In case of a clash, write the filename of the message file
     119print "Log message written to",msg
     120}}}
     121
     122Then, use the following shell script to do the actual backport:
     123{{{
     124#!sh
     125#!/bin/bash
     126export SVNMERGE_REVISION=`hg svn info -r $1 | egrep '^Revision' | cut -f 2 -d ' '`
     127hg transplant $1 --filter /path/to/backport.py
     128unset SVNMERGE_REVISION
     129}}}
     130
     131If you call this script 'hg_backport', then
     132
     133The command line is like:
     134{{{
     135#!sh
     136hg_backport 13643
     137}}}
     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':
     139{{{
     140#!sh
     141hg_backport tip
     142}}}
     143
     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`.
     145
    75146=== Gotchas ===
    76147
    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!
     149
Back to Top