config: add helper function for parsing key names

The config callback functions get keys of the general form:

  section.subsection.key

(where the subsection may be contain arbitrary data, or may
be missing). For matching keys without subsections, it is
simple enough to call "strcmp". Matching keys with
subsections is a little more complicated, and each callback
does it in an ad-hoc way, usually involving error-prone
pointer arithmetic.

Let's provide a helper that keeps the pointer arithmetic all
in one place.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-tar: use parse_config_key when parsing config

This is fewer lines of code, but more importantly, fixes a
bogus pointer offset. We are looking for "tar." in the
section, but later assume that the dot we found is at offset
9, not 3. This is a holdover from an earlier iteration of
767cf45 which called the section "tarfilter".

As a result, we could erroneously reject some filters with
dots in their name, as well as read uninitialized memory.

Reported by (and test by) René Scharfe.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert some config callbacks to parse_config_key

These callers can drop some inline pointer arithmetic and
magic offset constants, making them more readable and less
error-prone (those constants had to match the lengths of
strings, but there is no automatic verification of that
fact).

The "ep" pointer (presumably for "end pointer"), which
points to the final key segment of the config variable, is
given the more standard name "key" to describe its function
rather than its derivation.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
userdiff: drop parse_driver function

When we parse userdiff config, we generally assume that

  diff.name.key

will affect the "key" value of the "name" driver. However,
without confirming that the key is a valid userdiff key, we
may accidentally conflict with the ancient "diff.color.*"
namespace. The current code is careful not to even create a
driver struct if we do not see a key that is known by the
diff-driver code.

However, this carefulness is unnecessary; the default driver
with no keys set behaves exactly the same as having no
driver at all. We can simply set up the driver struct as
soon as we see we have a config key that looks like a
driver. This makes the code a bit more readable.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule: use parse_config_key when parsing config

This makes the code a lot simpler to read by dropping a
whole bunch of constant offsets.

As a bonus, it means we also feed the whole config variable
name to our error functions:

  [before]
  $ git -c submodule.foo.fetchrecursesubmodules=bogus checkout
  fatal: bad foo.fetchrecursesubmodules argument: bogus

  [after]
  $ git -c submodule.foo.fetchrecursesubmodules=bogus checkout
  fatal: bad submodule.foo.fetchrecursesubmodules argument: bogus

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule: simplify memory handling in config parsing

We keep a strbuf for the name of the submodule, even though
we only ever add one string to it. Let's just use xmemdupz
instead, which is slightly more efficient and makes it
easier to follow what is going on.

Unfortunately, we still end up having to deal with some
memory ownership issues in some code branches, as we have to
allocate the string in order to do a string list lookup, and
then only sometimes want to hand ownership of that string
over to the string_list. Still, making that explicit in the
code (as opposed to sometimes detaching the strbuf, and then
always releasing it) makes it a little more obvious what is
going on.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
help: use parse_config_key for man config

The resulting code ends up about the same length, but it is
a little more self-explanatory. It now explicitly documents
and checks the pre-condition that the incoming var starts
with "man.", and drops the magic offset "4".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reflog: use parse_config_key in config callback

This doesn't save any lines, but does keep us from doing
error-prone pointer arithmetic with constants.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'jk/config-parsing-cleanup' into jch

Expecting a reroll.

* jk/config-parsing-cleanup:
  reflog: use parse_config_key in config callback
  help: use parse_config_key for man config
  submodule: simplify memory handling in config parsing
  submodule: use parse_config_key when parsing config
  userdiff: drop parse_driver function
  convert some config callbacks to parse_config_key
  archive-tar: use parse_config_key when parsing config
  config: add helper function for parsing key names
Merge branch 'jc/remove-treesame-parent-in-simplify-merges' into jch

The --simplify-merges logic did not cull irrelevant parents from a
merge that is otherwise not interesting with respect to the paths
we are following.

As this touches a fairly core part of the revision traversal
infrastructure, it is appreciated to have an extra set of eyes for
sanity check.

Waiting for comments.

* jc/remove-treesame-parent-in-simplify-merges:
  simplify-merges: drop merge from irrelevant side branch

Conflicts:
	revision.c
Merge branch 'jk/remote-helpers-in-python-3' into jch

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

Will merge to 'next'.

* jk/remote-helpers-in-python-3:
  git-remote-testpy: call print as a function
  git-remote-testpy: don't do unbuffered text I/O
  git-remote-testpy: hash bytes explicitly
  svn-fe: allow svnrdump_sim.py to run with Python 3
  git_remote_helpers: use 2to3 if building with Python 3
  git_remote_helpers: force rebuild if python version changes
  git_remote_helpers: fix input when running under Python 3
  git_remote_helpers: allow building with Python 3
Merge branch 'bc/append-signed-off-by' into jch

Rerolled.

Seems that we will see another round.

* 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
  sequencer.c: remove broken support for rfc2822 continuation in footer

Conflicts:
	builtin/log.c
	t/t4014-format-patch.sh
Merge branch 'tb/t0050-maint' into jch

Will merge to 'next'.

* tb/t0050-maint:
  t0050: Use TAB for indentation
  t0050: honor CASE_INSENSITIVE_FS in add (with different case)
  t0050: known breakage vanished in merge (case change)
Merge branch 'jk/update-install-for-p4' into jch

Will merge to 'next'.

* jk/update-install-for-p4:
  INSTALL: git-p4 doesn't support Python 3
Merge branch 'bc/fix-array-syntax-for-3.0-in-completion-bash' into jch

Fix use of an array notation that older versions of bash do not
understand.

Will merge to 'next'.

* bc/fix-array-syntax-for-3.0-in-completion-bash:
  git-completion.bash: replace zsh notation that breaks bash 3.X
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 'jc/help' into jch

A header file that has the definition of a static array was
included in two places, wasting the space.

Will merge to 'next'.

* jc/help:
  help: include <common-cmds.h> only in one file
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.

* 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/howto/maintain-git.txt
Merge branch 'nd/magic-pathspec-from-root' into jch

Will merge to 'next'.

* nd/magic-pathspec-from-root:
  grep: avoid accepting ambiguous revision
  Update :/abc ambiguity check
Merge branch 'cr/push-force-tag-update' into jch

Regression fix (the bottom one), and error/advice message
improvements (the rest).

Will merge to 'master' the bottom one soonish.
The remainder can cook in 'next' like any other topic.

* cr/push-force-tag-update:
  push: further simplify the logic to assign rejection status
  push: introduce REJECT_FETCH_FIRST and REJECT_NEEDS_FORCE
  push: further clean up fields of "struct ref"