+my(%patches, %local_patch);
+
+# Start by finding all patches so that we can load all possible parents.
+open(PIPE, '-|', 'git', 'branch', '-a') or die $!;
+while (<PIPE>) {
+ if (m# origin/patch/(.*)#) {
+ $patches{$1} = 1;
+ } elsif (m# patch/(.*)#) {
+ $patches{$1} = $local_patch{$1} = 1;
+ }
+}
+close PIPE;
+
+my @patches = sort keys %patches;
+
+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;
+}
+