git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: git-send-email: Send with mutt(1)
Date: Tue, 7 Nov 2023 19:36:44 +0100	[thread overview]
Message-ID: <ZUqDwnmu9d1dD1tb@devuan> (raw)
In-Reply-To: <20231107174803.GA507007@coredump.intra.peff.net>

[-- Attachment #1: Type: text/plain, Size: 3961 bytes --]

Hi Jeff,

On Tue, Nov 07, 2023 at 12:48:03PM -0500, Jeff King wrote:
> I think there's a lot of overlap between what git-send-email does and
> what mutt does, to the point that you probably don't need to use
> send-email at all.
> 
> I assume what you want out of send-email here is the actual generation
> of patch emails. But under the hood that is all done by git-format-patch
> anyway. So for example if you do:

Yeah, most of it is done by format-patch.  There are few things I
actually need from send-email.  One of them is generating the Cc from
the sign-offs and other tags found in the patch.

I had been thinking these days that it would be useful to have
format-patch generate those.  How about adding a --signed-off-by-cc to
format-patch?

> 
>   git format-patch --stdout origin..HEAD >patches
>   mutt -f patches
> 
> And then you can use mutt's "resend-message" function to send each one.
> I use config like this:
> 
>   macro index,pager b ":set edit_headers=yes<enter><resend-message>:set edit_headers=no<enter>"
> 
> If you're sending a long series, it's helpful to pre-populate various
> headers in the format-patch command with "--to", etc. I usually do so by
> sending the cover letter directly via mutt, and then using some perl
> hackery to convert those headers into format-patch args. The script I

Indeed, that hackery is what send-email already does, so how about
moving those features a bit upstream so that format-patch can do them
too?

Although then, maybe it's simpler to teach send-email to learn to use
mutt(1) under the hood for the actual send.

> use is below (it will also, when run without a terminal, generate the
> patch summary for the cover letter; I use it with "r!my-script" while
> writing the cover letter in vim).
> 
> (This script is what I use every day, so it should be fairly robust. But
> it is also over 15 years old, so I don't promise there isn't a simpler
> way to do some of what it does ;) ).
> 
> -- >8 --
> #!/bin/sh
> upstream_branch() {
>   current=`git symbolic-ref HEAD`
>   upstream=`git for-each-ref --format='%(upstream)' "$current"`
>   if test -n "$upstream"; then
>     echo $upstream
>   else
>     echo origin
>   fi
> }
> 
> get_reply_headers() {
>   perl -ne '
>     if (defined $opt) {
>       if (/^\s+(.*)/) {
>         $val .= " $1";
>         next;
>       }
>       print "--$opt=", quotemeta($val), " ";
>       $opt = $val = undef;
>     }
>     if (/^(cc|to):\s*(.*)/i) {
>       $opt = lc($1);
>       $val = $2;
>     }
>     elsif (/^message-id:\s*(.*)/i) {
>       $opt = "in-reply-to";
>       $val = $1;
>     }
>     elsif (/^subject:\s*\[PATCH v(\d+)/i) {
>       print "-v$1 ";
>     }
>     elsif (/^$/) {
>       last;
>     }
>   '
> }
> 
> format_patch() {
>   git format-patch -s --stdout --from "$@"
> }
> 
> has_nonoption=
> for i in "$@"; do
>   case "$i" in
>     -[0-9]*) has_nonoption=yes ;;
>     -*) ;;
>      *) has_nonoption=yes
>   esac
> done
> 
> : ${REPLY:=$HOME/patch}
> test -e "$REPLY" && eval "set -- `get_reply_headers <\"$REPLY\"` \"\$@\""
> test "$has_nonoption" = "yes" || set -- "$@" `upstream_branch`
> 
> if test -t 1; then
>   format_patch "$@" >.mbox
>   mutt -e 'set sort=mailbox-order' -f .mbox
>   rm -f .mbox
> else
>   format_patch "$@" |
>   perl -lne '
>     if (/^Subject: (.*)/) {
>       $subject = $1;
>     }
>     elsif ($subject && /^\s+(.*)/) {
>       $subject .= " $1";
>     }
>     elsif ($subject) {
>       print $subject;
>       $subject = undef;
>     }
>   ' |
>   sed -e 's/\[PATCH /[/' \
>       -e 's/]/]:/' \
>       -e 's/^/  /'
>   echo
>   format_patch --cover-letter "$@" |
>   sed -ne '/|/,/^$/p; /^-- /q'
> fi

Thanks!  I'll try it.  Although I don't know perl, so I hope I don't
need to tweak it much.  :)

Cheers,
Alex

-- 
<https://www.alejandro-colomar.es/>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-11-07 18:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 11:14 git-send-email: Send with mutt(1) Alejandro Colomar
2023-11-07 17:48 ` Jeff King
2023-11-07 18:36   ` Alejandro Colomar [this message]
2023-11-07 20:16     ` Jeff King
2023-11-08 21:02       ` Alejandro Colomar
2023-11-08 21:27         ` Jeff King
2023-11-09 15:26           ` Alejandro Colomar
2023-11-09 16:08             ` Konstantin Ryabitsev
2023-11-09 17:42               ` Alejandro Colomar
2023-11-09 17:59                 ` Konstantin Ryabitsev
2023-11-10 21:06                   ` Alejandro Colomar
2023-11-09 18:03             ` Jeff King
2023-11-09 23:00               ` Alejandro Colomar
2023-11-10  0:51               ` Alejandro Colomar
2023-11-10 13:30                 ` Alejandro Colomar
2023-11-10 21:41                   ` Jeff King
2023-11-10 23:31                   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZUqDwnmu9d1dD1tb@devuan \
    --to=alx@kernel.org \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).