* [PATCH] send-email: Ask if a patch should be sent twice
@ 2019-07-30 0:13 Dmitry Safonov
2019-07-30 11:54 ` Ævar Arnfjörð Bjarmason
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Safonov @ 2019-07-30 0:13 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason,
Dmitry Safonov, Dmitry Safonov, Andrei Vagin
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 linux-kernel@vger.kernel.org /tmp/timens/
--cc 'Dmitry Safonov <0x7f454c46@gmail.com>' /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.
link: https://lkml.kernel.org/r/4d53ebc7-d5b2-346e-c383-606401d19d3a@gmail.com
Cc: Andrei Vagin <avagin@openvz.org>
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
git-send-email.perl | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 5f92c89c1c1b..0caafc104478 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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;
--
2.22.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] send-email: Ask if a patch should be sent twice
2019-07-30 0:13 [PATCH] send-email: Ask if a patch should be sent twice Dmitry Safonov
@ 2019-07-30 11:54 ` Ævar Arnfjörð Bjarmason
2019-07-30 12:50 ` Dmitry Safonov
0 siblings, 1 reply; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2019-07-30 11:54 UTC (permalink / raw)
To: Dmitry Safonov; +Cc: git, Junio C Hamano, Dmitry Safonov, Andrei Vagin
On Tue, Jul 30 2019, Dmitry Safonov wrote:
> 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 linux-kernel@vger.kernel.org /tmp/timens/
> --cc 'Dmitry Safonov <0x7f454c46@gmail.com>' /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.
>
> link: https://lkml.kernel.org/r/4d53ebc7-d5b2-346e-c383-606401d19d3a@gmail.com
> Cc: Andrei Vagin <avagin@openvz.org>
> Signed-off-by: Dmitry Safonov <dima@arista.com>
> ---
> 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.
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 5f92c89c1c1b..0caafc104478 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -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.
> 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 "),
These cases with a default should have "Y/n", not "y/n". See other
expamples in the file.
> + 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...
> + }
> +}
> +
> # 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);
> + }
One non-smartmatch idiom for this is:
my %seen;
for my $file (@files) {
if ($seen{$file}++) { ...}
}
Or:
my %seen;
my @dupes = grep { $seen{$_}++ } @files;
> + }
> + 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.
> } else {
> push @rev_list_opts, $f;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] send-email: Ask if a patch should be sent twice
2019-07-30 11:54 ` Ævar Arnfjörð Bjarmason
@ 2019-07-30 12:50 ` Dmitry Safonov
0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Safonov @ 2019-07-30 12:50 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Junio C Hamano, Dmitry Safonov, Andrei Vagin
On 7/30/19 12:54 PM, Ævar Arnfjörð Bjarmason wrote:
>
> On Tue, Jul 30 2019, Dmitry Safonov wrote:
>
>> 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 linux-kernel@vger.kernel.org /tmp/timens/
>> --cc 'Dmitry Safonov <0x7f454c46@gmail.com>' /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.
>>
>> link: https://lkml.kernel.org/r/4d53ebc7-d5b2-346e-c383-606401d19d3a@gmail.com
>> Cc: Andrei Vagin <avagin@openvz.org>
>> Signed-off-by: Dmitry Safonov <dima@arista.com>
>> ---
>> 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.
I wasn't sure if that needs a test or some `--send-them-twice` option.
Decided to send it early.. Will add a test.
>
>> diff --git a/git-send-email.perl b/git-send-email.perl
>> index 5f92c89c1c1b..0caafc104478 100755
>> --- a/git-send-email.perl
>> +++ b/git-send-email.perl
>> @@ -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.
>
>> 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 "),
>
> These cases with a default should have "Y/n", not "y/n". See other
> expamples in the file.
Ok.
>
>> + 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...
>
>> + }
>> +}
>> +
>> # 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);
>> + }
>
> One non-smartmatch idiom for this is:
>
> my %seen;
> for my $file (@files) {
> if ($seen{$file}++) { ...}
> }
>
> Or:
>
> my %seen;
> my @dupes = grep { $seen{$_}++ } @files;
>
>> + }
>> + 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.
> 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.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-30 12:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30 0:13 [PATCH] send-email: Ask if a patch should be sent twice Dmitry Safonov
2019-07-30 11:54 ` Ævar Arnfjörð Bjarmason
2019-07-30 12:50 ` Dmitry Safonov
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).