混帐SVN:自动导入/创建svn的修订版的Git标签
我使用Git SVN的svn库工作。 git的主
分支镜像主干
分支(使用的唯一SVN分支),即有一个对svn到主分支和主干分支元件之间的一个关系。
I am using git-svn to work with a svn repository. The git master
branch is mirroring the svn trunk
branch (the only svn branch in use), i.e. there is a one to one relation between elements on the master branch and the trunk branch.
我想有一个对应于svn的版本的Git标签,这样我可以这样做,例如 git的差异R123 workbranch
的东西,看看有什么我都比较SVN做修订123。
I want to have git tags that corresponds to svn revisions, so that I can do things like for instance git diff r123 workbranch
to see what I have done compared to svn revision 123.
当我这样做混帐SVN变基
的修订没有标记,所以我创建了我运行后SVN底垫下面的脚本:
The revisions are not tagged when I do git svn rebase
, so I have created the following script that I run post svn rebase:
#!/usr/bin/perl
use strict;
use warnings;
open(PIPE, "git log master |");
# Format for the pipe output:
# ...
# commit 6b24b8fdc6a25d35b01140dc1ac054697133423d
# ...
# git-svn-id: https://server.example.com/svn/project/trunk@594 164096ca-3471-41d1-a9ce-9541462a8c31
# ...
my $commit = "";
my $i = 0;
foreach my $line (<PIPE>) {
if ($line =~ /^commit ([\da-f]+)/) {
$commit = $1;
next;
}
next unless $line =~ /^\s+git-svn-id: .*\/trunk\@(\d+) /;
my $git_svn_id = $1;
run("git", "tag", "-f", "r$git_svn_id", $commit);
last if $i++ == 20;
}
close(PIPE);
sub run {
print join(' ', @_), "\n";
return system(@_);
}
该脚本可以完成任务,但我必须每次手动运行它,我已经(任意)上限它在检查过去的21修订所以缺少一些(但我会看到,从理论上的风险印刷)。
This script gets the job done, but I have to run it manually every time, and I have (arbitrarily) capped it at checking the last 21 revisions so there is a theoretical risk of missing some (but I will see that from the printing).
问题:有什么办法可以自动执行此让我就跑混帐SVN变基
键,全部采用进口版本将被标记的混帐?任何挂钩我可以使用?
The question: Is there any way I can automate this so that I just run git svn rebase
and all imported revisions will be tagged in git? Any hooks I can use?
PS
是的,我知道SVN的发现-REV,但我想绝对不必编写命令一样复杂 git的差异$(GIT SVN找到-REV R123)$(GIT SVN找到-REV R124没办法)
,而不是仅仅 git的差异R123 R124
。
下面是一个疯狂的想法:陷阱庆典
命令,并自动更换任何 r1234
与SHA哈希的字符串:
Here's a crazy idea: Trap bash
commands and automatically replace any r1234
strings with SHA hashes:
shopt -s extdebug
enhance_rev_parse () {
[ -n "$COMP_LINE" ] && return # do nothing if completing
case "$BASH_COMMAND" in
*r[0-9]*)
eval $(echo "$BASH_COMMAND" | sed -e 's/r[0-9][0-9]*/$(git svn find-rev &)/g')
return 1
;;
esac
}
trap 'enhance_rev_parse' DEBUG