Re: [PATCHv3] send-email: Ask if a patch should be sent twice
Hi Junio, On 7/30/19 11:13 PM, Junio C Hamano wrote: > Dmitry Safonov writes: > >> I was almost certain that git won't let me send the same patch twice, > > Why? And more importantly, does it matter to readers of this > message what you thought? I see the point of putting description in impersonal, technical way. Probably, was irritated after sending 50 patches instead of 37. Also I've seen that in `git log | grep ' I '` over the project, not that it justifies using it in the discussed patch. > >> but today I've managed to double-send a directory by a mistake: >> git send-email --to linux-ker...@vger.kernel.org /tmp/timens/ >> --cc 'Dmitry Safonov <0x7f454...@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-606401d19...@gmail.com > > What does "link:" mean? It's a tag, usually used to point URL for more information. Maybe not that common in git-ml, but often it shows an example of what can go wrong without a patch. > >> Cc: Andrei Vagin > > What's the significance for this project to record that this patch > was CCed to Andrei? I've felt like I need to give credit to my friend with whom I was working on the patches set; which I've failed to send properly. Maybe it's a thing of more opensource-friendly communities like lkml. > >> Suggested-by: Ævar Arnfjörð Bjarmason > > I think "Helped-by:" is a lot more appropriate, viewing the exchange > on v2 from the sideline. > >> Signed-off-by: Dmitry Safonov To be honest, I don't feel like going on with v5. I've underestimate how welcoming some communities are to foreign patches. If you feel like it's still worth to have the feature, please carry-on with the tag Abandoned-by: Dmitry Safonov and don't drop Cc tag. [..] Thanks and sorry for waisted time, Dmitry
[PATCHv4] 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 linux-ker...@vger.kernel.org /tmp/timens/ --cc 'Dmitry Safonov <0x7f454...@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-606401d19...@gmail.com Cc: Andrei Vagin Suggested-by: Ævar Arnfjörð Bjarmason Signed-off-by: Dmitry Safonov --- v4: Don't fail the test with GIT_TEST_GETTEXT_POISON=true v3: Use `test_i18ngrep` instead of plain `grep` v2: Moved the check under --validate, fixed tests, added a new test, updated documentation for --validate Documentation/git-send-email.txt | 2 ++ git-send-email.perl | 14 ++ t/t9001-send-email.sh| 15 +++ 3 files changed, 31 insertions(+) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index d93e5d0f58f0..0441bb1b5d3b 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -421,6 +421,8 @@ have been specified, in which case default to 'compose'. ('auto', 'base64', or 'quoted-printable') is used; this is due to SMTP limits as described by http://www.ietf.org/rfc/rfc5322.txt. + * Ask confirmation before sending patches multiple times + if the supplied patches set overlaps. -- + Default is the value of `sendemail.validate`; if this is not set, diff --git a/git-send-email.perl b/git-send-email.perl index 5f92c89c1c1b..c1638d06f81d 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -688,6 +688,9 @@ sub is_format_patch_arg { @files = handle_backup_files(@files); if ($validate) { + my %seen; + my @dupes = grep { $seen{$_}++ } @files; + foreach my $f (@files) { unless (-p $f) { my $error = validate_patch($f, $target_xfer_encoding); @@ -695,6 +698,17 @@ sub is_format_patch_arg { $f, $error); } } + if (@dupes) { + printf(__("Patches specified several times: \n")); + printf(__("%s \n" x @dupes), @dupes); + $_ = ask(__("Do you want to send those patches several times? Y/n "), + default => "y", + valid_re => qr/^(?:yes|y|no|n)/i); + if (/^n/i) { + cleanup_compose_files(); + exit(0); + } + } } if (@files) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 997f90b42b3e..8954f8e38d90 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -555,6 +555,7 @@ test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' --no-chain-reply-to \ --in-reply-to="$(cat expect)" \ --smtp-server="$(pwd)/fake.sendmail" \ + --no-validate \ $patches $patches $patches \ 2>errors && # The first message is a reply to --in-reply-to @@ -577,6 +578,7 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' --chain-reply-to \ --in-reply-to="$(cat expect)" \ --smtp-server="$(pwd)/fake.sendmail" \ + --no-validate \ $patches $patches $patches \ 2>errors && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && @@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' test_cmp expect actual ' +test_expect_success $PREREQ 'ask confirmation for double-send' ' + clean_fake_sendmail && + echo y | \ + GIT_SEND_EMAIL_NOTTY=1 \ + git send-email --from=aut...@example.com \ + --to=nob...@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + $patches $patches $patches \ + >stdout && + test_i18ngrep ! "Patches specified several times: " stdout +' + test_expect_success $PREREQ 'setup fake editor' ' write_script fake-editor <<-\EOF echo fake edit >>"$1" -- 2.22.0
Re: [PATCHv3] send-email: Ask if a patch should be sent twice
On 7/30/19 10:10 PM, SZEDER Gábor wrote: > On Tue, Jul 30, 2019 at 09:33:27PM +0100, Dmitry Safonov wrote: >> @@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with >> --chain-reply-to' ' >> test_cmp expect actual >> ' >> >> +test_expect_success $PREREQ 'ask confirmation for double-send' ' >> +clean_fake_sendmail && >> +echo y | \ >> +GIT_SEND_EMAIL_NOTTY=1 \ >> +git send-email --from=aut...@example.com \ >> +--to=nob...@example.com \ >> +--smtp-server="$(pwd)/fake.sendmail" \ >> +--validate \ >> +$patches $patches $patches \ >> +>stdout && >> +! test_i18ngrep "Patches specified several times: " stdout > > You should write this as 'test_i18ngrep ! <...>'. When running the > test with GIT_TEST_GETTEXT_POISON=true, then 'test_i18ngrep' is > basically a noop and always returns with success, the leading ! would > turn that into a failure, which then would fail the test. > > Sorry for not being specific enough. No worries, thanks for the review anyway, quite educative - I haven't worked much on i18-related things in other projects, so sorry for not getting it straight away. Will resend shortly.. Thanks, Dmtiry
[PATCHv3] 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 linux-ker...@vger.kernel.org /tmp/timens/ --cc 'Dmitry Safonov <0x7f454...@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-606401d19...@gmail.com Cc: Andrei Vagin Suggested-by: Ævar Arnfjörð Bjarmason Signed-off-by: Dmitry Safonov --- v3: Use `test_i18ngrep` instead of plain `grep` v2: Moved the check under --validate, fixed tests, added a new test, updated documentation for --validate Documentation/git-send-email.txt | 2 ++ git-send-email.perl | 14 ++ t/t9001-send-email.sh| 15 +++ 3 files changed, 31 insertions(+) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index d93e5d0f58f0..0441bb1b5d3b 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -421,6 +421,8 @@ have been specified, in which case default to 'compose'. ('auto', 'base64', or 'quoted-printable') is used; this is due to SMTP limits as described by http://www.ietf.org/rfc/rfc5322.txt. + * Ask confirmation before sending patches multiple times + if the supplied patches set overlaps. -- + Default is the value of `sendemail.validate`; if this is not set, diff --git a/git-send-email.perl b/git-send-email.perl index 5f92c89c1c1b..c1638d06f81d 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -688,6 +688,9 @@ sub is_format_patch_arg { @files = handle_backup_files(@files); if ($validate) { + my %seen; + my @dupes = grep { $seen{$_}++ } @files; + foreach my $f (@files) { unless (-p $f) { my $error = validate_patch($f, $target_xfer_encoding); @@ -695,6 +698,17 @@ sub is_format_patch_arg { $f, $error); } } + if (@dupes) { + printf(__("Patches specified several times: \n")); + printf(__("%s \n" x @dupes), @dupes); + $_ = ask(__("Do you want to send those patches several times? Y/n "), + default => "y", + valid_re => qr/^(?:yes|y|no|n)/i); + if (/^n/i) { + cleanup_compose_files(); + exit(0); + } + } } if (@files) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 997f90b42b3e..496005af1763 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -555,6 +555,7 @@ test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' --no-chain-reply-to \ --in-reply-to="$(cat expect)" \ --smtp-server="$(pwd)/fake.sendmail" \ + --no-validate \ $patches $patches $patches \ 2>errors && # The first message is a reply to --in-reply-to @@ -577,6 +578,7 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' --chain-reply-to \ --in-reply-to="$(cat expect)" \ --smtp-server="$(pwd)/fake.sendmail" \ + --no-validate \ $patches $patches $patches \ 2>errors && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && @@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' test_cmp expect actual ' +test_expect_success $PREREQ 'ask confirmation for double-send' ' + clean_fake_sendmail && + echo y | \ + GIT_SEND_EMAIL_NOTTY=1 \ + git send-email --from=aut...@example.com \ + --to=nob...@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + $patches $patches $patches \ + >stdout && + ! test_i18ngrep "Patches specified several times: " stdout +' + test_expect_success $PREREQ 'setup fake editor' ' write_script fake-editor <<-\EOF echo fake edit >>"$1" -- 2.22.0
Re: [PATCHv2] send-email: Ask if a patch should be sent twice
On 7/30/19 8:35 PM, Junio C Hamano wrote: > SZEDER Gábor writes: > >> On Tue, Jul 30, 2019 at 05:26:24PM +0100, Dmitry Safonov wrote: >>> + if (@dupes) { >>> + printf(__("Patches specified several times: \n")); >> >> Is this message translated? (I don't know what __("") does in >> Perl.) If it is, then ... > > That's not "in Perl" per-se, but what our own Git::I18N gives us. > >>> +test_expect_success $PREREQ 'ask confirmation for double-send' ' >>> + clean_fake_sendmail && >>> + echo y | \ >>> + GIT_SEND_EMAIL_NOTTY=1 \ >>> + git send-email --from=aut...@example.com \ >>> + --to=nob...@example.com \ >>> + --smtp-server="$(pwd)/fake.sendmail" \ >>> + --validate \ >>> + $patches $patches $patches \ >>> + >stdout && >>> + ! grep "Patches specified several times: " stdout >> >> ... this here should be 'test_i18ngrep' instead of plain old 'grep'. > > Yup. Thanks for carefully reading the patch(es), as always. Thanks for spotting, will fix in v3. -- Dmitry
[PATCHv2] 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 linux-ker...@vger.kernel.org /tmp/timens/ --cc 'Dmitry Safonov <0x7f454...@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-606401d19...@gmail.com Cc: Andrei Vagin Suggested-by: Ævar Arnfjörð Bjarmason Signed-off-by: Dmitry Safonov --- v2: Moved the check under --validate, fixed tests, added a new test, updated documentation for --validate Documentation/git-send-email.txt | 2 ++ git-send-email.perl | 14 ++ t/t9001-send-email.sh| 15 +++ 3 files changed, 31 insertions(+) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index d93e5d0f58f0..0441bb1b5d3b 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -421,6 +421,8 @@ have been specified, in which case default to 'compose'. ('auto', 'base64', or 'quoted-printable') is used; this is due to SMTP limits as described by http://www.ietf.org/rfc/rfc5322.txt. + * Ask confirmation before sending patches multiple times + if the supplied patches set overlaps. -- + Default is the value of `sendemail.validate`; if this is not set, diff --git a/git-send-email.perl b/git-send-email.perl index 5f92c89c1c1b..c1638d06f81d 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -688,6 +688,9 @@ sub is_format_patch_arg { @files = handle_backup_files(@files); if ($validate) { + my %seen; + my @dupes = grep { $seen{$_}++ } @files; + foreach my $f (@files) { unless (-p $f) { my $error = validate_patch($f, $target_xfer_encoding); @@ -695,6 +698,17 @@ sub is_format_patch_arg { $f, $error); } } + if (@dupes) { + printf(__("Patches specified several times: \n")); + printf(__("%s \n" x @dupes), @dupes); + $_ = ask(__("Do you want to send those patches several times? Y/n "), + default => "y", + valid_re => qr/^(?:yes|y|no|n)/i); + if (/^n/i) { + cleanup_compose_files(); + exit(0); + } + } } if (@files) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 997f90b42b3e..77df51519d6e 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -555,6 +555,7 @@ test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' --no-chain-reply-to \ --in-reply-to="$(cat expect)" \ --smtp-server="$(pwd)/fake.sendmail" \ + --no-validate \ $patches $patches $patches \ 2>errors && # The first message is a reply to --in-reply-to @@ -577,6 +578,7 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' --chain-reply-to \ --in-reply-to="$(cat expect)" \ --smtp-server="$(pwd)/fake.sendmail" \ + --no-validate \ $patches $patches $patches \ 2>errors && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && @@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' test_cmp expect actual ' +test_expect_success $PREREQ 'ask confirmation for double-send' ' + clean_fake_sendmail && + echo y | \ + GIT_SEND_EMAIL_NOTTY=1 \ + git send-email --from=aut...@example.com \ + --to=nob...@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + $patches $patches $patches \ + >stdout && + ! grep "Patches specified several times: " stdout +' + test_expect_success $PREREQ 'setup fake editor' ' write_script fake-editor <<-\EOF echo fake edit >>"$1" -- 2.22.0
Re: [PATCH] send-email: Ask if a patch should be sent twice
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-ker...@vger.kernel.org /tmp/timens/ >> --cc 'Dmitry Safonov <0x7f454...@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-606401d19...@gmail.com >> Cc: Andrei Vagin >> Signed-off-by: Dmitry Safonov >> --- >> 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 > ?". > > Now the user is asked a file-at-a-time. Ok, thanks for the suggestions. -- Dmitry
[PATCH] 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 linux-ker...@vger.kernel.org /tmp/timens/ --cc 'Dmitry Safonov <0x7f454...@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-606401d19...@gmail.com Cc: Andrei Vagin Signed-off-by: Dmitry Safonov --- 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
Re: [Question] Git histrory after greybus merge
Adding Cc: git list, Junio. 2016-10-26 15:55 GMT+03:00 Dmitry Safonov <0x7f454...@gmail.com>: > Hi, > > Is there any way to specify git-log or git-rev-list which root tree to use? > I mean, I got the following situation: > I saw the commit a67dd266adf4 ("netfilter: xtables: prepare for > on-demand hook register") > by git-blame and want to see commits on top of that particular commit. > Earlier I've used for that: > $ git log --reverse a67dd266adf4^..HEAD > > But now after merging greybus it follows the greybus's tree and shows me: > [linux]$ git log --reverse a67dd266adf4^..HEAD --oneline > cd26f1bd6bf3 greybus: Initial commit > c8a797a98cb6 greybus: Import most recent greybus code to new repo. > 06823c3eb9c4 greybus: README and .gitignore updates > > Which quite sucks as this isn't a hash I'm referencing. > Anyway, back to the question, is there any option to tell git which tree to > use? > I'm sure this was asked before (on btrfs merge?), but I didn't find > the answer so far. > I'm using git v2.10.1 if anything. > > Thanks, > Dmitry