Preparing for release of 3.0.0pre8
[rsync.git] / support / patch-update
blob7c51e9c24035ecaf6e4d4ffefb38457ec8b82a59
1 #!/usr/bin/perl -w
2 # This script is used to turn one or more of the "patch/*" branches
3 # into one or more diffs in the "patches" directory. Pass the option
4 # --gen if you want generated files in the diffs. Pass the name of
5 # one or more diffs if you want to just update a subset of all the
6 # diffs.
8 use strict;
10 my $patches_dir = 'patches';
11 my $incl_generated_files;
13 if (@ARGV && $ARGV[0] =~ /^--gen(?:=(\S+))?$/) {
14 $patches_dir = $1 if defined $1;
15 $incl_generated_files = 1;
16 shift;
19 die "No '$patches_dir' directory was found.\n" unless -d $patches_dir;
20 die "No '.git' directory present in the current dir.\n" unless -d '.git';
22 my @extra_files;
23 open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
24 while (<IN>) {
25 if (s/^GENFILES=//) {
26 while (s/\\$//) {
27 $_ .= <IN>;
29 @extra_files = split(' ', $_);
30 last;
33 close IN;
35 system "git checkout master" and exit 1;
36 if ($incl_generated_files) {
37 die "'a' must not exist in the current directory.\n" if -e 'a';
38 die "'b' must not exist in the current directory.\n" if -e 'b';
39 system "./config.status Makefile && make gen && rsync -a @extra_files a/" and exit 1;
41 my $last_touch = time;
43 my(@patches, %local_patch);
44 if (@ARGV) {
45 foreach (@ARGV) {
46 s{^(patches|patch|origin/patch)/} {};
47 s{\.diff$} {};
48 push(@patches, $_);
50 open(PIPE, '-|', 'git', 'branch', '-l') or die $!;
51 } else {
52 open(PIPE, '-|', 'git', 'branch', '-a') or die $!;
54 while (<PIPE>) {
55 if (m# origin/patch/(.*)#) {
56 push(@patches, $1);
57 } elsif (m# patch/(.*)#) {
58 $local_patch{$1} = 1;
61 close PIPE;
63 my(%parent, %description);
64 foreach my $patch (@patches) {
65 my $branch = ($local_patch{$patch} ? '' : 'origin/') . "patch/$patch";
66 my $desc = '';
67 open(PIPE, '-|', 'git', 'diff', '-U1000', "master...$branch", '--', "PATCH.$patch") or die $!;
68 while (<PIPE>) {
69 last if /^@@ /;
71 while (<PIPE>) {
72 next unless s/^[ +]//;
73 if (m#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) {
74 $parent{$patch} = $1;
76 $desc .= $_;
78 $description{$patch} = $desc;
81 my %completed;
82 foreach my $patch (@patches) {
83 next if $completed{$patch}++;
84 update_patch($patch);
87 if ($incl_generated_files) {
88 system "rm -rf a b";
91 sleep 1 if $last_touch == time;
92 system "git checkout master";
94 exit;
97 sub update_patch
99 my($patch) = @_;
101 my $parent = $parent{$patch};
102 if (defined $parent) {
103 unless ($completed{$parent}++) {
104 update_patch($parent);
106 $parent = "patch/$parent";
107 } else {
108 $parent = 'master';
111 print "======== $patch ========\n";
113 sleep 1 if $incl_generated_files && $last_touch == time;
114 if ($local_patch{$patch}) {
115 system "git checkout patch/$patch" and exit 1;
116 } else {
117 system "git checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
120 open(OUT, '>', "$patches_dir/$patch.diff") or die $!;
121 print OUT $description{$patch}, "\n";
123 if (system("git rebase -m $parent") != 0) {
124 print qq|"git rebase -m $parent" incomplete -- please fix.\n|;
125 $ENV{PS1} = "[$parent] patch/$patch: ";
126 system $ENV{SHELL} and exit 1;
129 if ($incl_generated_files) {
130 system "./config.status Makefile && make gen && rsync -a @extra_files b/" and exit 1;
132 $last_touch = time;
134 open(PIPE, '-|', 'git', 'diff', $parent) or die $!;
135 DIFF: while (<PIPE>) {
136 while (m{^diff --git a/PATCH}) {
137 while (<PIPE>) {
138 last if m{^diff --git a/};
140 last DIFF if !defined $_;
142 next if /^index /;
143 print OUT $_;
145 close PIPE;
147 if ($incl_generated_files) {
148 open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!;
149 while (<PIPE>) {
150 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;
151 print OUT $_;
153 close PIPE;
156 close OUT;