Merge branch 'nd/complete-format-patch'
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:28 +0000 (22:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:28 +0000 (22:37 +0900)
The support for format-patch (and send-email) by the command-line
completion script (in contrib/) has been simplified a bit.

* nd/complete-format-patch:
completion: use __gitcomp_builtin for format-patch

1  2 
contrib/completion/git-completion.bash
git-send-email.perl
index e9647a103a220a8cbd73096b37d0fb54ccc133d9,8409978793c7b2fc8bb1410f3bad070e3b372e8a..9e8ec95c3c7adb2956435ded43b020532aafa1c2
@@@ -400,7 -400,7 +400,7 @@@ __gitcomp_builtin (
        if [ -z "$options" ]; then
                # leading and trailing spaces are significant to make
                # option removal work correctly.
 -              options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
 +              options=" $incl $(__git ${cmd/_/ } --git-completion-helper) "
                for i in $excl; do
                        options="${options/ $i / }"
                done
@@@ -1341,6 -1341,17 +1341,6 @@@ _git_checkout (
        esac
  }
  
 -_git_cherry ()
 -{
 -      case "$cur" in
 -      --*)
 -              __gitcomp_builtin cherry
 -              return
 -      esac
 -
 -      __git_complete_refs
 -}
 -
  __git_cherry_pick_inprogress_options="--continue --quit --abort"
  
  _git_cherry_pick ()
@@@ -1521,13 -1532,9 +1521,9 @@@ _git_fetch (
        __git_complete_remote_or_refspec
  }
  
- __git_format_patch_options="
-       --stdout --attach --no-attach --thread --thread= --no-thread
-       --numbered --start-number --numbered-files --keep-subject --signoff
-       --signature --no-signature --in-reply-to= --cc= --full-index --binary
-       --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
-       --inline --suffix= --ignore-if-in-upstream --subject-prefix=
-       --output-directory --reroll-count --to= --quiet --notes
+ __git_format_patch_extra_options="
+       --full-index --not --all --no-prefix --src-prefix=
+       --dst-prefix= --notes
  "
  
  _git_format_patch ()
                return
                ;;
        --*)
-               __gitcomp "$__git_format_patch_options"
+               __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
                return
                ;;
        esac
@@@ -1822,7 -1829,7 +1818,7 @@@ _git_mergetool (
                return
                ;;
        --*)
 -              __gitcomp "--tool= --prompt --no-prompt"
 +              __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
                return
                ;;
        esac
@@@ -2070,7 -2077,7 +2066,7 @@@ _git_send_email (
                return
                ;;
        --*)
-               __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
+               __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
                        --compose --confirm= --dry-run --envelope-sender
                        --from --identity
                        --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
                        --smtp-server-port --smtp-encryption= --smtp-user
                        --subject --suppress-cc= --suppress-from --thread --to
                        --validate --no-validate
-                       $__git_format_patch_options"
+                       $__git_format_patch_extra_options"
                return
                ;;
        esac
diff --combined git-send-email.perl
index 4b9d3ad1bdc56881add391def6ed52645ddb89a7,ed0714eaaa2e90f6db09404d111f513cbfc50296..8eb63b5a2f8d07038f6c8ef645a483cd77ffd99f
@@@ -82,11 -82,8 +82,11 @@@ git send-email --dump-aliase
                                       Pass an empty string to disable certificate
                                       verification.
      --smtp-domain           <str>  * The domain name sent to HELO/EHLO handshake
 -    --smtp-auth             <str>  * Space-separated list of allowed AUTH mechanisms.
 +    --smtp-auth             <str>  * Space-separated list of allowed AUTH mechanisms, or
 +                                     "none" to disable authentication.
                                       This setting forces to use one of the listed mechanisms.
 +    --no-smtp-auth                   Disable SMTP authentication. Shorthand for
 +                                     `--smtp-auth=none`
      --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.
  
      --batch-size            <int>  * send max <int> message per connection.
@@@ -97,7 -94,7 +97,7 @@@
      --identity              <str>  * Use the sendemail.<id> options.
      --to-cmd                <str>  * Email To: via `<str> \$patch_path`
      --cc-cmd                <str>  * Email Cc: via `<str> \$patch_path`
 -    --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.
 +    --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, misc-by, all.
      --[no-]cc-cover                * Email Cc: addresses in the cover letter.
      --[no-]to-cover                * Email To: addresses in the cover letter.
      --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.
@@@ -122,6 -119,11 +122,11 @@@ EO
        exit(1);
  }
  
+ sub completion_helper {
+     print Git::command('format-patch', '--git-completion-helper');
+     exit(0);
+ }
  # most mail servers generate the Date: header, but not all...
  sub format_2822_time {
        my ($time) = @_;
@@@ -314,6 -316,7 +319,7 @@@ $SIG{INT}  = \&signal_handler
  # needing, first, from the command line:
  
  my $help;
+ my $git_completion_helper;
  my $rc = GetOptions("h" => \$help,
                      "dump-aliases" => \$dump_aliases);
  usage() unless $rc;
@@@ -344,7 -347,6 +350,7 @@@ $rc = GetOptions
                    "smtp-debug:i" => \$debug_net_smtp,
                    "smtp-domain:s" => \$smtp_domain,
                    "smtp-auth=s" => \$smtp_auth,
 +                  "no-smtp-auth" => sub {$smtp_auth = 'none'},
                    "identity=s" => \$identity,
                    "annotate!" => \$annotate,
                    "no-annotate" => sub {$annotate = 0},
                    "no-xmailer" => sub {$use_xmailer = 0},
                    "batch-size=i" => \$batch_size,
                    "relogin-delay=i" => \$relogin_delay,
+                   "git-completion-helper" => \$git_completion_helper,
         );
  
  usage() if $help;
+ completion_helper() if $git_completion_helper;
  unless ($rc) {
      usage();
  }
@@@ -458,13 -462,13 +466,13 @@@ my(%suppress_cc)
  if (@suppress_cc) {
        foreach my $entry (@suppress_cc) {
                die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry)
 -                      unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc)$/;
 +                      unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/;
                $suppress_cc{$entry} = 1;
        }
  }
  
  if ($suppress_cc{'all'}) {
 -      foreach my $entry (qw (cccmd cc author self sob body bodycc)) {
 +      foreach my $entry (qw (cccmd cc author self sob body bodycc misc-by)) {
                $suppress_cc{$entry} = 1;
        }
        delete $suppress_cc{'all'};
@@@ -475,7 -479,7 +483,7 @@@ $suppress_cc{'self'} = $suppress_from i
  $suppress_cc{'sob'} = !$signed_off_by_cc if defined $signed_off_by_cc;
  
  if ($suppress_cc{'body'}) {
 -      foreach my $entry (qw (sob bodycc)) {
 +      foreach my $entry (qw (sob bodycc misc-by)) {
                $suppress_cc{$entry} = 1;
        }
        delete $suppress_cc{'body'};
@@@ -1245,7 -1249,7 +1253,7 @@@ sub smtp_host_string 
  # (smtp_user was not specified), and 0 otherwise.
  
  sub smtp_auth_maybe {
 -      if (!defined $smtp_authuser || $auth) {
 +      if (!defined $smtp_authuser || $auth || (defined $smtp_auth && $smtp_auth eq "none")) {
                return 1;
        }
  
@@@ -1685,7 -1689,7 +1693,7 @@@ sub process_file 
        # Now parse the message body
        while(<$fh>) {
                $message .=  $_;
 -              if (/^(Signed-off-by|Cc): (.*)/i) {
 +              if (/^([a-z-]*-by|Cc): (.*)/i) {
                        chomp;
                        my ($what, $c) = ($1, $2);
                        # strip garbage for the address we'll use:
                        if ($sc eq $sender) {
                                next if ($suppress_cc{'self'});
                        } else {
 -                              next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
 -                              next if $suppress_cc{'bodycc'} and $what =~ /Cc/i;
 +                              if ($what =~ /^Signed-off-by$/i) {
 +                                      next if $suppress_cc{'sob'};
 +                              } elsif ($what =~ /-by$/i) {
 +                                      next if $suppress_cc{'misc-by'};
 +                              } elsif ($what =~ /Cc/i) {
 +                                      next if $suppress_cc{'bodycc'};
 +                              }
 +                      }
 +                      if ($c !~ /.+@.+|<.+>/) {
 +                              printf("(body) Ignoring %s from line '%s'\n",
 +                                      $what, $_) unless $quiet;
 +                              next;
                        }
                        push @cc, $c;
                        printf(__("(body) Adding cc: %s from line '%s'\n"),
@@@ -1848,7 -1842,7 +1856,7 @@@ sub apply_transfer_encoding 
        my $from = shift;
        my $to = shift;
  
 -      return $message if ($from eq $to and $from ne '7bit');
 +      return ($message, $to) if ($from eq $to and $from ne '7bit');
  
        require MIME::QuotedPrint;
        require MIME::Base64;