path.c: update validate_headref to handle db ref backends

Update validate_headref to take an extra path argument to specify
which directory to read the git data from. If NULL then as before
this means we try to use the cwd.

Change the two callers to pass the optional path as argument.

In validate_headref, try to read the db configuration from "config"
and if this is possible, check if core.db_repo_name is set or not.

IF core.db-repo-name is set then we treat this as sufficient proof that
the directory is valid and implicitely that HEAD exists in the database.

If core.db-repo-name does NOT exist we fall back to the original check
to try to open the "HEAD" file and check that it looks sane-ish.

Change-Id: I9f4b695d3e4935f4a3e655a74c0ec280bb5ba8c1
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>