svn:如何自动在分支之间传输提交

发布于 2024-07-23 10:20:37 字数 455 浏览 6 评论 0原文

我想自动化这个过程:

  1. 一个数字来自外部系统,比方说 35。
  2. 搜索并找到在分支 A 的注释中有 #35 的 svn 提交。
  3. 列出这些提交对之前提交的所有更改。
  4. 将此更改应用于分支 B。

例如,如果版本 95 的注释中有 #35 并在版本 94 上引入了新文件,请添加此 [添加文件 x.txt]。 rev 132 的注释中有#35,它更改了 x.txt 中的一行。 还添加此[更改第 n 行,文件 x.txt]。 等等。 现在我们有一个更改列表:

[Add File x.txt]
[Change line n, file x.txt]
...

将此更改应用到分支 B。

这可以在 svn 上实现吗? 命令是什么(或命令行以外的方式)? 是否存在涵盖这些操作所需命令的文档?

I want to automate this process:

  1. A number comes from an external system, let's say 35.
  2. Search and find svn commits which have #35 in their comments on branch A.
  3. Make list of all the changes of these commits to the commits before them.
  4. Apply this changes to branch B.

For e.g. if rev 95 has #35 in its comments and introduced a new file over rev 94, add this [Add File x.txt]. And rev 132 has #35 in its comments and it changed a line in x.txt. Add this also [Change line n, file x.txt]. And so on. Now we have a list of changes:

[Add File x.txt]
[Change line n, file x.txt]
...

Apply this changes to branch B.

Can this be achieved on svn? What are the commands (or a way other than command line)? Does a documentation covering necessary commands for these operations exist out there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2024-07-30 10:20:37

您需要知道刚刚提交的修订版本,然后签出/切换到分支 B,如果修订版本是 123 和 125,则使用 svn merge -c 123,125。

另请参阅 SvnBook 合并

You need to know the revision(s) that was just committed, then checkout/switch to branch B, and svn merge -c 123,125 if the revisions were 123 and 125.

See also SvnBook on merging

私藏温柔 2024-07-30 10:20:37

如果您的开发人员有足够的纪律,总是在提交日志消息中写入票号,您可以使用此 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文