git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] send-email: detect and offer to skip backup files

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Apr 12, 2016, 23:00 UTC
Message-ID
<CAPig+cToB2ZLBarhtHMR3VHfE16ypRj-drdYDmVS9NmdJ4rYuw@mail.gmail.com>
In-Reply-To
<xmqqlh4io2v1.fsf@gitster.mtv.corp.google.com>
On Tue, Apr 12, 2016 at 6:53 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 38 quoted lines
> Diligent people save output from format-patch to files, proofread
> and edit them and then finally send the result out.  If the
> resulting files are sent out with "git send-email 0*", this ends up
> sending backup files (e.g. 0001-X.patch.backup or 0001-X.patch~)
> left by their editors next to the final version.  Sending them with
> "git send-email 0*.patch" (if format-patch was run with the standard
> suffix) would avoid such an embarrassment, but not everybody is
> careful.
>
> After collecting files to be sent (and sorting them if read from a
> directory), notice when the file being sent out has the same name as
> the previous file, plus some suffix (e.g. 0001-X.patch was sent, and
> we are looking at 0001-X.patch.backup or 0001-X.patch~), and the
> suffix begins with a non-alnum (e.g. ".backup" or "~") and ask if
> the user really wants to send it out.  Once the user skips sending
> such a "backup" file, remember the suffix and stop asking the same
> question (e.g. after skipping 0001-X.patch~, skip 0002-Y.patch~
> without asking).
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> diff --git a/git-send-email.perl b/git-send-email.perl
> +sub handle_backup {
> +       my ($last, $lastlen, $file, $known_suffix) = @_;
> +       my ($suffix, $skip);
> +
> +       $skip = 0;
> +       if (defined $last &&
> +           ($lastlen < length($file)) &&
> +           (substr($file, 0, $lastlen) eq $last) &&
> +           ($suffix = substr($file, $lastlen)) !~ /^[a-z0-9]/i) {
> +               if (defined $known_suffix && $suffix eq $known_suffix) {
> +                       print "Skipping $file with backup suffix '$known_suffix'.\n";
> +                       $skip = 1;
> +               } else {
> +                       my $answer = ask("Do you really want to send $file? (y|N): ",
> +                                        valid_re => qr/^(?:y|n)/i,
> +                                        default => 'y');

I still have the same question[1] as last time I reviewed this patch: Should default be 'n', or am I misunderstanding?

[1]: http://thread.gmane.org/gmane.comp.version-control.git/289063/focus=289197
Show 27 quoted lines
> +                       $skip = ($answer ne 'y');
> +                       if ($skip) {
> +                               $known_suffix = $suffix;
> +                       }
> +               }
> +       }
> +       return ($skip, $known_suffix);
> +}
> +
> +sub handle_backup_files {
> +       my @file = @_;
> +       my ($last, $lastlen, $known_suffix, $skip, @result);
> +       for my $file (@file) {
> +               ($skip, $known_suffix) = handle_backup($last, $lastlen,
> +                                                      $file, $known_suffix);
> +               push @result, $file unless $skip;
> +               $last = $file;
> +               $lastlen = length($file);
> +       }
> +       return @result;
> +}
> +
>  sub file_has_nonascii {
>         my $fn = shift;
>         open(my $fh, '<', $fn)
> --
> 2.8.1-347-g322afaf
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 5 in “send-email: detect and offer to skip backup files”
  1. send-email: detect and offer to skip backup filesJunio C Hamano, Apr 12, 2016
  2. Eric SunshineApr 12, 2016
  3. Junio C HamanoApr 13, 2016
  4. Stefan BellerApr 12, 2016
  5. Junio C HamanoApr 13, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.