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.
MidnightBSD may also not have strnlen
Merge pull request #2309 from jacquesg/midnightbsd

MidnightBSD may also not have strnlen
commit: safer commit creation with reference update

The current version of the commit creation and amend function are unsafe
to use when passing the update_ref parameter, as they do not check that
the reference at the moment of update points to what the user expects.

Make sure that we're moving history forward when we ask the library to
update the reference for us by checking that the first parent of the new
commit is the current value of the reference. We also make sure that the
ref we're updating hasn't moved between the read and the write.

Similarly, when amending a commit, make sure that the current tip of the
branch is the commit we're amending.
tests: Introduce count_config_entries_match() helper
Unquiet CMake output

The point of this phase is to know what we have and not. Show the user a
clear indication of what we have.