sequencer.c: rework search for start of footer to improve clarity

This code sequence is somewhat difficult to read.  Let's rewrite it
using more descriptive variable names to try to make it easier to
understand.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit, cherry-pick -s: remove broken support for multiline rfc2822 fields

Starting with c1e01b0c (commit: More generous accepting of RFC-2822 footer
lines, 2009-10-28), "git commit -s" carefully parses the last paragraph of
each commit message to check if it consists only of RFC2822-style headers,
in which case the signoff will be added as a new line in the same list:

   Reported-by: Reporter <reporter@example.com>
   Signed-off-by: Author <author@example.com>
   Acked-by: Lieutenant <lt@example.com>

It even included support for accepting indented continuation lines for
multiline fields.  Unfortunately the multiline field support is broken
because it checks whether buf[k] (the first character of the *next* line)
instead of buf[i] is a whitespace character.  The result is that any footer
with a continuation line is not accepted, since the last continuation line
neither starts with an RFC2822 field name nor is followed by a continuation
line.

That this has remained broken for so long is good evidence that nobody
actually needed multiline fields.  Rip out the broken continuation support.

There should be no functional change.

[Thanks to Jonathan Nieder for the excellent commit message]

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib-functions.sh: allow to specify the tag name to test_commit

The <message> part of test_commit() may not be appropriate for a tag name.
So let's allow test_commit to accept a fourth argument to specify the tag
name.

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3511: add some tests of 'cherry-pick -s' functionality

Add some tests to ensure that 'cherry-pick -s' operates in the following
manner:

   * Inserts a blank line before appending a s-o-b to a commit message that
     does not contain a s-o-b footer

   * Does not mistake first line "subject: description" as a s-o-b footer

   * Does not mistake single word message body as conforming to rfc2822

   * Appends a s-o-b when last s-o-b in footer does not match committer
     s-o-b, even when committer's s-o-b exists elsewhere in footer.

   * Does not append a s-o-b when last s-o-b matches committer s-o-b

   * Correctly detects a non-conforming footer containing a mix of s-o-b
     like elements and s-o-b elements. (marked "expect failure")

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c: recognize "(cherry picked from ..." as part of s-o-b footer

When 'cherry-pick -s' is used to append a signed-off-by line to a cherry
picked commit, it does not currently detect the "(cherry picked from..."
that may have been appended by a previous 'cherry-pick -x' as part of the
s-o-b footer and it will insert a blank line before appending a new s-o-b.

Let's detect "(cherry picked from...)" as part of the footer so that we
will produce this:

   Signed-off-by: A U Thor <author@example.com>
   (cherry picked from da39a3ee5e6b4b0d3255bfef95601890afd80709)
   Signed-off-by: C O Mmitter <committer@example.com>

instead of this:

   Signed-off-by: A U Thor <author@example.com>
   (cherry picked from da39a3ee5e6b4b0d3255bfef95601890afd80709)

   Signed-off-by: C O Mmitter <committer@example.com>

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Acked-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c: always separate "(cherry picked from" from commit body

Start treating the "(cherry picked from" line added by cherry-pick -x
the same way that the s-o-b lines are treated.  Namely, separate them
from the main commit message body with an empty line.

This commit is mostly a code movement, but notice that
has_conforming_footer() was modified, in addition to being moved.

Introduce tests to test this functionality.

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c: teach append_signoff how to detect duplicate s-o-b

Teach append_signoff how to detect a duplicate s-o-b in the commit footer.
This is in preparation to unify the append_signoff implementations in
log-tree.c and sequencer.c.

Fixes test in t3511.

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c: teach append_signoff to avoid adding a duplicate newline

Teach append_signoff to detect whether a blank line exists at the position
that the signed-off-by line will be added, and avoid adding an additional
one if one already exists.  This is necessary to allow format-patch to add a
s-o-b to a patch with no commit message without adding an extra newline.  A
following patch will make format-patch use this function rather than the
append_signoff implementation inside log-tree.c.

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t4014: more tests about appending s-o-b lines

[bc: Squash the tests from Duy's original unify-appending-sob series.

     Fix test 90 "signoff: some random signoff-alike" and mark as failing.
     Correct behavior should insert a blank line after message body and
     signed-off-by.

     Add two additional tests:

       1. failure to detect non-conforming elements in the footer when last
          line matches committer's s-o-b.
       2. ensure various s-o-b -like elements in the footer are handled as
          conforming. e.g. "Change-id: IXXXX or Bug: 1234"
]

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
format-patch: update append_signoff prototype

This is a preparation step for merging with append_signoff from
sequencer.c

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Unify appending signoff in format-patch, commit and sequencer

There are two implementations of append_signoff in log-tree.c and
sequencer.c, which do more or less the same thing.  Unify on top of the
sequencer.c implementation.

Add a test in t4014 to demonstrate support for non-s-o-b elements in the
commit footer provided by sequence.c:append_sob.  Mark tests fixed as
appropriate.

[Commit message mostly stolen from Nguyễn Thái Ngọc Duy's original
 unification patch]

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'bc/append-signed-off-by' into jch

Rerolled.

Expecting another reroll.
$gmane/214231

* bc/append-signed-off-by:
  Unify appending signoff in format-patch, commit and sequencer
  format-patch: update append_signoff prototype
  t4014: more tests about appending s-o-b lines
  sequencer.c: teach append_signoff to avoid adding a duplicate newline
  sequencer.c: teach append_signoff how to detect duplicate s-o-b
  sequencer.c: always separate "(cherry picked from" from commit body
  sequencer.c: recognize "(cherry picked from ..." as part of s-o-b footer
  t/t3511: add some tests of 'cherry-pick -s' functionality
  t/test-lib-functions.sh: allow to specify the tag name to test_commit
  commit, cherry-pick -s: remove broken support for multiline rfc2822 fields
  sequencer.c: rework search for start of footer to improve clarity

Conflicts:
	builtin/log.c
	t/t4014-format-patch.sh
Merge branch 'jc/hidden-refs' into jch

Allow the server side to unclutter the refs/ namespace it shows by
default, while still allowing requests for histories leading to the
tips of hidden refs by updated clients (which are not written yet).

* jc/hidden-refs:
  upload-pack: allow hiding ref hiearchies
  upload-pack: share more code
Merge branch 'ta/doc-no-small-caps' into jch

Update documentation to change "GIT" which was a poor-man's small
caps to "Git" which was the intended spelling.  Also change "git"
spelled in all-lowercase to "Git" when it refers to the system as
the whole or the concept it embodies, as opposed to the command the
end users would type.

Will wait for a week or so (say, til end of January) for Thomas to
collect fix-ups, squash the result into two patches and then merge
to 'next'.

* ta/doc-no-small-caps:
  fixup! Change 'git' to 'Git' whenever the whole system is referred to #4
  Change 'git' to 'Git' whenever the whole system is referred to #4
  fixup! Change 'git' to 'Git' whenever the whole system is referred to #3
  Change 'git' to 'Git' whenever the whole system is referred to #3
  fixup! Change 'git' to 'Git' whenever the whole system is referred to #2
  Change 'git' to 'Git' whenever the whole system is referred to #2
  fixup! fixup! Change 'git' to 'Git' whenever the whole system is referred to #1
  fixup! Change 'git' to 'Git' whenever the whole system is referred to #1
  Change 'git' to 'Git' whenever the whole system is referred to #1
  Documentation: avoid poor-man's small caps

Conflicts:
	Documentation/git-cvsimport.txt
	Documentation/howto/maintain-git.txt
Merge branch 'jk/mergetool' into jch

Cleans up mergetool/difftool combo.

Will merge to 'next'.

* jk/mergetool:
  mergetools: simplify how we handle "vim" and "defaults"
  mergetool--lib: don't call "exit" in setup_tool
  mergetool--lib: improve show_tool_help() output
  mergetools/vim: remove redundant diff command
  git-difftool: use git-mergetool--lib for "--tool-help"
  git-mergetool: don't hardcode 'mergetool' in show_tool_help
  git-mergetool: remove redundant assignment
  git-mergetool: move show_tool_help to mergetool--lib
Merge branch 'da/mergetool-docs' into jch

Build on top of the clean-up done by jk/mergetool and automatically
generate the list of mergetool and difftool backends the build
supports to be included in the documentation.

Expecting a reroll.

* da/mergetool-docs:
  doc: generate a list of valid merge tools
  mergetool--lib: add functions for finding available tools
  mergetool--lib: improve the help text in guess_merge_tool()
  mergetool--lib: simplify command expressions

Conflicts:
	Documentation/Makefile
Merge branch 'jk/remote-helpers-in-python-3' into jch

Prepare remote-helper test written in Python to be run with Python3.

Waiting for the final review and Ack, perhaps from Michael.

* jk/remote-helpers-in-python-3:
  git-remote-testpy: fix path hashing on Python 3
Merge branch 'jk/gc-auto-after-fetch' into pu

This is to resolve merge conflicts early for the same topic to
recent codebase.

Will merge to 'next'.

* jk/gc-auto-after-fetch:
  fetch-pack: avoid repeatedly re-scanning pack directory
  fetch: run gc --auto after fetching
Merge branch 'jk/read-commit-buffer-data-after-free' into pu

Clarify the ownership rule for commit->buffer field, which some
callers incorrectly accessed without making sure the data is
available there.

* jk/read-commit-buffer-data-after-free:
  logmsg_reencode: lazily load missing commit buffers
  logmsg_reencode: never return NULL
  commit: drop useless xstrdup of commit message
Merge branch 'ss/mergetools-tortoise' into pu

Update mergetools to work better with newer merge helper tortoise ships.

Will merge to 'next'.

* ss/mergetools-tortoise:
  mergetools: allow passing pathnames with SP in them to TortoiseGitMerge
  mergetools: support TortoiseGitMerge