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.
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.
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(@_);
}
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).
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
Yes, I am aware of svn find-rev, but I want in absolutely no way having to write commands as complicated as git diff $(git svn find-rev r123) $(git svn find-rev r124)
instead of just git diff r123 r124
.