If we start a sub-shell to let the user fix a rebase, output a
[rsync/rsync.git] / support / patch-update
... / ...
CommitLineData
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.
7
8use strict;
9
10die "No 'patches' directory present in the current dir.\n" unless -d 'patches';
11die "No '.git' directory present in the current dir.\n" unless -d '.git';
12
13open(IN, '<', 'prepare-source.mak') or die "Couldn't open prepare-source.mak: $!\n";
14$_ = join('', <IN>);
15close IN;
16
17my @extra_files = m{\n([^\s:]+):.*\n\t\S}g;
18my $incl_generated_files;
19
20$incl_generated_files = shift if @ARGV && $ARGV[0] eq '--gen';
21
22system "git-checkout master" and exit 1;
23
24if ($incl_generated_files) {
25 die "'a' already exists.\n" if -e 'a';
26 die "'b' already exists.\n" if -e 'b';
27 system "./prepare-source && rsync -a @extra_files a/" and exit 1;
28}
29
30my(@patches, %local_patch);
31if (@ARGV) {
32 foreach (@ARGV) {
33 s{^(patches|patch|origin/patch)/} {};
34 s{\.diff$} {};
35 push(@patches, $_);
36 }
37 open(PIPE, '-|', 'git-branch', '-l') or die $!;
38} else {
39 open(PIPE, '-|', 'git-branch', '-a') or die $!;
40}
41while (<PIPE>) {
42 if (m# origin/patch/(.*)#) {
43 push(@patches, $1);
44 } elsif (m# patch/(.*)#) {
45 $local_patch{$1} = 1;
46 }
47}
48close PIPE;
49
50foreach my $patch (@patches) {
51 print "======== $patch ========\n";
52 if ($local_patch{$patch}) {
53 system "git-checkout patch/$patch" and exit 1;
54 } else {
55 system "git-checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
56 }
57 my $parent = 'master';
58 open(IN, '<', 'PATCH') or next;
59 open(OUT, '>', "patches/$patch.diff") or die $!;
60
61 while (<IN>) {
62 if (m#patch -p1 <patch/(\S+)\.diff# && $1 ne $patch) {
63 $parent = $1;
64 }
65 print OUT $_;
66 }
67 close IN;
68 print OUT "\n";
69
70 if (system("git-rebase -m $parent") != 0) {
71 print qq|"git-rebase -m $parent" incomplete -- please fix.\n|;
72 $ENV{PS1} = "[$parent] patch/$patch: ";
73 system $ENV{SHELL};
74 }
75
76 open(PIPE, '-|', 'git-diff', 'master') or die $!;
77 while (<PIPE>) {
78 last if m{^diff --git a/PATCH b/PATCH$};
79 print OUT $_;
80 }
81 while (<PIPE>) {
82 last if m{^diff --git a/};
83 }
84 print OUT $_, <PIPE>;
85 close PIPE;
86
87 if ($incl_generated_files) {
88 system "./prepare-source && rsync -a @extra_files b/" and exit 1;
89 open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!;
90 while (<PIPE>) {
91 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;
92 print OUT $_;
93 }
94 close PIPE;
95 }
96
97 close OUT;
98}
99
100if ($incl_generated_files) {
101 system "rm -rf a b";
102}
103
104print "-------- master --------\n";
105system "git-checkout master && ./prepare-source";