* [PATCH] contrib: git-cpcover: copy cover letter
@ 2019-10-13 11:50 Michael S. Tsirkin
0 siblings, 0 replies; only message in thread
From: Michael S. Tsirkin @ 2019-10-13 11:50 UTC (permalink / raw)
To: git
My flow looks like this:
1. git format-patch -v<n> --cover-letter <params> -o <dir>
2. vi <dir>/v<n-1>-0000-cover-letter.patch <dir>/v<n>-0000-cover-letter.patch
copy subject and blurb, avoiding patchset stats
3. add changelog update blurb as appropriate
4. git send-email <dir>/v<n>-*
The following perl script automates step 2 above. Hacked together
rather quickly, so I'm only proposing it for contrib for now. If others
see the need, we can add docs, tests and move it to git proper.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
contrib/git-cpcover | 80 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100755 contrib/git-cpcover
diff --git a/contrib/git-cpcover b/contrib/git-cpcover
new file mode 100755
index 0000000000..d80bd141ba
--- /dev/null
+++ b/contrib/git-cpcover
@@ -0,0 +1,80 @@
+#!/usr/bin/perl -i
+
+use strict;
+
+die "Usage: ${0} <from> [<to>]" unless $#ARGV == 0 or $#ARGV == 1;
+
+my $ffrom = shift @ARGV;
+my @extraheaders = ();
+
+open(FROM, "<", $ffrom) || die "Can not open $ffrom";
+
+my @from = ();
+while (<FROM>) {
+ push @from, $_;
+}
+
+close(FROM) || die "error closing $ffrom";
+
+#get subject
+my $subj;
+my $bodyi;
+for (my $i = 0; $i <= $#from; $i++) {
+ $_ = $from[$i];
+ #print STDERR "<$line>\n";
+ if (not defined ($subj) and s/^Subject: \[[^]]+\] //) {
+ $subj = $_;
+ chomp $subj;
+ }
+ if (m/^(To|Cc):/) {
+ push @extraheaders, $from[$i];
+ }
+ if (defined ($subj) and m/^$/) {
+ $bodyi = $i + 1;
+ last;
+ }
+}
+
+die "No subject found in $ffrom" unless defined($subj);
+
+die "No body found in $ffrom" unless defined($bodyi);
+
+my $bodyl;
+my $statb;
+my $state;
+for (my $i = $#from; $i >= $bodyi; $i--) {
+ $_ = $from[$i];
+ $statb = $i if m/ [0-9]+ files changed, [0-9]+ insertions\(\+\), [0-9]+ deletions\(-\)/;
+ next unless defined($statb);
+ $state = $i if m/^$/;
+ next unless defined($state);
+ next if m/^$/;
+ next if m/^ [^ ]/;
+ next if m/\([0-9]+\):$/;
+ $bodyl = $i;
+ last;
+}
+
+die "No body found in $ffrom" unless defined($bodyl);
+
+#print STDERR $bodyi, "-", $bodyl, "\n";
+my $blurb = join("", @from[$bodyi..$bodyl]);
+
+my $gotsubj = 0;
+my $gotblurb = 0;
+my $gotendofheaders = 0;
+while (<>) {
+ if (not $gotsubj and
+ s/\*\*\* SUBJECT HERE \*\*\*/$subj/) {
+ $gotsubj = 1;
+ }
+ if (not $gotblurb and
+ s/\*\*\* BLURB HERE \*\*\*/$blurb/) {
+ $gotblurb = 1;
+ }
+ if (not $gotendofheaders and m/^$/) {
+ print join("", @extraheaders);
+ $gotendofheaders = 1;
+ }
+ print $_;
+}
--
MST
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-13 11:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-13 11:50 [PATCH] contrib: git-cpcover: copy cover letter Michael S. Tsirkin
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).