send-email: Ask if a patch should be sent twice
PATCH 1/1 send-email: Ask if a patch should be sent twice
I was almost certain that git won't let me send the same patch twice, but today I've managed to double-send a directory by a mistake:
git send-email --to [email protected] /tmp/timens/ --cc 'Dmitry Safonov <[email protected]>' /tmp/timens/`
[I haven't noticed that I put the directory twice ^^]
Prevent this shipwreck from happening again by asking if a patch is sent multiple times on purpose.
--- git-send-email.perl | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
git-send-email.perl +22 -1
@@ -33,6 +33,7 @@ use Net::Domain (); use Net::SMTP (); use Git::LoadCPAN::Mail::Address; +use experimental 'smartmatch'; Getopt::Long::Configure qw/ pass_through /;
@@ -658,6 +659,17 @@ sub is_format_patch_arg { } } +sub send_file_twice { + my $f = shift; + $_ = ask(__("Patch $f will be sent twice, continue? [y]/n "), + default => "y", + valid_re => qr/^(?:yes|y|no|n)/i); + if (/^n/i) { + cleanup_compose_files(); + exit(0); + } +} + # Now that all the defaults are set, process the rest of the command line # arguments and collect up the files that need to be processed. my @rev_list_opts;
@@ -669,10 +681,19 @@ sub is_format_patch_arg { opendir my $dh, $f or die sprintf(__("Failed to opendir %s: %s"), $f, $!); - push @files, grep { -f $_ } map { catfile($f, $_) } + my @new_files = grep { -f $_ } map { catfile($f, $_) } sort readdir $dh; + foreach my $nfile (@new_files) { + if ($nfile ~~ @files) { + send_file_twice($nfile); + } + } + push @files, @new_files; closedir $dh; } elsif ((-f $f or -p $f) and !is_format_patch_arg($f)) { + if ($f ~~ @files) { + send_file_twice($f); + } push @files, $f; } else { push @rev_list_opts, $f;
Signature · 1 line
2.22.0
Quoted 10 lines · Dmitry Safonov
I was almost certain that git won't let me send the same patch twice, but today I've managed to double-send a directory by a mistake:
git send-email --to [email protected] /tmp/timens/ --cc 'Dmitry Safonov <[email protected]>' /tmp/timens/`[I haven't noticed that I put the directory twice ^^]
Prevent this shipwreck from happening again by asking if a patch is sent multiple times on purpose.
Quoted 6 lines
Cc Andrei Vagin <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- git-send-email.perl | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
There's tests for send-email in t/t9001-send-email.sh. See if what you're adding can have a test added, seems simple enough in this case.
git-send-email.perl line 36
Quoted 9 lines
git-send-email.perl +1
-0@@ -33,6 +33,7 @@ use Net::Domain (); use Net::SMTP (); use Git::LoadCPAN::Mail::Address; +use experimental 'smartmatch';
We depend on Perl 5.8, this bumps the requirenment to 5.10. Aside from that ~~ is its own can of worms in Perl and is best avoided.
git-send-email.perl sub is_format_patch_arg { · line 664
Quoted 9 lines
git-send-email.perl +3
-0Getopt::Long::Configure qw/ pass_through /;@@ -658,6 +659,17 @@ sub is_format_patch_arg { } } +sub send_file_twice { + my $f = shift; + $_ = ask(__("Patch $f will be sent twice, continue? [y]/n "),
These cases with a default should have "Y/n", not "y/n". See other expamples in the file.
git-send-email.perl sub is_format_patch_arg { · line 669
Quoted 5 lines
git-send-email.perl +5
-0+ default => "y", + valid_re => qr/^(?:yes|y|no|n)/i); + if (/^n/i) { + cleanup_compose_files(); + exit(0);
Exit if we have just one of these? More on that later...
Quoted 7 lines
git-send-email.perl +3
-0+ } +} + # Now that all the defaults are set, process the rest of the command line # arguments and collect up the files that need to be processed. my @rev_list_opts;
git-send-email.perl sub is_format_patch_arg { · line 689
Quoted 10 lines
git-send-email.perl +5
-1@@ -669,10 +681,19 @@ sub is_format_patch_arg { opendir my $dh, $f or die sprintf(__("Failed to opendir %s: %s"), $f, $!); - push @files, grep { -f $_ } map { catfile($f, $_) } + my @new_files = grep { -f $_ } map { catfile($f, $_) } sort readdir $dh; + foreach my $nfile (@new_files) { + if ($nfile ~~ @files) { + send_file_twice($nfile); + }
One non-smartmatch idiom for this is:
my %seen;
for my $file (@files) {
if ($seen{$file}++) { ...}
}Or:
my %seen;
my @dupes = grep { $seen{$_}++ } @files;git-send-email.perl sub is_format_patch_arg { · line 697
Quoted 8 lines
git-send-email.perl +5
-0+ } + push @files, @new_files; closedir $dh; } elsif ((-f $f or -p $f) and !is_format_patch_arg($f)) { + if ($f ~~ @files) { + send_file_twice($f); + } push @files, $f;
...but picking up the comment above, I'd expect this to be in the "if ($validate)" block below or something similar, seems like this fits right in with --validate.
Then you can also ask "do you want to send this set of patches twice <full list>?".
Now the user is asked a file-at-a-time.
Quoted 2 lines
git-send-email.perl +0
-0} else { push @rev_list_opts, $f;
Quoted 20 lines · Ævar Arnfjörð Bjarmason
Quoted 10 lines · Dmitry Safonov
I was almost certain that git won't let me send the same patch twice, but today I've managed to double-send a directory by a mistake:
git send-email --to [email protected] /tmp/timens/ --cc 'Dmitry Safonov <[email protected]>' /tmp/timens/`[I haven't noticed that I put the directory twice ^^]
Prevent this shipwreck from happening again by asking if a patch is sent multiple times on purpose.
Quoted 6 lines
Cc Andrei Vagin <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- git-send-email.perl | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
Quoted 2 lines
There's tests for send-email in
t/t9001-send-email.sh. See if what you're adding can have a test added, seems simple enough in this case.
I wasn't sure if that needs a test or some --send-them-twice option. Decided to send it early.. Will add a test.
Quoted 13 lines
git-send-email.perl line 36
Quoted 10 lines
git-send-email.perl +1
-0@@ -33,6 +33,7 @@ use Net::Domain (); use Net::SMTP (); use Git::LoadCPAN::Mail::Address; +use experimental 'smartmatch';We depend on Perl 5.8, this bumps the requirenment to 5.10. Aside from that ~~ is its own can of worms in Perl and is best avoided.
Yeah, I'm not very into Perl and Stackoverflow *blush* suggested to use ~~. Will drop.
Quoted 7 lines
Quoted 7 lines
git-send-email.perl +0
-0Getopt::Long::Configure qw/ pass_through /;@@ -658,6 +659,17 @@ sub is_format_patch_arg { } }
Quoted 6 lines
git-send-email.perl sub is_format_patch_arg { · line 664
Quoted 3 lines
git-send-email.perl +3
-0+sub send_file_twice { + my $f = shift; + $_ = ask(__("Patch $f will be sent twice, continue? [y]/n "),These cases with a default should have "Y/n", not "y/n". See other expamples in the file.
Ok.
Quoted 39 lines
git-send-email.perl sub is_format_patch_arg { · line 669
Quoted 6 lines
git-send-email.perl +5
-0+ default => "y", + valid_re => qr/^(?:yes|y|no|n)/i); + if (/^n/i) { + cleanup_compose_files(); + exit(0);Exit if we have just one of these? More on that later...
Quoted 7 lines
git-send-email.perl +3
-0+ } +} + # Now that all the defaults are set, process the rest of the command line # arguments and collect up the files that need to be processed. my @rev_list_opts;git-send-email.perl sub is_format_patch_arg { · line 689
Quoted 10 lines
git-send-email.perl +5
-1@@ -669,10 +681,19 @@ sub is_format_patch_arg { opendir my $dh, $f or die sprintf(__("Failed to opendir %s: %s"), $f, $!); - push @files, grep { -f $_ } map { catfile($f, $_) } + my @new_files = grep { -f $_ } map { catfile($f, $_) } sort readdir $dh; + foreach my $nfile (@new_files) { + if ($nfile ~~ @files) { + send_file_twice($nfile); + }One non-smartmatch idiom for this is:
my %seen; for my $file (@files) { if ($seen{$file}++) { ...} }Or:
my %seen; my @dupes = grep { $seen{$_}++ } @files;
Quoted 12 lines
git-send-email.perl sub is_format_patch_arg { · line 697
Quoted 8 lines
git-send-email.perl +5
-0+ } + push @files, @new_files; closedir $dh; } elsif ((-f $f or -p $f) and !is_format_patch_arg($f)) { + if ($f ~~ @files) { + send_file_twice($f); + } push @files, $f;...but picking up the comment above, I'd expect this to be in the "if ($validate)" block below or something similar, seems like this fits right in with --validate.
By default it's on - sounds good to me.
Quoted 4 lines
Then you can also ask "do you want to send this set of patches twice <full list>?".
Now the user is asked a file-at-a-time.
Ok, thanks for the suggestions.
Signature · 1 line
Dmitry