config: document current write behaviour in a test

On set, we set/add the value written to the config's internal values,
but we do not refresh old values.

Document this in a test in preparation for the refresh changes.
config: implement config snapshotting

In order to have consistent views of the config files for remotes,
submodules et al. and a configuration that represents what is currently
stored on-disk, we need a way to provide a view of the configuration
that does not change.

The goal here is to provide the snapshotting part by creating a
read-only copy of the state of the configuration at a particular point
in time, which does not change when a repository's main config changes.
Use config snapshotting

This way we can assume we have a consistent view of the config situation
when we're looking up remote, branch, pack-objects, etc.
config: make refresh atomic

Current code sets the active map to a new one and builds it whilst it's
active. This is a race condition with someone else trying to access the
same config.

Instead, let's build up our new map and swap the active and new one.
config: split out the refresh step

This will be used by the writing commands in a later step.
config: use a snapshot for the iterator
config: refresh the values on write

When writing out, parse the resulting file instead of adding or
replacing the value locally. This has the effect of reading external
changes as well.
config: refresh before reading a value

With the isolation of complex reads, we can now try to refresh the
on-disk file before reading a value from it.

This changes the semantics a bit, as before we could be sure that a
string we got from the configuration was valid until we wrote or
refreshed. This is no longer the case, as a read can also invalidate the
pointer.
config: document the how long the pointers are valid for
config: refresh on delete

When we delete an entry, we also want to refresh the configuration to
catch any changes that happened externally.

This allows us to simplify the logic, as we no longer need to delete
these variables internally. The whole state will be refreshed and the
deleted entries won't be there.
config: refcount the values map

This is mostly groundwork to let us re-use the map in the snapshots.
config: share the strmap on snapshot

Now that our strmap is no longer modified but replaced, we can use the
same strmap for the snapshot's values and it will be freed when we don't
need it anymore.
netops: unit-test the cert host-name pattern matching

This kind of stuff should have unit tests, even if it's just to show
what we expect to match successfully.
netops: provide more specific error for cert failure

Specify what we do not like about the certificate. In this case, we do
not like the name.
netops: catch the server not sending a certificate

It's possible for an encrypted connection not have a certificate. In
this case, SSL_get_verify_result() will return OK because no error
happened (as it never even tried to validate anything).

SSL_get_peer_certificate() will return NULL in this case so we need to
catch that. On the upside, the current code would segfault in this
situation instead of letting it through as a valid cert.
repository: introduce a convenience config snapshot method

Accessing the repository's config and immediately taking a snapshot of
it is a common operation, so let's provide a convenience function for
it.
Be more careful with user-supplied buffers

This adds in missing calls to `git_buf_sanitize` and fixes a
number of places where `git_buf` APIs could inadvertently write
NUL terminator bytes into invalid buffers.  This also changes the
behavior of `git_buf_sanitize` to NUL terminate a buffer if it can
and of `git_buf_shorten` to do nothing if it can.

Adds tests of filtering code with zeroed (i.e. unsanitized) buffer
which was previously triggering a segfault.
Pass unconverted data when iconv doesn't like it

When using Iconv to convert unicode data and iconv doesn't like
the source data (because it thinks that it's not actual UTF-8),
instead of stopping the operation, just use the unconverted data.
This will generally do the right thing on the filesystem, since
that is the source of the non-UTF-8 path data anyhow.

This adds some tests for creating and looking up branches with
messy Unicode names.  Also, this takes the helper function that
was previously internal to `git_repository_init` and makes it
into `git_path_does_fs_decompose_unicode` which is a useful in
tests to understand what the expected results should be.
Allow cl_repo_get_bool to work with missing key

One of the test helpers provides a quick way for looking up a
boolean key.  But if the key way missing completely, the check
would actually raise an error.  Given the way we use this helper,
if the key is missing, this should just return false, I think.
Don't always test composed-insensitive lookups

Only on a filesystem that is composed/decomposed insensitive,
should be testing that a branch can be looked up by the opposite
form and still work correctly.