如果您的開發人員有足夠的紀律以便始終在提交日誌消息中寫入故障單編號,則可以使用此Perl腳本搜索日誌消息中包含指定單詞的修訂版。第一次檢出分支B的工作副本,然後將工作副本中,運行
perl merge-ticket.pl searchWord sourceURL
指定票號和分支A.庫URL腳本合併來自一個分支匹配的版本到工作副本。
# 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;
哇,這看起來像一個很棒的作品,並且完全符合我的需求。如果只有我知道一點Perl(:我會嘗試理解並將其轉換爲C#,謝謝。 – 2009-06-14 20:10:59