use correct locations on git.samba.org
[metze/old/samba4-sync/samba4-sync.scripts/.git] / sync-v4-0-0alpha2.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 = "tags/release-4-0-0alpha2";
12 my $svn_start_rev = 26362;
13 my $basepath = "/tmp/svn/release-4-0-0alpha2";
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 load_last_svn_rev($;$)
24 {
25         my ($file, $default_rev) = @_;
26
27         $default_rev = 0 unless 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 "load_last_svn_rev: $v\n";
36         return $v;
37 }
38
39 sub save_last_svn_rev($$)
40 {
41         my ($file, $rev) = @_;
42         util::FileSave($file, $rev);
43         print "save_last_svn_rev: $rev\n";
44 }
45
46 my $last_rev = $r->get_last_svn_rev($svn_branch);
47 my $start_rev = load_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 (sort keys %{$revs}) {
53         print "Get patch for rev: $rev\n";
54         my $p = $r->get_git_patch($revs->{$rev}->{branch}, $rev);
55
56         if (defined($p->{git_patch})) {
57                 my $patch_path = "$patch_path/$rev.patch";
58                 open(PATCH, ">$patch_path") or
59                         die ("failed to $patch_path for write");
60                 print PATCH $p->{git_patch}."\n";
61                 close PATCH;
62
63                 my $applycmd = "cd $git_repo_path && git am --whitespace=nowarn --binary $patch_path";
64
65                 print "Apply $rev.patch\n";
66                 my $apply = `$applycmd` or die "$applycmd: failed";
67         }
68
69         save_last_svn_rev($last_svn_rev_file, $rev);
70 }