Refactor git_repository_open with new options

Add a new command `git_repository_open_ext` with extended options
that control how searching for a repository will be done.  The
existing `git_repository_open` and `git_repository_discover` are
reimplemented on top of it.  We may want to change the default
behavior of `git_repository_open` but this commit does not do that.

Improve support for "gitdir" files where the work dir is separate
from the repo and support for the "separate-git-dir" config.  Also,
add support for opening repos created with `git-new-workdir` script
(although I have only confirmed that they can be opened, not that
all functions work correctly).

There are also a few minor changes that came up:

- Fix `git_path_prettify` to allow in-place prettifying.

- Fix `git_path_root` to support backslashes on Win32.  This fix
  should help many repo open/discover scenarios - it is the one
  function called when opening before prettifying the path.

- Tweak `git_config_get_string` to set the "out" pointer to NULL
  if the config value is not found.  Allows some other cleanup.

- Fix a couple places that should have been calling
  `git_repository_config__weakptr` and were not.

- Fix `cl_git_sandbox_init` clar helper to support bare repos.
revwalk: don't assume malloc succeeds
revwalk: allow pushing/hiding a reference by name

The code was already there, so factor it out and let users push an OID
by giving it a reference name. Only refs to commits are
supported. Annotated tags will throw an error.
Implement git_merge_base()

It's implemented in revwalk.c so it has access to the revision
walker's commit cache and related functions. The algorithm is the one
used by git, modified so it fits better with the library's functions.
revwalk: use merge bases to speed up processing

There is no need walk down the parents of a merge base to mark them as
uninteresting because we'll never see them. Calculate the merge bases
in prepare_walk() so mark_uninteresting() can stop at a merge base
instead of walking all the way to the root.
revwalk: add test hiding a commit without a merge base

Nothing should be hidden and this shouldn't bother the merge base
calculation.
revwalk: use a priority queue for calculating merge bases

As parents are older than their children, we're appending to the
commit list most of the time, which makes an ordered linked list quite
inefficient.

While we're there, don't sort the results list in the main loop, as
we're sorting them afterwards and it creates extra work.
Move git_merge_base() to is own header and document it
error-handling: revwalk
branch: plug leaks in git_branch_move() and _delete()
local transport: plug leak
Merge pull request #625 from carlosmn/valgrind

Plug a few leaks
branch: simplify error handling for git_branch_move()

The cleanup needs to happen anyway, so set the error code and jump
there instead of copying the code.
Merge pull request #623 from arrbee/refactor-open

Update git_repository_open
Merge remote-tracking branch 'carlosmn/revwalk-merge-base' into new-error-handling
Add support for pathspec to diff and status

This adds preliminary support for pathspecs to diff and status.
The implementation is not very optimized (it still looks at
every single file and evaluated the the pathspec match against
them), but it works.
Merge pull request #627 from arrbee/diff-with-pathspec

Diff with pathspec
repo: plug a couple of leaks