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

[PATCH] send-email: Ask if a patch should be sent twice

From
DSDmitry Safonov <dima@arista.com>
Date
Jul 30, 2019, 00:13 UTC
Message-ID
<20190730001352.7477-1-dima@arista.com>
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
Next: Ævar Arnfjörð Bjarmason
Message 1 of 3 in “send-email: Ask if a patch should be sent twice”
  1. send-email: Ask if a patch should be sent twiceDmitry Safonov, Jul 30, 2019
  2. Ævar Arnfjörð BjarmasonJul 30, 2019
  3. Dmitry SafonovJul 30, 2019

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.