如果您的开发人员有足够的纪律,总是在提交日志消息中写入票号,您可以使用这个 Perl 脚本来搜索日志消息包含指定单词的修订。首先签出分支 B 的工作副本,然后在工作副本中运行
perl merge-ticket.pl searchWord sourceURL
指定分支 A 的票号和存储库 URL。脚本将分支 A 中的匹配修订合并到工作副本中。
# 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;