{"thread":{"id":"42006","subject":"[PATCH] send-email: detect and offer to skip backup files","startedAt":"2016-04-12T22:53:54Z","lastAt":"2016-04-13T01:38:13Z","messageCount":5,"participants":["Junio C Hamano","Eric Sunshine","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"283229","messageId":"xmqqlh4io2v1.fsf@gitster.mtv.corp.google.com","threadId":"42006","inReplyTo":null,"subject":"[PATCH] send-email: detect and offer to skip backup files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-12T22:53:54Z","receivedAt":"2016-04-12T22:53:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Diligent people save output from format-patch to files, proofread\nand edit them and then finally send the result out.  If the\nresulting files are sent out with \"git send-email 0*\", this ends up\nsending backup files (e.g. 0001-X.patch.backup or 0001-X.patch~)\nleft by their editors next to the final version.  Sending them with\n\"git send-email 0*.patch\" (if format-patch was run with the standard\nsuffix) would avoid such an embarrassment, but not everybody is\ncareful.\n\nAfter collecting files to be sent (and sorting them if read from a\ndirectory), notice when the file being sent out has the same name as\nthe previous file, plus some suffix (e.g. 0001-X.patch was sent, and\nwe are looking at 0001-X.patch.backup or 0001-X.patch~), and the\nsuffix begins with a non-alnum (e.g. \".backup\" or \"~\") and ask if\nthe user really wants to send it out.  Once the user skips sending\nsuch a \"backup\" file, remember the suffix and stop asking the same\nquestion (e.g. after skipping 0001-X.patch~, skip 0002-Y.patch~\nwithout asking).\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * Just something I had lying around in my tree...\n\n git-send-email.perl | 40 ++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 40 insertions(+)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex d356901..74ed01a 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -621,6 +621,8 @@ sub is_format_patch_arg {\n \tpush @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts);\n }\n \n+@files = handle_backup_files(@files);\n+\n if ($validate) {\n \tforeach my $f (@files) {\n \t\tunless (-p $f) {\n@@ -1726,6 +1728,44 @@ sub validate_patch {\n \treturn;\n }\n \n+sub handle_backup {\n+\tmy ($last, $lastlen, $file, $known_suffix) = @_;\n+\tmy ($suffix, $skip);\n+\n+\t$skip = 0;\n+\tif (defined $last &&\n+\t    ($lastlen < length($file)) &&\n+\t    (substr($file, 0, $lastlen) eq $last) &&\n+\t    ($suffix = substr($file, $lastlen)) !~ /^[a-z0-9]/i) {\n+\t\tif (defined $known_suffix && $suffix eq $known_suffix) {\n+\t\t\tprint \"Skipping $file with backup suffix '$known_suffix'.\\n\";\n+\t\t\t$skip = 1;\n+\t\t} else {\n+\t\t\tmy $answer = ask(\"Do you really want to send $file? (y|N): \",\n+\t\t\t\t\t valid_re => qr/^(?:y|n)/i,\n+\t\t\t\t\t default => 'y');\n+\t\t\t$skip = ($answer ne 'y');\n+\t\t\tif ($skip) {\n+\t\t\t\t$known_suffix = $suffix;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn ($skip, $known_suffix);\n+}\n+\n+sub handle_backup_files {\n+\tmy @file = @_;\n+\tmy ($last, $lastlen, $known_suffix, $skip, @result);\n+\tfor my $file (@file) {\n+\t\t($skip, $known_suffix) = handle_backup($last, $lastlen,\n+\t\t\t\t\t\t       $file, $known_suffix);\n+\t\tpush @result, $file unless $skip;\n+\t\t$last = $file;\n+\t\t$lastlen = length($file);\n+\t}\n+\treturn @result;\n+}\n+\n sub file_has_nonascii {\n \tmy $fn = shift;\n \topen(my $fh, '<', $fn)\n-- \n2.8.1-347-g322afaf\n"},{"id":"283231","messageId":"CAPig+cToB2ZLBarhtHMR3VHfE16ypRj-drdYDmVS9NmdJ4rYuw@mail.gmail.com","threadId":"42006","inReplyTo":"xmqqlh4io2v1.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] send-email: detect and offer to skip backup files","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-04-12T23:00:20Z","receivedAt":"2016-04-12T23:00:20Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Apr 12, 2016 at 6:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Diligent people save output from format-patch to files, proofread\n> and edit them and then finally send the result out.  If the\n> resulting files are sent out with \"git send-email 0*\", this ends up\n> sending backup files (e.g. 0001-X.patch.backup or 0001-X.patch~)\n> left by their editors next to the final version.  Sending them with\n> \"git send-email 0*.patch\" (if format-patch was run with the standard\n> suffix) would avoid such an embarrassment, but not everybody is\n> careful.\n>\n> After collecting files to be sent (and sorting them if read from a\n> directory), notice when the file being sent out has the same name as\n> the previous file, plus some suffix (e.g. 0001-X.patch was sent, and\n> we are looking at 0001-X.patch.backup or 0001-X.patch~), and the\n> suffix begins with a non-alnum (e.g. \".backup\" or \"~\") and ask if\n> the user really wants to send it out.  Once the user skips sending\n> such a \"backup\" file, remember the suffix and stop asking the same\n> question (e.g. after skipping 0001-X.patch~, skip 0002-Y.patch~\n> without asking).\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> +sub handle_backup {\n> +       my ($last, $lastlen, $file, $known_suffix) = @_;\n> +       my ($suffix, $skip);\n> +\n> +       $skip = 0;\n> +       if (defined $last &&\n> +           ($lastlen < length($file)) &&\n> +           (substr($file, 0, $lastlen) eq $last) &&\n> +           ($suffix = substr($file, $lastlen)) !~ /^[a-z0-9]/i) {\n> +               if (defined $known_suffix && $suffix eq $known_suffix) {\n> +                       print \"Skipping $file with backup suffix '$known_suffix'.\\n\";\n> +                       $skip = 1;\n> +               } else {\n> +                       my $answer = ask(\"Do you really want to send $file? (y|N): \",\n> +                                        valid_re => qr/^(?:y|n)/i,\n> +                                        default => 'y');\n\nI still have the same question[1] as last time I reviewed this patch:\nShould default be 'n', or am I misunderstanding?\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/289063/focus=289197\n\n> +                       $skip = ($answer ne 'y');\n> +                       if ($skip) {\n> +                               $known_suffix = $suffix;\n> +                       }\n> +               }\n> +       }\n> +       return ($skip, $known_suffix);\n> +}\n> +\n> +sub handle_backup_files {\n> +       my @file = @_;\n> +       my ($last, $lastlen, $known_suffix, $skip, @result);\n> +       for my $file (@file) {\n> +               ($skip, $known_suffix) = handle_backup($last, $lastlen,\n> +                                                      $file, $known_suffix);\n> +               push @result, $file unless $skip;\n> +               $last = $file;\n> +               $lastlen = length($file);\n> +       }\n> +       return @result;\n> +}\n> +\n>  sub file_has_nonascii {\n>         my $fn = shift;\n>         open(my $fh, '<', $fn)\n> --\n> 2.8.1-347-g322afaf\n"},{"id":"283239","messageId":"CAGZ79kZ+_JW-5BWdXse++_KaATO+qDhNtTz_k5gX507sObZyzA@mail.gmail.com","threadId":"42006","inReplyTo":"xmqqlh4io2v1.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] send-email: detect and offer to skip backup files","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-12T23:05:21Z","receivedAt":"2016-04-12T23:05:21Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Apr 12, 2016 at 3:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Diligent people save output from format-patch to files, proofread\n> and edit them and then finally send the result out.  If the\n> resulting files are sent out with \"git send-email 0*\", this ends up\n> sending backup files (e.g. 0001-X.patch.backup or 0001-X.patch~)\n> left by their editors next to the final version.  Sending them with\n> \"git send-email 0*.patch\" (if format-patch was run with the standard\n> suffix) would avoid such an embarrassment, but not everybody is\n> careful.\n>\n> After collecting files to be sent (and sorting them if read from a\n> directory), notice when the file being sent out has the same name as\n> the previous file, plus some suffix (e.g. 0001-X.patch was sent, and\n> we are looking at 0001-X.patch.backup or 0001-X.patch~), and the\n> suffix begins with a non-alnum (e.g. \".backup\" or \"~\") and ask if\n> the user really wants to send it out.  Once the user skips sending\n> such a \"backup\" file, remember the suffix and stop asking the same\n> question (e.g. after skipping 0001-X.patch~, skip 0002-Y.patch~\n> without asking).\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>\n>  * Just something I had lying around in my tree...\n\nI think that is a valid use case. (Save the user from embarrassment).\nAlthough I admit to being even more stupid than that.\n\nOnce I made the mistake to not remove a previous patch series I had,\nsuch that there was:\n\n  0000-coverletter.patch (newly worded)\n  0001-bla-from-new-series\n  0001-foo-from-old-series\n  0002-...\n  ...\n\n`git send-email 0*` then sent out a totally bogus series for me.\n\nAs another user friendly helper we could warn/abort if the first <n> characters\nare the same as the previous patch as well?\n\n>\n>  git-send-email.perl | 40 ++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 40 insertions(+)\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index d356901..74ed01a 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -621,6 +621,8 @@ sub is_format_patch_arg {\n>         push @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts);\n>  }\n>\n> +@files = handle_backup_files(@files);\n> +\n>  if ($validate) {\n>         foreach my $f (@files) {\n>                 unless (-p $f) {\n> @@ -1726,6 +1728,44 @@ sub validate_patch {\n>         return;\n>  }\n>\n> +sub handle_backup {\n> +       my ($last, $lastlen, $file, $known_suffix) = @_;\n> +       my ($suffix, $skip);\n> +\n> +       $skip = 0;\n> +       if (defined $last &&\n> +           ($lastlen < length($file)) &&\n> +           (substr($file, 0, $lastlen) eq $last) &&\n> +           ($suffix = substr($file, $lastlen)) !~ /^[a-z0-9]/i) {\n> +               if (defined $known_suffix && $suffix eq $known_suffix) {\n> +                       print \"Skipping $file with backup suffix '$known_suffix'.\\n\";\n> +                       $skip = 1;\n> +               } else {\n> +                       my $answer = ask(\"Do you really want to send $file? (y|N): \",\n> +                                        valid_re => qr/^(?:y|n)/i,\n> +                                        default => 'y');\n> +                       $skip = ($answer ne 'y');\n> +                       if ($skip) {\n> +                               $known_suffix = $suffix;\n> +                       }\n> +               }\n> +       }\n> +       return ($skip, $known_suffix);\n> +}\n> +\n> +sub handle_backup_files {\n> +       my @file = @_;\n> +       my ($last, $lastlen, $known_suffix, $skip, @result);\n> +       for my $file (@file) {\n> +               ($skip, $known_suffix) = handle_backup($last, $lastlen,\n> +                                                      $file, $known_suffix);\n> +               push @result, $file unless $skip;\n> +               $last = $file;\n> +               $lastlen = length($file);\n> +       }\n> +       return @result;\n> +}\n> +\n>  sub file_has_nonascii {\n>         my $fn = shift;\n>         open(my $fh, '<', $fn)\n> --\n> 2.8.1-347-g322afaf\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"283282","messageId":"xmqqzisyl27y.fsf@gitster.mtv.corp.google.com","threadId":"42006","inReplyTo":"CAPig+cToB2ZLBarhtHMR3VHfE16ypRj-drdYDmVS9NmdJ4rYuw@mail.gmail.com","subject":"Re: [PATCH] send-email: detect and offer to skip backup files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-13T01:36:01Z","receivedAt":"2016-04-13T01:36:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> I still have the same question[1] as last time I reviewed this patch:\n> Should default be 'n', or am I misunderstanding?\n\nYes, you are right and no, there is no misunderstanding.\n\nThanks.\n"},{"id":"283284","messageId":"xmqqvb3ml24a.fsf@gitster.mtv.corp.google.com","threadId":"42006","inReplyTo":"CAGZ79kZ+_JW-5BWdXse++_KaATO+qDhNtTz_k5gX507sObZyzA@mail.gmail.com","subject":"Re: [PATCH] send-email: detect and offer to skip backup files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-13T01:38:13Z","receivedAt":"2016-04-13T01:38:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> Once I made the mistake to not remove a previous patch series I had,\n> such that there was:\n>\n>   0000-coverletter.patch (newly worded)\n>   0001-bla-from-new-series\n>   0001-foo-from-old-series\n>   0002-...\n>   ...\n>\n> `git send-email 0*` then sent out a totally bogus series for me.\n>\n> As another user friendly helper we could warn/abort if the first <n> characters\n> are the same as the previous patch as well?\n\nI think that would be one of the many things that can be built on\ntop.  For example, you could notice that all messages begin with\n4-digit and a dash, and send such a set to a special case (where\npatches having duplicated numbers are signalled as a potential\nerror).\n"}]}