If your developers are disciplined enough to always write the ticket number in the commit log message, you can use this Perl script which searches for revisions where the log message contains a specified word. First checkout a working copy of branch B, then inside the working copy, run
perl merge-ticket.pl searchWord sourceURL
specifying the ticket number and the repository URL for branch A. The script merges the matching revisions from branch A into the working copy.
# merge-ticket.pl
use strict;
use XML::Parser;
if ($#ARGV != 1) {
die "usage: $0 searchWord sourceURL\n";
exit 1;
}
my $searchWord = $ARGV[0];
my $sourceUrl = $ARGV[1];
my @revisions = ();
my $revision;
my $inMsg;
my $message;
sub startTag {
my($parser, $tag, %attrs) = @_;
if ($tag eq 'logentry') {
$revision = $attrs{'revision'};
} elsif ($tag eq 'msg') {
$inMsg = 1;
$message = '';
}
}
sub endTag {
my($parser, $tag) = @_;
if ($tag eq 'msg') {
$inMsg = 0;
if ($message =~ /\b$searchWord\b/) {
push(@revisions, $revision);
print "$revision: $message\n";
}
}
}
sub characterData {
my($parser, $data) = @_;
if ($inMsg) {
$message .= $data;
}
}
# Search commit log messages for word.
my $command = "svn log --xml $sourceUrl";
open(INPUT, "$command|") || die "Error executing $command: $!\n";
my $parser = new XML::Parser(
Handlers => {
Start => \&startTag,
End => \&endTag,
Char => \&characterData});
$parser->parse(*INPUT);
close(INPUT);
if ($#revisions < 0) {
print "No log messages containing $searchWord found\n";
exit 1;
}
# Merge found revisions into working copy.
my $changes = join(',', reverse(@revisions));
$command = "svn merge -c$changes $sourceUrl";
print "$command\n";
system $command;