return if there's no mode change and no content change
[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 $svn_repo_path = "/home/svn/samba";
10 my $authors_file = "svn-authors";
11
12 my $svn_branch = "branches/SAMBA_4_0";
13 my $svn_start_rev = 25600;
14 $svn_start_rev = 26554;
15 my $basepath = "/tmp/svn/v4-0-test";
16 $basepath = "/data/git/metze/samba4-sync/samba4-draft";
17
18 my $patch_path = "$basepath/patches";
19 my $last_svn_rev_file = "$patch_path/latest.svnrev";
20 my $git_repo_path = "$basepath/git";
21
22 $ENV{LANG} = "en_US.UTF-8";
23
24 my $r = SVN2GitPatch->new($svn_repo_path, $authors_file);
25
26 sub load_last_svn_rev($;$)
27 {
28         my ($file, $default_rev) = @_;
29
30         $default_rev = 0 unless defined($default_rev);
31
32         my $v = util::FileLoad($file);
33
34         $v = $default_rev if $v eq "";
35         $v *= 1;
36         $v = $default_rev if $v == 0;
37
38         print "load_last_svn_rev: $v\n";
39         return $v;
40 }
41
42 sub save_last_svn_rev($$)
43 {
44         my ($file, $rev) = @_;
45         util::FileSave($file, $rev);
46         print "save_last_svn_rev: $rev\n";
47 }
48
49 my $last_rev = $r->get_last_svn_rev($svn_branch);
50 my $start_rev = load_last_svn_rev($last_svn_rev_file, $svn_start_rev);
51 my $revs = $r->get_missing_svn_revs($svn_branch, $start_rev);
52
53 print "start: $start_rev last: $last_rev\n";
54
55 foreach my $rev (sort keys %{$revs}) {
56         print "Get patch for rev: $rev\n";
57         my $p = $r->get_git_patch($revs->{$rev}->{branch}, $rev);
58
59         if (defined($p->{git_patch})) {
60                 my $patch_path = "$patch_path/$rev.patch";
61                 open(PATCH, ">$patch_path") or
62                         die ("failed to $patch_path for write");
63                 print PATCH $p->{git_patch}."\n";
64                 close PATCH;
65
66                 my $applycmd = "cd $git_repo_path && git am --whitespace=nowarn --binary $patch_path";
67
68                 print "Apply $rev.patch\n";
69                 my $apply = `$applycmd` or die "$applycmd: failed";
70         }
71
72         save_last_svn_rev($last_svn_rev_file, $rev);
73 }
74