summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--notmuch-extract-patch.1.pod31
-rwxr-xr-xnotmuch-extract-patch/notmuch-extract-patch24
2 files changed, 43 insertions, 12 deletions
diff --git a/notmuch-extract-patch.1.pod b/notmuch-extract-patch.1.pod
index 21095bc..a18cc22 100644
--- a/notmuch-extract-patch.1.pod
+++ b/notmuch-extract-patch.1.pod
@@ -4,7 +4,7 @@ notmuch-extract-patch - extract a git patch series from notmuch
=head1 SYNOPSIS
-B<notmuch-extract-patch> I<QUERY>
+B<notmuch-extract-patch> [B<-v>|B<--reroll-count=>I<N>] I<QUERY>
=head1 DESCRIPTION
@@ -15,7 +15,23 @@ replies/reviews.
=head1 OPTIONS
-None.
+=over 4
+
+=item B<-v>|B<--reroll-count=>I<N>
+
+Try to extract the I<N>th version of a patch series, where these
+patches are identified by subject prefixes like "[PATCH vI<N> 1/3]".
+
+If this option is not specified, default to extracting the first
+version of the patch series.
+
+Note that this option should not usually be needed, because best
+practices when sharing patches with git-send-email(1) include starting
+a new thread when posting a revised series. The I<--in-reply-to>
+option to git-format-patch(1) is used mainly for posting a patch
+series in reply to a bug report.
+
+=back
=head1 EXAMPLE
@@ -28,17 +44,12 @@ None.
=head1 LIMITATIONS
-B<notmuch-extract-patch> assumes one patch series per query. So if
-there is more than one patch series in a thread, you will need to
+B<notmuch-extract-patch> can select patches to extract based on the
+reroll count, but otherwise assumes that there is only one patch
+series in a thread. If this assumption is violated, you would need to
construct a notmuch query that includes only the patches you want to
extract, which somewhat defeats the purpose of this script.
-This should not happen often because best practices when sharing
-patches with git-send-email(1) include starting a new thread when
-posting a revised series. The I<--in-reply-to> option to
-B<notmuch-extract-patch> is used mainly for posting a patch series in
-reply to a bug report.
-
=head1 SEE ALSO
notmuch(1), git-send-email(1)
diff --git a/notmuch-extract-patch/notmuch-extract-patch b/notmuch-extract-patch/notmuch-extract-patch
index cfd4464..4cfda4c 100755
--- a/notmuch-extract-patch/notmuch-extract-patch
+++ b/notmuch-extract-patch/notmuch-extract-patch
@@ -22,6 +22,7 @@ import sys
import tempfile
import subprocess
import re
+import getopt
def get_body(message):
body = None
@@ -48,8 +49,27 @@ def is_git_patch(msg):
# return ("git-send-email" in msg['x-mailer'] and match)
return match
+def has_reroll_count(msg, v):
+ subject_prefix = get_subject_prefix(msg['subject'])
+ if subject_prefix is not None:
+ return "v"+str(v) in subject_prefix \
+ or (v == 1 and not any(entry[0] == 'v' for entry in subject_prefix))
+
+def get_subject_prefix(s):
+ match = re.search(r'''^\[(.*PATCH.*)\]''', s)
+ if match:
+ return match.group(1).split()
+
def main():
- query = sys.argv[1:]
+ try:
+ opts, query = getopt.getopt(sys.argv[1:], "v:", ["reroll-count="])
+ except getopt.GetoptError as err:
+ sys.stderr.write(str(err)+"\n")
+ sys.exit(2)
+ reroll_count = 1
+ for o, a in opts:
+ if o in ("-v", "--reroll-count"):
+ reroll_count = int(a)
with tempfile.NamedTemporaryFile() as in_mb_file:
out = subprocess.check_output(['notmuch', 'show', '--format=mbox']+query)
in_mb_file.write(out)
@@ -59,7 +79,7 @@ def main():
with tempfile.NamedTemporaryFile() as out_mb_file:
out_mb = mailbox.mbox(out_mb_file.name)
for m in in_mb:
- if is_git_patch(m):
+ if is_git_patch(m) and has_reroll_count(m, reroll_count):
sys.stderr.write(m['subject']+"\n")
out_mb.add(m)
out_mb.flush()