1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my $make_patch_cmd = 'svn diff > b4_svn_relocate_2_waltz.patch'; |
---|
7 | { |
---|
8 | my $psp = $ENV{HOME}.'/bin/patch_store.pl'; |
---|
9 | if (-x $psp) { $make_patch_cmd = 'patch_store.pl --keep AUTO'; } |
---|
10 | } |
---|
11 | |
---|
12 | |
---|
13 | sub get_svn_url_rev() { |
---|
14 | my $cmd = 'svn info'; |
---|
15 | my ($url,$rev) = (undef,undef); |
---|
16 | |
---|
17 | open(INFO,$cmd.'|') || die "can't exec '$cmd' (Reason: $?)"; |
---|
18 | foreach (<INFO>) { |
---|
19 | chomp; |
---|
20 | if (/^URL:\s/) { $url = $'; } |
---|
21 | if (/^Revision:\s/) { $rev = $'; } |
---|
22 | } |
---|
23 | close(INFO); |
---|
24 | |
---|
25 | if (not defined $url) { die "could not parse 'URL' from '$cmd'"; } |
---|
26 | if (not defined $rev) { die "could not parse 'Revision' from '$cmd'"; } |
---|
27 | |
---|
28 | return ($url,$rev); |
---|
29 | } |
---|
30 | |
---|
31 | sub convert_URL($) { |
---|
32 | my ($old) = @_; |
---|
33 | if (not $old =~ /\@menuett\.mikro\.biologie\.tu-muenchen\.de\/menuett1\/repository\/ARB\//) { |
---|
34 | die "expected URL '$old'\nto contain 'menuett.mikro.biologie.tu-muenchen.de/menuett1/repository/ARB'"; |
---|
35 | } |
---|
36 | |
---|
37 | my ($prefix,$suffix) = ($`,$'); |
---|
38 | my $accept_suffix = 0; |
---|
39 | if ($suffix eq 'trunk') { $accept_suffix = 1; } |
---|
40 | elsif ($suffix =~ /^(branches|tags)\/[^\/]+$/) { $accept_suffix = 1; } |
---|
41 | |
---|
42 | if ($accept_suffix==0) { die "wont accept url '$old'\ndid you call from root of checkout?"; } |
---|
43 | |
---|
44 | my $new_part = '@svn.arb-home.de/svn/ARB/'; |
---|
45 | return $prefix.$new_part.$suffix; |
---|
46 | } |
---|
47 | |
---|
48 | sub main() { |
---|
49 | my ($oldurl,$rev) = get_svn_url_rev(); |
---|
50 | |
---|
51 | # print "rev='$rev'\n"; |
---|
52 | |
---|
53 | if (not $rev =~ /^[0-9]+$/) { die "invalid revision '$rev'"; } |
---|
54 | |
---|
55 | my $newurl = convert_URL($oldurl); |
---|
56 | print "oldurl='$oldurl'\n"; |
---|
57 | print "newurl='$newurl'\n"; |
---|
58 | |
---|
59 | print "creating safety-patch using\n$make_patch_cmd\n"; |
---|
60 | system($make_patch_cmd)==0 || die "failed to exec '$make_patch_cmd' (Reason: $?)"; |
---|
61 | |
---|
62 | my $switch_command = "svn switch --relocate -r $rev '$oldurl' '$newurl'"; |
---|
63 | print "Running\n$switch_command\n"; |
---|
64 | |
---|
65 | system($switch_command)==0 || die "failed to exec '$switch_command' (Reason: $?)"; |
---|
66 | } |
---|
67 | main(); |
---|