summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-11 17:31:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-07-11 17:31:04 (GMT)
commit89b8710fce0d1b3d99c0a1c218bacb82ff0811e4 (patch)
tree039534265e7969747df16b610d389184fb0c0522 /git-send-email.perl
parent5c589a73de4394ad125a4effac227b3aec856fa1 (diff)
parent531220ba500168bc5a2080df24dfd61705cafa3c (diff)
downloadgit-89b8710fce0d1b3d99c0a1c218bacb82ff0811e4.zip
git-89b8710fce0d1b3d99c0a1c218bacb82ff0811e4.tar.gz
git-89b8710fce0d1b3d99c0a1c218bacb82ff0811e4.tar.bz2
Merge branch 'jc/send-email-skip-backup'
A careless invocation of "git send-email directory/" after editing 0001-change.patch with an editor often ends up sending both 0001-change.patch and its backup file, 0001-change.patch~, causing embarrassment and a minor confusion. Detect such an input and offer to skip the backup files when sending the patches out. * jc/send-email-skip-backup: send-email: detect and offer to skip backup files
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl40
1 files changed, 40 insertions, 0 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index 6958785..da81be4 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -621,6 +621,8 @@ if (@rev_list_opts) {
push @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts);
}
+@files = handle_backup_files(@files);
+
if ($validate) {
foreach my $f (@files) {
unless (-p $f) {
@@ -1727,6 +1729,44 @@ sub validate_patch {
return;
}
+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 => 'n');
+ $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)