add code based on SVN and SVK perl bindings to get
[metze/old/samba4-sync/samba4-sync.scripts/.git] / sync-v4-0-test.pl
1 #!/usr/bin/perl
2 #
3
4 use strict;
5
6 use SVN2GitPatch;
7
8 my $svn_repo_path = "/tmp/svn/samba.repo";
9 my $authors_file = "svn-authors";
10
11 my $svn_branch = "branches/SAMBA_4_0";
12 my $svn_start_rev = 25600;
13 my $basepath = "/tmp/svn/v4-0-test";
14
15 my $patch_path = "$basepath/patches";
16 my $last_svn_rev_file = "$patch_path/latest.svnrev";
17 my $git_repo_path = "$basepath/git";
18
19 $ENV{LANG} = "en_US.UTF-8";
20
21 my $r = SVN2GitPatch->new($svn_repo_path, $authors_file);
22
23 sub get_last_svn_rev($;$)
24 {
25         my ($file, $default_rev) = @_;
26
27         $default_rev = 25600 if defined($default_rev);
28
29         my $v = util::FileLoad($file);
30
31         $v = $default_rev if $v eq "";
32         $v *= 1;
33         $v = $default_rev if $v == 0;
34
35         print "get_last_svn_rev: $v\n";
36         return $v;
37 }
38
39 sub set_last_svn_rev($$)
40 {
41         my ($file, $rev) = @_;
42         util::FileSave($file, $rev);
43         print "set_last_svn_rev: $rev\n";
44 }
45
46 my $last_rev = $r->get_last_svn_rev($svn_branch);
47 my $start_rev = get_last_svn_rev($last_svn_rev_file, $svn_start_rev);
48 my @revs = $r->get_missing_svn_revs($svn_branch, $start_rev);
49
50 print "start: $start_rev last: $last_rev\n";
51
52 foreach my $rev (@revs) {
53
54         print "Get patch for rev: $rev\n";
55         my $p = $r->get_git_patch($svn_branch, $rev);
56
57         next unless defined($p->{git_patch});
58
59         my $patch_path = "$patch_path/$rev.patch";
60         open(PATCH, ">$patch_path") or die ("failed to $patch_path for write");
61         print PATCH $p->{git_patch}."\n";
62         close PATCH;
63
64         my $applycmd = "cd $git_repo_path && git am --whitespace=nowarn --binary $patch_path";
65
66         my $apply = `$applycmd` or die "$applycmd: failed";
67
68         set_last_svn_rev($last_svn_rev_file, $rev);
69 }