Merge branch 'jm/format-patch-mail-sig'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 19:18:38 +0000 (12:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 19:18:38 +0000 (12:18 -0700)
* jm/format-patch-mail-sig:
format-patch: add "--signature-file=<file>" option
format-patch: make newline after signature conditional

1  2 
Documentation/config.txt
builtin/log.c
t/t4014-format-patch.sh
diff --combined Documentation/config.txt
index bdce52981dbcb12e6dfb82c175d2ca169b53a4be,140ed771efc1e664262809d804ea7b9100cd049c..20cb3a25bc6bc77e62fe05c6ce2d1e8e16e2bfea
@@@ -381,7 -381,7 +381,7 @@@ false), while all other repositories ar
  core.worktree::
        Set the path to the root of the working tree.
        This can be overridden by the GIT_WORK_TREE environment
 -      variable and the '--work-tree' command line option.
 +      variable and the '--work-tree' command-line option.
        The value can be an absolute path or relative to the path to
        the .git directory, which is either specified by --git-dir
        or GIT_DIR, or automatically discovered.
@@@ -489,7 -489,7 +489,7 @@@ core.deltaBaseCacheLimit:
        to avoid unpacking and decompressing frequently used base
        objects multiple times.
  +
 -Default is 16 MiB on all platforms.  This should be reasonable
 +Default is 96 MiB on all platforms.  This should be reasonable
  for all users/operating systems, except on the largest projects.
  You probably do not need to adjust this value.
  +
@@@ -523,7 -523,7 +523,7 @@@ core.askpass:
        environment variable. If not set, fall back to the value of the
        'SSH_ASKPASS' environment variable or, failing that, a simple password
        prompt. The external program shall be given a suitable prompt as
 -      command line argument and write the password on its STDOUT.
 +      command-line argument and write the password on its STDOUT.
  
  core.attributesfile::
        In addition to '.gitattributes' (per-directory) and
@@@ -544,9 -544,6 +544,9 @@@ core.commentchar:
        messages consider a line that begins with this character
        commented, and removes them after the editor returns
        (default '#').
 ++
 +If set to "auto", `git-commit` would select a character that is not
 +the beginning character of any line in existing commit messages.
  
  sequence.editor::
        Text editor used by `git rebase -i` for editing the rebase instruction file.
@@@ -561,19 -558,14 +561,19 @@@ core.pager:
        configuration, then `$PAGER`, and then the default chosen at
        compile time (usually 'less').
  +
 -When the `LESS` environment variable is unset, Git sets it to `FRSX`
 +When the `LESS` environment variable is unset, Git sets it to `FRX`
  (if `LESS` environment variable is set, Git does not change it at
  all).  If you want to selectively override Git's default setting
 -for `LESS`, you can set `core.pager` to e.g. `less -+S`.  This will
 +for `LESS`, you can set `core.pager` to e.g. `less -S`.  This will
  be passed to the shell by Git, which will translate the final
 -command to `LESS=FRSX less -+S`. The environment tells the command
 -to set the `S` option to chop long lines but the command line
 -resets it to the default to fold long lines.
 +command to `LESS=FRX less -S`. The environment does not set the
 +`S` option but the command line does, instructing less to truncate
 +long lines. Similarly, setting `core.pager` to `less -+F` will
 +deactivate the `F` option specified by the environment from the
 +command-line, deactivating the "quit if one screen" behavior of
 +`less`.  One can specifically activate some flags for particular
 +commands: for example, setting `pager.blame` to `less -S` enables
 +line truncation only for `git blame`.
  +
  Likewise, when the `LV` environment variable is unset, Git sets it
  to `-c`.  You can override this setting by exporting `LV` with
@@@ -1122,6 -1114,10 +1122,10 @@@ format.signature:
        Set this variable to the empty string ("") to suppress
        signature generation.
  
+ format.signaturefile::
+       Works just like format.signature except the contents of the
+       file specified by this variable will be used as the signature.
  format.suffix::
        The default for format-patch is to output files with the suffix
        `.patch`. Use this variable to change that suffix (make sure to
@@@ -1332,7 -1328,7 +1336,7 @@@ grep.extendedRegexp:
  gpg.program::
        Use this custom program instead of "gpg" found on $PATH when
        making or verifying a PGP signature. The program must support the
 -      same command line interface as GPG, namely, to verify a detached
 +      same command-line interface as GPG, namely, to verify a detached
        signature, "gpg --verify $file - <$signature" is run, and the
        program is expected to signal a good signature by exiting with
        code 0, and to generate an ascii-armored detached signature, the
@@@ -2301,11 -2297,9 +2305,11 @@@ status.submodulesummary:
        --summary-limit option of linkgit:git-submodule[1]). Please note
        that the summary output command will be suppressed for all
        submodules when `diff.ignoreSubmodules` is set to 'all' or only
 -      for those submodules where `submodule.<name>.ignore=all`. To
 +      for those submodules where `submodule.<name>.ignore=all`. The only
 +      exception to that rule is that status and commit will show staged
 +      submodule changes. To
        also view the summary for ignored submodules you can either use
 -      the --ignore-submodules=dirty command line option or the 'git
 +      the --ignore-submodules=dirty command-line option or the 'git
        submodule summary' command, which shows a similar output but does
        not honor these settings.
  
@@@ -2327,16 -2321,14 +2331,16 @@@ submodule.<name>.branch:
  submodule.<name>.fetchRecurseSubmodules::
        This option can be used to control recursive fetching of this
        submodule. It can be overridden by using the --[no-]recurse-submodules
 -      command line option to "git fetch" and "git pull".
 +      command-line option to "git fetch" and "git pull".
        This setting will override that from in the linkgit:gitmodules[5]
        file.
  
  submodule.<name>.ignore::
        Defines under what circumstances "git status" and the diff family show
        a submodule as modified. When set to "all", it will never be considered
 -      modified, "dirty" will ignore all changes to the submodules work tree and
 +      modified (but it will nonetheless show up in the output of status and
 +      commit when it has been staged), "dirty" will ignore all changes
 +      to the submodules work tree and
        takes only differences between the HEAD of the submodule and the commit
        recorded in the superproject into account. "untracked" will additionally
        let submodules with modified tracked files in their work tree show up.
diff --combined builtin/log.c
index 3b6a6bbaddc8795c148763bb6d71136900a8fbb4,e6dcd19278abacadc748ed5b05b0e6c8296280bc..83b6c489fcb789dde11172a66fa03f948ca8f759
@@@ -158,9 -158,13 +158,9 @@@ static void cmd_log_init_finish(int arg
        if (rev->show_notes)
                init_display_notes(&rev->notes_opt);
  
 -      if (rev->diffopt.pickaxe || rev->diffopt.filter)
 +      if (rev->diffopt.pickaxe || rev->diffopt.filter ||
 +          DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES))
                rev->always_show_header = 0;
 -      if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
 -              rev->always_show_header = 0;
 -              if (rev->diffopt.pathspec.nr != 1)
 -                      usage("git logs can only follow renames on one pathname at a time");
 -      }
  
        if (source)
                rev->show_source = 1;
@@@ -669,6 -673,7 +669,7 @@@ static void add_header(const char *valu
  static int thread;
  static int do_signoff;
  static const char *signature = git_version_string;
+ static const char *signature_file;
  static int config_cover_letter;
  
  enum {
@@@ -738,6 -743,8 +739,8 @@@ static int git_format_config(const cha
        }
        if (!strcmp(var, "format.signature"))
                return git_config_string(&signature, var, value);
+       if (!strcmp(var, "format.signaturefile"))
+               return git_config_pathname(&signature_file, var, value);
        if (!strcmp(var, "format.coverletter")) {
                if (value && !strcasecmp(value, "auto")) {
                        config_cover_letter = COVER_AUTO;
@@@ -840,8 -847,13 +843,13 @@@ static void gen_message_id(struct rev_i
  
  static void print_signature(void)
  {
-       if (signature && *signature)
-               printf("-- \n%s\n\n", signature);
+       if (!signature || !*signature)
+               return;
+       printf("-- \n%s", signature);
+       if (signature[strlen(signature)-1] != '\n')
+               putchar('\n');
+       putchar('\n');
  }
  
  static void add_branch_description(struct strbuf *buf, const char *branch_name)
@@@ -1226,6 -1238,8 +1234,8 @@@ int cmd_format_patch(int argc, const ch
                            PARSE_OPT_OPTARG, thread_callback },
                OPT_STRING(0, "signature", &signature, N_("signature"),
                            N_("add a signature")),
+               OPT_FILENAME(0, "signature-file", &signature_file,
+                               N_("add a signature from a file")),
                OPT__QUIET(&quiet, N_("don't print the patch filenames")),
                OPT_END()
        };
                        cover_letter = (config_cover_letter == COVER_ON);
        }
  
+       if (!signature) {
+               ; /* --no-signature inhibits all signatures */
+       } else if (signature && signature != git_version_string) {
+               ; /* non-default signature already set */
+       } else if (signature_file) {
+               struct strbuf buf = STRBUF_INIT;
+               if (strbuf_read_file(&buf, signature_file, 128) < 0)
+                       die_errno(_("unable to read signature file '%s'"), signature_file);
+               signature = strbuf_detach(&buf, NULL);
+       }
        if (in_reply_to || thread || cover_letter)
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
diff --combined t/t4014-format-patch.sh
index 282bee4a54c924b8168b6a28dfdbeb7ab300d7b7,ae25353a14234b2f7471bfdcafb0a0cd4bbec909..256affce89517a707f9054d2c9643db4f5398832
@@@ -43,7 -43,7 +43,7 @@@ test_expect_success setup 
  test_expect_success "format-patch --ignore-if-in-upstream" '
  
        git format-patch --stdout master..side >patch0 &&
 -      cnt=`grep "^From " patch0 | wc -l` &&
 +      cnt=$(grep "^From " patch0 | wc -l) &&
        test $cnt = 3
  
  '
@@@ -52,7 -52,7 +52,7 @@@ test_expect_success "format-patch --ign
  
        git format-patch --stdout \
                --ignore-if-in-upstream master..side >patch1 &&
 -      cnt=`grep "^From " patch1 | wc -l` &&
 +      cnt=$(grep "^From " patch1 | wc -l) &&
        test $cnt = 2
  
  '
@@@ -69,7 -69,7 +69,7 @@@ test_expect_success "format-patch doesn
        git checkout -b merger master &&
        test_tick &&
        git merge --no-ff slave &&
 -      cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` &&
 +      cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) &&
        test $cnt = 3
  '
  
@@@ -77,7 -77,7 +77,7 @@@ test_expect_success "format-patch resul
  
        git checkout -b rebuild-0 master &&
        git am -3 patch0 &&
 -      cnt=`git rev-list master.. | wc -l` &&
 +      cnt=$(git rev-list master.. | wc -l) &&
        test $cnt = 2
  '
  
@@@ -85,7 -85,7 +85,7 @@@ test_expect_success "format-patch --ign
  
        git checkout -b rebuild-1 master &&
        git am -3 patch1 &&
 -      cnt=`git rev-list master.. | wc -l` &&
 +      cnt=$(git rev-list master.. | wc -l) &&
        test $cnt = 2
  '
  
@@@ -762,6 -762,67 +762,67 @@@ test_expect_success 'format-patch --sig
        ! grep "^-- \$" output
  '
  
+ test_expect_success 'prepare mail-signature input' '
+       cat >mail-signature <<-\EOF
+       Test User <test.email@kernel.org>
+       http://git.kernel.org/cgit/git/git.git
+       git.kernel.org/?p=git/git.git;a=summary
+       EOF
+ '
+ test_expect_success '--signature-file=file works' '
+       git format-patch --stdout --signature-file=mail-signature -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+ '
+ test_expect_success 'format.signaturefile works' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+ '
+ test_expect_success '--no-signature suppresses format.signaturefile ' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout --no-signature -1 >output &&
+       check_patch output &&
+       ! grep "^-- \$" output
+ '
+ test_expect_success '--signature-file overrides format.signaturefile' '
+       cat >other-mail-signature <<-\EOF
+       Use this other signature instead of mail-signature.
+       EOF
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout \
+                       --signature-file=other-mail-signature -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat other-mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+ '
+ test_expect_success '--signature overrides format.signaturefile' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout --signature="my sig" -1 >output &&
+       check_patch output &&
+       grep "my sig" output
+ '
  test_expect_success TTY 'format-patch --stdout paginates' '
        rm -f pager_used &&
        test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&