]> git.ipfire.org Git - thirdparty/git.git/commit - setup.c
setup: refactor repo format reading and verification
authorJeff King <peff@peff.net>
Fri, 11 Mar 2016 22:37:07 +0000 (17:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Mar 2016 23:02:23 +0000 (15:02 -0800)
commit2cc7c2c737f2af16915b3d6cb6245111e1349609
treea1940e2efd97afff6a2c881b4254b3a0d23e7bba
parent801818680ab907abf347fbdc48623f43a49beee9
setup: refactor repo format reading and verification

When we want to know if we're in a git repository of
reasonable vintage, we can call check_repository_format_gently(),
which does three things:

  1. Reads the config from the .git/config file.

  2. Verifies that the version info we read is sane.

  3. Writes some global variables based on this.

There are a few things we could improve here.

One is that steps 1 and 3 happen together. So if the
verification in step 2 fails, we still clobber the global
variables. This is especially bad if we go on to try another
repository directory; we may end up with a state of mixed
config variables.

The second is there's no way to ask about the repository
version for anything besides the main repository we're in.
git-init wants to do this, and it's possible that we would
want to start doing so for submodules (e.g., to find out
which ref backend they're using).

We can improve both by splitting the first two steps into
separate functions. Now check_repository_format_gently()
calls out to steps 1 and 2, and does 3 only if step 2
succeeds.

Note that the public interface for read_repository_format()
and what check_repository_format_gently() needs from it are
not quite the same, leading us to have an extra
read_repository_format_1() helper. The extra needs from
check_repository_format_gently() will go away in a future
patch, and we can simplify this then to just the public
interface.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
setup.c