+my(%parent, %description);
+foreach my $patch (@patches) {
+ my $branch = ($local_patch{$patch} ? '' : 'origin/') . "patch/$patch";
+ my $desc = '';
+ open(PIPE, '-|', 'git', 'diff', '-U1000', "master...$branch", '--', "PATCH.$patch") or die $!;
+ while (<PIPE>) {
+ last if /^@@ /;
+ }
+ while (<PIPE>) {
+ next unless s/^[ +]//;
+ if (m#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) {
+ $parent{$patch} = $1;
+ }
+ $desc .= $_;
+ }
+ $description{$patch} = $desc;
+}
+
+if (@ARGV) {
+ # Limit the list of patches to actually process based on @ARGV.
+ @patches = ( );
+ foreach (@ARGV) {
+ s{^(patches|patch|origin/patch)/} {};
+ s{\.diff$} {};
+ push(@patches, $_);
+ }
+}
+
+my %completed;