Be more thread aware with some index updates

The index isn't really thread safe for the most part, but we can
easily be more careful and avoid double frees and the like, which
are serious problems (as opposed to a lookup which might return
the incorrect value but if the index in being updated, that is
much harder to avoid).
Fix a crash if git_remote_set_cred_acquire_cb wasn't called before connecting.

Fixes #1700.
Fix a probable leak.
Add some missing error messages.
Tab indent.
Merge branch 'ssh-cred-fix' of tiennou/libgit2

Conflicts:
	src/transports/ssh.c
Bring SSH error reporting up to base standards

The SSH error checking and reporting could still be further
improved by using the libssh2 native methods to get error info,
but at least this ensures that all error codes are checked and
translated into libgit2 error messages.
trivial whitespace fixup
Merge pull request #1717 from libgit2/arrbee/pr-1706-merged-and-cleaned

PR 1706 plus error reporting cleanups
Merge pull request #1705 from arrbee/avoid-index-double-free

Try harder not to double free index entries
Basic framework for log command
Add public API for pathspec matching

This adds a new public API for compiling pathspecs and matching
them against the working directory, the index, or a tree from the
repository.  This also reworks the pathspec internals to allow the
sharing of code between the existing internal usage of pathspec
matching and the new external API.

While this is working and the new API is ready for discussion, I
think there is still an incorrect behavior in which patterns are
always matched against the full path of an entry without taking
the subdirectories into account (so "s*" will match "subdir/file"
even though it wouldn't with core Git).  Further enhancements are
coming, but this was a good place to take a functional snapshot.
Extending log example code

This adds more command line processing to the example version of
log.  In particular, this adds the funky command line processing
that allows an arbitrary series of revisions followed by an
arbitrary number of paths and/or glob patterns.

The actual logging part still isn't implemented.
More progress on log example
rev-parse example
Add raw header access to commit API
Add basic commit formatting to log output
Fix example/log.c minor diffs with git log
fix bug with order args and no revision
more examples/log.c bug fixing