diff mbox series

[v3,09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro

Message ID 7e023a335f500658b09a0037aee48eff06c668f8.1718347699.git.ps@pks.im (mailing list archive)
State Accepted
Commit e7da9385708accf518a80a1e17969020fb361048
Headers show
Series Introduce `USE_THE_REPOSITORY_VARIABLE` macro | expand

Commit Message

Patrick Steinhardt June 14, 2024, 6:50 a.m. UTC
Use of the `the_repository` variable is deprecated nowadays, and we
slowly but steadily convert the codebase to not use it anymore. Instead,
callers should be passing down the repository to work on via parameters.

It is hard though to prove that a given code unit does not use this
variable anymore. The most trivial case, merely demonstrating that there
is no direct use of `the_repository`, is already a bit of a pain during
code reviews as the reviewer needs to manually verify claims made by the
patch author. The bigger problem though is that we have many interfaces
that implicitly rely on `the_repository`.

Introduce a new `USE_THE_REPOSITORY_VARIABLE` macro that allows code
units to opt into usage of `the_repository`. The intent of this macro is
to demonstrate that a certain code unit does not use this variable
anymore, and to keep it from new dependencies on it in future changes,
be it explicit or implicit

For now, the macro only guards `the_repository` itself as well as
`the_hash_algo`. There are many more known interfaces where we have an
implicit dependency on `the_repository`, but those are not guarded at
the current point in time. Over time though, we should start to add
guards as required (or even better, just remove them).

Define the macro as required in our code units. As expected, most of our
code still relies on the global variable. Nearly all of our builtins
rely on the variable as there is no way yet to pass `the_repository` to
their entry point. For now, declare the macro in "biultin.h" to keep the
required changes at least a little bit more contained.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 add-interactive.c                            | 2 ++
 add-patch.c                                  | 2 ++
 apply.c                                      | 2 ++
 archive-tar.c                                | 3 +++
 archive-zip.c                                | 3 +++
 archive.c                                    | 2 ++
 attr.c                                       | 2 ++
 bisect.c                                     | 2 ++
 blame.c                                      | 2 ++
 branch.c                                     | 2 ++
 builtin.h                                    | 8 ++++++++
 builtin/blame.c                              | 2 +-
 builtin/log.c                                | 2 +-
 bulk-checkin.c                               | 3 +++
 bundle-uri.c                                 | 2 ++
 bundle.c                                     | 2 ++
 cache-tree.c                                 | 2 ++
 checkout.c                                   | 2 ++
 chunk-format.c                               | 2 ++
 combine-diff.c                               | 2 ++
 commit-graph.c                               | 2 ++
 commit-reach.c                               | 2 ++
 commit.c                                     | 2 ++
 common-main.c                                | 2 ++
 compat/win32/trace2_win32_process_info.c     | 2 ++
 config.c                                     | 3 +++
 connected.c                                  | 2 ++
 convert.c                                    | 2 ++
 csum-file.c                                  | 3 +++
 delta-islands.c                              | 2 ++
 diagnose.c                                   | 2 ++
 diff-lib.c                                   | 3 +++
 diff.c                                       | 3 +++
 diffcore-break.c                             | 3 +++
 diffcore-rename.c                            | 3 +++
 dir.c                                        | 3 +++
 entry.c                                      | 2 ++
 environment.c                                | 3 +++
 fetch-pack.c                                 | 2 ++
 fmt-merge-msg.c                              | 2 ++
 fsck.c                                       | 2 ++
 fsmonitor-ipc.c                              | 2 ++
 git.c                                        | 2 ++
 hash-lookup.c                                | 2 ++
 hash.h                                       | 4 +++-
 help.c                                       | 2 ++
 hex.c                                        | 2 ++
 http-backend.c                               | 2 ++
 http-push.c                                  | 2 ++
 http-walker.c                                | 2 ++
 http.c                                       | 2 ++
 list-objects-filter-options.c                | 2 ++
 list-objects-filter.c                        | 2 ++
 list-objects.c                               | 2 ++
 log-tree.c                                   | 2 ++
 loose.c                                      | 2 ++
 ls-refs.c                                    | 2 ++
 mailmap.c                                    | 2 ++
 match-trees.c                                | 2 ++
 merge-blobs.c                                | 2 ++
 merge-ort.c                                  | 2 ++
 merge-recursive.c                            | 3 +++
 merge.c                                      | 2 ++
 midx-write.c                                 | 2 ++
 midx.c                                       | 2 ++
 negotiator/default.c                         | 2 ++
 negotiator/skipping.c                        | 2 ++
 notes-cache.c                                | 2 ++
 notes-merge.c                                | 2 ++
 notes-utils.c                                | 2 ++
 notes.c                                      | 2 ++
 object-file-convert.c                        | 2 ++
 object-file.c                                | 3 +++
 object-name.c                                | 2 ++
 object.c                                     | 2 ++
 oid-array.c                                  | 2 ++
 oss-fuzz/fuzz-commit-graph.c                 | 2 ++
 pack-bitmap-write.c                          | 2 ++
 pack-bitmap.c                                | 2 ++
 pack-check.c                                 | 2 ++
 pack-revindex.c                              | 2 ++
 pack-write.c                                 | 2 ++
 packfile.c                                   | 2 ++
 parse-options-cb.c                           | 2 ++
 path.c                                       | 3 +++
 pathspec.c                                   | 2 ++
 pretty.c                                     | 2 ++
 progress.c                                   | 2 ++
 promisor-remote.c                            | 2 ++
 range-diff.c                                 | 2 ++
 reachable.c                                  | 2 ++
 read-cache.c                                 | 3 +++
 rebase-interactive.c                         | 2 ++
 ref-filter.c                                 | 2 ++
 reflog-walk.c                                | 2 ++
 reflog.c                                     | 2 ++
 refs.c                                       | 2 ++
 refs/files-backend.c                         | 2 ++
 refs/packed-backend.c                        | 2 ++
 refs/reftable-backend.c                      | 2 ++
 refspec.c                                    | 2 ++
 remote-curl.c                                | 2 ++
 remote.c                                     | 2 ++
 repository.c                                 | 8 ++++++++
 repository.h                                 | 2 ++
 rerere.c                                     | 2 ++
 reset.c                                      | 2 ++
 resolve-undo.c                               | 2 ++
 revision.c                                   | 2 ++
 run-command.c                                | 2 ++
 scalar.c                                     | 2 ++
 send-pack.c                                  | 2 ++
 sequencer.c                                  | 2 ++
 serve.c                                      | 2 ++
 server-info.c                                | 2 ++
 setup.c                                      | 2 ++
 shallow.c                                    | 2 ++
 split-index.c                                | 2 ++
 streaming.c                                  | 3 +++
 submodule-config.c                           | 2 ++
 submodule.c                                  | 2 ++
 t/helper/test-bitmap.c                       | 2 ++
 t/helper/test-bloom.c                        | 2 ++
 t/helper/test-cache-tree.c                   | 2 ++
 t/helper/test-dump-cache-tree.c              | 2 ++
 t/helper/test-dump-fsmonitor.c               | 2 ++
 t/helper/test-dump-split-index.c             | 2 ++
 t/helper/test-dump-untracked-cache.c         | 2 ++
 t/helper/test-find-pack.c                    | 2 ++
 t/helper/test-fsmonitor-client.c             | 2 ++
 t/helper/test-lazy-init-name-hash.c          | 2 ++
 t/helper/test-match-trees.c                  | 2 ++
 t/helper/test-oidmap.c                       | 2 ++
 t/helper/test-pack-mtimes.c                  | 2 ++
 t/helper/test-reach.c                        | 2 ++
 t/helper/test-read-cache.c                   | 2 ++
 t/helper/test-read-graph.c                   | 2 ++
 t/helper/test-read-midx.c                    | 2 ++
 t/helper/test-ref-store.c                    | 2 ++
 t/helper/test-repository.c                   | 2 ++
 t/helper/test-revision-walking.c             | 2 ++
 t/helper/test-scrap-cache-tree.c             | 2 ++
 t/helper/test-submodule-config.c             | 2 ++
 t/helper/test-submodule-nested-repo-config.c | 2 ++
 t/helper/test-submodule.c                    | 2 ++
 t/helper/test-trace2.c                       | 2 ++
 t/helper/test-write-cache.c                  | 2 ++
 t/unit-tests/t-example-decorate.c            | 2 ++
 tag.c                                        | 2 ++
 tmp-objdir.c                                 | 2 ++
 transport-helper.c                           | 2 ++
 transport.c                                  | 2 ++
 tree-walk.c                                  | 2 ++
 tree.c                                       | 2 ++
 unpack-trees.c                               | 2 ++
 upload-pack.c                                | 2 ++
 walker.c                                     | 2 ++
 worktree.c                                   | 2 ++
 wt-status.c                                  | 2 ++
 xdiff-interface.c                            | 2 ++
 160 files changed, 347 insertions(+), 3 deletions(-)

Comments

Karthik Nayak June 17, 2024, 9:30 a.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

> Use of the `the_repository` variable is deprecated nowadays, and we
> slowly but steadily convert the codebase to not use it anymore. Instead,
> callers should be passing down the repository to work on via parameters.
>
> It is hard though to prove that a given code unit does not use this
> variable anymore. The most trivial case, merely demonstrating that there
> is no direct use of `the_repository`, is already a bit of a pain during
> code reviews as the reviewer needs to manually verify claims made by the
> patch author. The bigger problem though is that we have many interfaces
> that implicitly rely on `the_repository`.
>
> Introduce a new `USE_THE_REPOSITORY_VARIABLE` macro that allows code
> units to opt into usage of `the_repository`. The intent of this macro is
> to demonstrate that a certain code unit does not use this variable
> anymore, and to keep it from new dependencies on it in future changes,
> be it explicit or implicit
>
> For now, the macro only guards `the_repository` itself as well as
> `the_hash_algo`. There are many more known interfaces where we have an
> implicit dependency on `the_repository`, but those are not guarded at
> the current point in time. Over time though, we should start to add
> guards as required (or even better, just remove them).
>
> Define the macro as required in our code units. As expected, most of our
> code still relies on the global variable. Nearly all of our builtins
> rely on the variable as there is no way yet to pass `the_repository` to
> their entry point. For now, declare the macro in "biultin.h" to keep the

s/biultin.h/builtin.h

[snip]

> diff --git a/hash.h b/hash.h
> index 39a0164be3..cb85d26a2f 100644
> --- a/hash.h
> +++ b/hash.h
> @@ -4,6 +4,8 @@
>  #include "hash-ll.h"
>  #include "repository.h"
>
> -#define the_hash_algo the_repository->hash_algo
> +#ifdef USE_THE_REPOSITORY_VARIABLE
> +# define the_hash_algo the_repository->hash_algo

s/# define/#define/
Patrick Steinhardt June 18, 2024, 5:16 a.m. UTC | #2
On Mon, Jun 17, 2024 at 05:30:31AM -0400, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/hash.h b/hash.h
> > index 39a0164be3..cb85d26a2f 100644
> > --- a/hash.h
> > +++ b/hash.h
> > @@ -4,6 +4,8 @@
> >  #include "hash-ll.h"
> >  #include "repository.h"
> >
> > -#define the_hash_algo the_repository->hash_algo
> > +#ifdef USE_THE_REPOSITORY_VARIABLE
> > +# define the_hash_algo the_repository->hash_algo
> 
> s/# define/#define/

This is in fact intentional. We aren't strictly following this in our
codebase, but when nesting preprocessor macros into ifdefs then we often
indent the inner macros with spaces.

Patrick
Karthik Nayak June 18, 2024, 9:25 a.m. UTC | #3
Patrick Steinhardt <ps@pks.im> writes:

> On Mon, Jun 17, 2024 at 05:30:31AM -0400, Karthik Nayak wrote:
>> Patrick Steinhardt <ps@pks.im> writes:
>> > diff --git a/hash.h b/hash.h
>> > index 39a0164be3..cb85d26a2f 100644
>> > --- a/hash.h
>> > +++ b/hash.h
>> > @@ -4,6 +4,8 @@
>> >  #include "hash-ll.h"
>> >  #include "repository.h"
>> >
>> > -#define the_hash_algo the_repository->hash_algo
>> > +#ifdef USE_THE_REPOSITORY_VARIABLE
>> > +# define the_hash_algo the_repository->hash_algo
>>
>> s/# define/#define/
>
> This is in fact intentional. We aren't strictly following this in our
> codebase, but when nesting preprocessor macros into ifdefs then we often
> indent the inner macros with spaces.
>
> Patrick

That's something I didn't know. Thanks.
Junio C Hamano June 18, 2024, 3:58 p.m. UTC | #4
Karthik Nayak <karthik.188@gmail.com> writes:

>>> s/# define/#define/
>>
>> This is in fact intentional. We aren't strictly following this in our
>> codebase, but when nesting preprocessor macros into ifdefs then we often
>> indent the inner macros with spaces.
>>
>> Patrick
>
> That's something I didn't know. Thanks.

Unlike borrowed sources in compat/, in our codebase, such
indentation is minority.  IOW "often indent" -> "sometimes indent".

A quick look at an early part of git-compat-util.h would show that
even within a single file we are not consistent at all.

#if __STDC_VERSION__ - 0 < 199901L
#error "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."
#endif

#ifdef USE_MSVC_CRTDBG
#include <stdlib.h>
#include <crtdbg.h>
#endif

#define _FILE_OFFSET_BITS 64

#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define GIT_GNUC_PREREQ(maj, min) \
	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
 #define GIT_GNUC_PREREQ(maj, min) 0
#endif

#ifndef FLEX_ARRAY
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
#elif defined(__GNUC__)
# if (__GNUC__ >= 3)
#  define FLEX_ARRAY /* empty */
# else
#  define FLEX_ARRAY 0 /* older GNU extension */
# endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEX_ARRAY /* empty */
#endif
...


We may want to eventually fix this, but we need to decide what the
desirable layout is.  I am not sure if the indented version is
easier to read and maintain, but one thing that is sure is that a
mixed mess is harder than either.  In the above excerpt, you cannot
tell if I quoted everything related to FLEX_ARRAY (in other words,
if "#ifndef FLEX_ARRAY" is already closed in the excerpt) without
carefully looking.
Junio C Hamano June 18, 2024, 4:56 p.m. UTC | #5
Junio C Hamano <gitster@pobox.com> writes:

> We may want to eventually fix this, but we need to decide what the
> desirable layout is.  I am not sure if the indented version is
> easier to read and maintain, but one thing that is sure is that a
> mixed mess is harder than either.  In the above excerpt, you cannot
> tell if I quoted everything related to FLEX_ARRAY (in other words,
> if "#ifndef FLEX_ARRAY" is already closed in the excerpt) without
> carefully looking.

Here is how a patch to reindent (which is full of patch noise and
not enough value by itself) looks like.



----- >8 ---------- >8 ---------- >8 ---------- >8 -----
Subject: [PATCH] git-compat-util.h: reindent CPP directives

Karthik noticed that Patrick used a not-so-consistently-used
convention to indent the CPP directives inside #if/#else/#endif by
one extra space, which may look like a typo to an eye unfamiliar
with the convention.  Unlike compat/ with borrowed sources, we do
not use the convention very much, and even when it is used, we are
very inconsistent.

Taking git-compat-util.h as an example, here is how a "normalized"
version of that file would look like.  It makes it immediately
obvious that an unindented CPP directive (like #define and #include)
is in effect for any and all architectures, so there might be a
readability value in such a change, even though the one-time patch
noise is a bit annoying.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

use strict;
use warnings;

my $level = 0;

my %levelchange = (
	if => [0, 1],
	ifdef => [0, 1],
	ifndef => [0, 1],
	else => [-1, 0],
	elif => [-1, 0],
	endif => [-1, -1],
);

my $file_name = undef;

while (<>) {
	if (!defined $file_name || $ARGV ne $file_name) {
		$. = 0;
		$file_name = $ARGV;
		# Special case for the header files
		if ($file_name =~ /\.h$/) {
			# cause early part of a header file
			# #ifndef FILENAME_H
			# #define FILENAME_H
			# and the corresponding #endif at the end
			# not to be indented.
			$level = -1;
		} else {
			$level = 0;
		}
	}

	# Not a CPP directive? copy it out.
	if (!/^\s*#\s*(\S+)(.*)/) {
		print;
		next;
	}

	#
	my ($what, $rest) = ($1, $2);
	my $thislevel = $level;

	if (exists $levelchange{$what}) {
		$thislevel = $level + $levelchange{$what}[0];
		$level = $level + $levelchange{$what}[1];
	}

	if ($thislevel < 0) {
		$thislevel = 0;
	}
	print "#", " " x $thislevel, "$what$rest\n";
}
---
 git-compat-util.h | 528 +++++++++++++++++++++++-----------------------
 1 file changed, 264 insertions(+), 264 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index ca7678a379..dd9edb30e1 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -11,7 +11,7 @@
  * directive, but please report the details of your system to
  * git@vger.kernel.org.
  */
-#error "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."
+# error "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."
 #endif
 
 #ifdef USE_MSVC_CRTDBG
@@ -19,8 +19,8 @@
  * For these to work they must appear very early in each
  * file -- before most of the standard header files.
  */
-#include <stdlib.h>
-#include <crtdbg.h>
+# include <stdlib.h>
+# include <crtdbg.h>
 #endif
 
 struct strbuf;
@@ -41,7 +41,7 @@ struct strbuf;
 # define GIT_GNUC_PREREQ(maj, min) \
 	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
 #else
- #define GIT_GNUC_PREREQ(maj, min) 0
+# define GIT_GNUC_PREREQ(maj, min) 0
 #endif
 
 
@@ -57,23 +57,23 @@ struct strbuf;
  * here, we can fall back to use the "safer but a bit wasteful" one
  * later.
  */
-#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
-#elif defined(__GNUC__)
-# if (__GNUC__ >= 3)
+# if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
+# elif defined(__GNUC__)
+#  if (__GNUC__ >= 3)
+#   define FLEX_ARRAY /* empty */
+#  else
+#   define FLEX_ARRAY 0 /* older GNU extension */
+#  endif
+# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
 #  define FLEX_ARRAY /* empty */
-# else
-#  define FLEX_ARRAY 0 /* older GNU extension */
 # endif
-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
-# define FLEX_ARRAY /* empty */
-#endif
 
 /*
  * Otherwise, default to safer but a bit wasteful traditional style
  */
-#ifndef FLEX_ARRAY
-# define FLEX_ARRAY 1
-#endif
+# ifndef FLEX_ARRAY
+#  define FLEX_ARRAY 1
+# endif
 #endif
 
 
@@ -153,9 +153,9 @@ struct strbuf;
      (a) > maximum_unsigned_value_of_type(a) >> (shift))
 
 #ifdef __GNUC__
-#define TYPEOF(x) (__typeof__(x))
+# define TYPEOF(x) (__typeof__(x))
 #else
-#define TYPEOF(x)
+# define TYPEOF(x)
 #endif
 
 #define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
@@ -167,7 +167,7 @@ struct strbuf;
 #define decimal_length(x)	((int)(sizeof(x) * 2.56 + 0.5) + 1)
 
 #ifdef __MINGW64__
-#define _POSIX_C_SOURCE 1
+# define _POSIX_C_SOURCE 1
 #elif defined(__sun__)
  /*
   * On Solaris, when _XOPEN_EXTENDED is set, its header file
@@ -177,16 +177,16 @@ struct strbuf;
   * non XPG6 programs must be compiled with a pre-c99 compiler.
   */
 # if __STDC_VERSION__ - 0 >= 199901L
-# define _XOPEN_SOURCE 600
+#  define _XOPEN_SOURCE 600
 # else
-# define _XOPEN_SOURCE 500
+#  define _XOPEN_SOURCE 500
 # endif
 #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \
       !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \
       !defined(__TANDEM) && !defined(__QNX__) && !defined(__MirBSD__) && \
       !defined(__CYGWIN__)
-#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
-#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
+# define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
+# define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
 #endif
 #define _ALL_SOURCE 1
 #define _GNU_SOURCE 1
@@ -196,38 +196,38 @@ struct strbuf;
 #define _SGI_SOURCE 1
 
 #if GIT_GNUC_PREREQ(4, 5)
-#define UNUSED __attribute__((unused)) \
+# define UNUSED __attribute__((unused)) \
 	__attribute__((deprecated ("parameter declared as UNUSED")))
 #elif defined(__GNUC__)
-#define UNUSED __attribute__((unused)) \
+# define UNUSED __attribute__((unused)) \
 	__attribute__((deprecated))
 #else
-#define UNUSED
+# define UNUSED
 #endif
 
 #if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */
 # if !defined(_WIN32_WINNT)
 #  define _WIN32_WINNT 0x0600
 # endif
-#define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
-#include <winsock2.h>
-#ifndef NO_UNIX_SOCKETS
-#include <afunix.h>
-#endif
-#include <windows.h>
-#define GIT_WINDOWS_NATIVE
+# define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
+# include <winsock2.h>
+# ifndef NO_UNIX_SOCKETS
+#  include <afunix.h>
+# endif
+# include <windows.h>
+# define GIT_WINDOWS_NATIVE
 #endif
 
 #if defined(NO_UNIX_SOCKETS) || !defined(GIT_WINDOWS_NATIVE)
 static inline int _have_unix_sockets(void)
 {
-#if defined(NO_UNIX_SOCKETS)
+# if defined(NO_UNIX_SOCKETS)
 	return 0;
-#else
+# else
 	return 1;
-#endif
+# endif
 }
-#define have_unix_sockets _have_unix_sockets
+# define have_unix_sockets _have_unix_sockets
 #endif
 
 #include <unistd.h>
@@ -240,13 +240,13 @@ static inline int _have_unix_sockets(void)
 #include <stdbool.h>
 #include <string.h>
 #ifdef HAVE_STRINGS_H
-#include <strings.h> /* for strcasecmp() */
+# include <strings.h> /* for strcasecmp() */
 #endif
 #include <errno.h>
 #include <limits.h>
 #include <locale.h>
 #ifdef NEEDS_SYS_PARAM_H
-#include <sys/param.h>
+# include <sys/param.h>
 #endif
 #include <sys/types.h>
 #include <dirent.h>
@@ -258,15 +258,15 @@ static inline int _have_unix_sockets(void)
 #include <utime.h>
 #include <syslog.h>
 #if !defined(NO_POLL_H)
-#include <poll.h>
+# include <poll.h>
 #elif !defined(NO_SYS_POLL_H)
-#include <sys/poll.h>
+# include <sys/poll.h>
 #else
 /* Pull the compat stuff */
-#include <poll.h>
+# include <poll.h>
 #endif
 #ifdef HAVE_BSD_SYSCTL
-#include <sys/sysctl.h>
+# include <sys/sysctl.h>
 #endif
 
 /* Used by compat/win32/path-utils.h, and more */
@@ -276,44 +276,44 @@ static inline int is_xplatform_dir_sep(int c)
 }
 
 #if defined(__CYGWIN__)
-#include "compat/win32/path-utils.h"
+# include "compat/win32/path-utils.h"
 #endif
 #if defined(__MINGW32__)
 /* pull in Windows compatibility stuff */
-#include "compat/win32/path-utils.h"
-#include "compat/mingw.h"
+# include "compat/win32/path-utils.h"
+# include "compat/mingw.h"
 #elif defined(_MSC_VER)
-#include "compat/win32/path-utils.h"
-#include "compat/msvc.h"
-#else
-#include <sys/utsname.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/statvfs.h>
-#include <termios.h>
-#ifndef NO_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <sys/un.h>
-#ifndef NO_INTTYPES_H
-#include <inttypes.h>
+# include "compat/win32/path-utils.h"
+# include "compat/msvc.h"
 #else
-#include <stdint.h>
-#endif
-#ifdef HAVE_ARC4RANDOM_LIBBSD
-#include <bsd/stdlib.h>
-#endif
-#ifdef HAVE_GETRANDOM
-#include <sys/random.h>
-#endif
-#ifdef NO_INTPTR_T
+# include <sys/utsname.h>
+# include <sys/wait.h>
+# include <sys/resource.h>
+# include <sys/socket.h>
+# include <sys/ioctl.h>
+# include <sys/statvfs.h>
+# include <termios.h>
+# ifndef NO_SYS_SELECT_H
+#  include <sys/select.h>
+# endif
+# include <netinet/in.h>
+# include <netinet/tcp.h>
+# include <arpa/inet.h>
+# include <netdb.h>
+# include <pwd.h>
+# include <sys/un.h>
+# ifndef NO_INTTYPES_H
+#  include <inttypes.h>
+# else
+#  include <stdint.h>
+# endif
+# ifdef HAVE_ARC4RANDOM_LIBBSD
+#  include <bsd/stdlib.h>
+# endif
+# ifdef HAVE_GETRANDOM
+#  include <sys/random.h>
+# endif
+# ifdef NO_INTPTR_T
 /*
  * On I16LP32, ILP32 and LP64 "long" is the safe bet, however
  * on LLP86, IL33LLP64 and P64 it needs to be "long long",
@@ -323,15 +323,15 @@ static inline int is_xplatform_dir_sep(int c)
  */
 typedef long intptr_t;
 typedef unsigned long uintptr_t;
-#endif
-#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */
-#include <grp.h>
-#define _ALL_SOURCE 1
+# endif
+# undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */
+# include <grp.h>
+# define _ALL_SOURCE 1
 #endif
 
 /* used on Mac OS X */
 #ifdef PRECOMPOSE_UNICODE
-#include "compat/precompose_utf8.h"
+# include "compat/precompose_utf8.h"
 #else
 static inline const char *precompose_argv_prefix(int argc UNUSED,
 						 const char **argv UNUSED,
@@ -344,16 +344,16 @@ static inline const char *precompose_string_if_needed(const char *in)
 	return in;
 }
 
-#define probe_utf8_pathname_composition()
+# define probe_utf8_pathname_composition()
 #endif
 
 #ifdef MKDIR_WO_TRAILING_SLASH
-#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
+# define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
 int compat_mkdir_wo_trailing_slash(const char*, mode_t);
 #endif
 
 #ifdef time
-#undef time
+# undef time
 #endif
 static inline time_t git_time(time_t *tloc)
 {
@@ -384,34 +384,34 @@ static inline int git_setitimer(int which UNUSED,
 				struct itimerval *newvalue UNUSED) {
 	return 0; /* pretend success */
 }
-#undef setitimer
-#define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue)
+# undef setitimer
+# define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue)
 #endif
 
 #ifndef NO_LIBGEN_H
-#include <libgen.h>
+# include <libgen.h>
 #else
-#define basename gitbasename
+# define basename gitbasename
 char *gitbasename(char *);
-#define dirname gitdirname
+# define dirname gitdirname
 char *gitdirname(char *);
 #endif
 
 #ifndef NO_ICONV
-#include <iconv.h>
+# include <iconv.h>
 #endif
 
 #ifndef NO_OPENSSL
-#ifdef __APPLE__
-#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
-#define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
-#include <AvailabilityMacros.h>
-#undef DEPRECATED_ATTRIBUTE
-#define DEPRECATED_ATTRIBUTE
-#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
-#endif
-#include <openssl/ssl.h>
-#include <openssl/err.h>
+# ifdef __APPLE__
+#  undef __AVAILABILITY_MACROS_USES_AVAILABILITY
+#  define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
+#  include <AvailabilityMacros.h>
+#  undef DEPRECATED_ATTRIBUTE
+#  define DEPRECATED_ATTRIBUTE
+#  undef __AVAILABILITY_MACROS_USES_AVAILABILITY
+# endif
+# include <openssl/ssl.h>
+# include <openssl/err.h>
 #endif
 
 #ifdef HAVE_SYSINFO
@@ -422,22 +422,22 @@ char *gitdirname(char *);
  * not on some systems (e.g. z/OS).
  */
 #ifndef NI_MAXHOST
-#define NI_MAXHOST 1025
+# define NI_MAXHOST 1025
 #endif
 
 #ifndef NI_MAXSERV
-#define NI_MAXSERV 32
+# define NI_MAXSERV 32
 #endif
 
 /* On most systems <limits.h> would have given us this, but
  * not on some systems (e.g. GNU/Hurd).
  */
 #ifndef PATH_MAX
-#define PATH_MAX 4096
+# define PATH_MAX 4096
 #endif
 
 #ifndef NAME_MAX
-#define NAME_MAX 255
+# define NAME_MAX 255
 #endif
 
 typedef uintmax_t timestamp_t;
@@ -447,14 +447,14 @@ typedef uintmax_t timestamp_t;
 #define TIME_MIN 0
 
 #ifndef PATH_SEP
-#define PATH_SEP ':'
+# define PATH_SEP ':'
 #endif
 
 #ifdef HAVE_PATHS_H
-#include <paths.h>
+# include <paths.h>
 #endif
 #ifndef _PATH_DEFPATH
-#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
+# define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
 #endif
 
 #ifndef platform_core_config
@@ -466,12 +466,12 @@ static inline int noop_core_config(const char *var UNUSED,
 {
 	return 0;
 }
-#define platform_core_config noop_core_config
+# define platform_core_config noop_core_config
 #endif
 
 int lstat_cache_aware_rmdir(const char *path);
 #if !defined(__MINGW32__) && !defined(_MSC_VER)
-#define rmdir lstat_cache_aware_rmdir
+# define rmdir lstat_cache_aware_rmdir
 #endif
 
 #ifndef has_dos_drive_prefix
@@ -479,7 +479,7 @@ static inline int git_has_dos_drive_prefix(const char *path UNUSED)
 {
 	return 0;
 }
-#define has_dos_drive_prefix git_has_dos_drive_prefix
+# define has_dos_drive_prefix git_has_dos_drive_prefix
 #endif
 
 #ifndef skip_dos_drive_prefix
@@ -487,7 +487,7 @@ static inline int git_skip_dos_drive_prefix(char **path UNUSED)
 {
 	return 0;
 }
-#define skip_dos_drive_prefix git_skip_dos_drive_prefix
+# define skip_dos_drive_prefix git_skip_dos_drive_prefix
 #endif
 
 static inline int git_is_dir_sep(int c)
@@ -495,7 +495,7 @@ static inline int git_is_dir_sep(int c)
 	return c == '/';
 }
 #ifndef is_dir_sep
-#define is_dir_sep git_is_dir_sep
+# define is_dir_sep git_is_dir_sep
 #endif
 
 #ifndef offset_1st_component
@@ -503,20 +503,20 @@ static inline int git_offset_1st_component(const char *path)
 {
 	return is_dir_sep(path[0]);
 }
-#define offset_1st_component git_offset_1st_component
+# define offset_1st_component git_offset_1st_component
 #endif
 
 #ifndef is_valid_path
-#define is_valid_path(path) 1
+# define is_valid_path(path) 1
 #endif
 
 #ifndef is_path_owned_by_current_user
 
-#ifdef __TANDEM
-#define ROOT_UID 65535
-#else
-#define ROOT_UID 0
-#endif
+# ifdef __TANDEM
+#  define ROOT_UID 65535
+# else
+#  define ROOT_UID 0
+# endif
 
 /*
  * Do not use this function when
@@ -576,7 +576,7 @@ static inline int is_path_owned_by_current_uid(const char *path,
 	return st.st_uid == euid;
 }
 
-#define is_path_owned_by_current_user is_path_owned_by_current_uid
+# define is_path_owned_by_current_user is_path_owned_by_current_uid
 #endif
 
 #ifndef find_last_dir_sep
@@ -584,7 +584,7 @@ static inline char *git_find_last_dir_sep(const char *path)
 {
 	return strrchr(path, '/');
 }
-#define find_last_dir_sep git_find_last_dir_sep
+# define find_last_dir_sep git_find_last_dir_sep
 #endif
 
 #ifndef has_dir_sep
@@ -592,53 +592,53 @@ static inline int git_has_dir_sep(const char *path)
 {
 	return !!strchr(path, '/');
 }
-#define has_dir_sep(path) git_has_dir_sep(path)
+# define has_dir_sep(path) git_has_dir_sep(path)
 #endif
 
 #ifndef query_user_email
-#define query_user_email() NULL
+# define query_user_email() NULL
 #endif
 
 #ifdef __TANDEM
-#include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
-#include <floss.h(floss_getpwuid)>
-#ifndef NSIG
+# include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
+# include <floss.h(floss_getpwuid)>
+# ifndef NSIG
 /*
  * NonStop NSE and NSX do not provide NSIG. SIGGUARDIAN(99) is the highest
  * known, by detective work using kill -l as a list is all signals
  * instead of signal.h where it should be.
  */
-# define NSIG 100
-#endif
+#  define NSIG 100
+# endif
 #endif
 
 #if defined(__HP_cc) && (__HP_cc >= 61000)
-#define NORETURN __attribute__((noreturn))
-#define NORETURN_PTR
+# define NORETURN __attribute__((noreturn))
+# define NORETURN_PTR
 #elif defined(__GNUC__) && !defined(NO_NORETURN)
-#define NORETURN __attribute__((__noreturn__))
-#define NORETURN_PTR __attribute__((__noreturn__))
+# define NORETURN __attribute__((__noreturn__))
+# define NORETURN_PTR __attribute__((__noreturn__))
 #elif defined(_MSC_VER)
-#define NORETURN __declspec(noreturn)
-#define NORETURN_PTR
+# define NORETURN __declspec(noreturn)
+# define NORETURN_PTR
 #else
-#define NORETURN
-#define NORETURN_PTR
-#ifndef __GNUC__
-#ifndef __attribute__
-#define __attribute__(x)
-#endif
-#endif
+# define NORETURN
+# define NORETURN_PTR
+# ifndef __GNUC__
+#  ifndef __attribute__
+#   define __attribute__(x)
+#  endif
+# endif
 #endif
 
 /* The sentinel attribute is valid from gcc version 4.0 */
 #if defined(__GNUC__) && (__GNUC__ >= 4)
-#define LAST_ARG_MUST_BE_NULL __attribute__((sentinel))
+# define LAST_ARG_MUST_BE_NULL __attribute__((sentinel))
 /* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */
-#define RESULT_MUST_BE_USED __attribute__ ((warn_unused_result))
+# define RESULT_MUST_BE_USED __attribute__ ((warn_unused_result))
 #else
-#define LAST_ARG_MUST_BE_NULL
-#define RESULT_MUST_BE_USED
+# define LAST_ARG_MUST_BE_NULL
+# define RESULT_MUST_BE_USED
 #endif
 
 #define MAYBE_UNUSED __attribute__((__unused__))
@@ -660,17 +660,17 @@ void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
 #ifndef NO_OPENSSL
-#ifdef APPLE_COMMON_CRYPTO
-#include "compat/apple-common-crypto.h"
-#else
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
-#endif /* APPLE_COMMON_CRYPTO */
-#include <openssl/x509v3.h>
+# ifdef APPLE_COMMON_CRYPTO
+#  include "compat/apple-common-crypto.h"
+# else
+#  include <openssl/evp.h>
+#  include <openssl/hmac.h>
+# endif /* APPLE_COMMON_CRYPTO */
+# include <openssl/x509v3.h>
 #endif /* NO_OPENSSL */
 
 #ifdef HAVE_OPENSSL_CSPRNG
-#include <openssl/rand.h>
+# include <openssl/rand.h>
 #endif
 
 /*
@@ -683,8 +683,8 @@ static inline int const_error(void)
 {
 	return -1;
 }
-#define error(...) (error(__VA_ARGS__), const_error())
-#define error_errno(...) (error_errno(__VA_ARGS__), const_error())
+# define error(...) (error(__VA_ARGS__), const_error())
+# define error_errno(...) (error_errno(__VA_ARGS__), const_error())
 #endif
 
 typedef void (*report_fn)(const char *, va_list params);
@@ -782,32 +782,32 @@ static inline bool strip_suffix(const char *str, const char *suffix,
 
 #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
 
-#ifndef PROT_READ
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define MAP_PRIVATE 1
-#endif
+# ifndef PROT_READ
+#  define PROT_READ 1
+#  define PROT_WRITE 2
+#  define MAP_PRIVATE 1
+# endif
 
-#define mmap git_mmap
-#define munmap git_munmap
+# define mmap git_mmap
+# define munmap git_munmap
 void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
 int git_munmap(void *start, size_t length);
 
 #else /* NO_MMAP || USE_WIN32_MMAP */
 
-#include <sys/mman.h>
+# include <sys/mman.h>
 
 #endif /* NO_MMAP || USE_WIN32_MMAP */
 
 #ifdef NO_MMAP
 
 /* This value must be multiple of (pagesize * 2) */
-#define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
+# define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
 
 #else /* NO_MMAP */
 
 /* This value must be multiple of (pagesize * 2) */
-#define DEFAULT_PACKED_GIT_WINDOW_SIZE \
+# define DEFAULT_PACKED_GIT_WINDOW_SIZE \
 	(sizeof(void*) >= 8 \
 		?  1 * 1024 * 1024 * 1024 \
 		: 32 * 1024 * 1024)
@@ -815,46 +815,46 @@ int git_munmap(void *start, size_t length);
 #endif /* NO_MMAP */
 
 #ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
+# define MAP_FAILED ((void *)-1)
 #endif
 
 #ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
-#define on_disk_bytes(st) ((st).st_size)
+# define on_disk_bytes(st) ((st).st_size)
 #else
-#define on_disk_bytes(st) ((st).st_blocks * 512)
+# define on_disk_bytes(st) ((st).st_blocks * 512)
 #endif
 
 #ifdef NEEDS_MODE_TRANSLATION
-#undef S_IFMT
-#undef S_IFREG
-#undef S_IFDIR
-#undef S_IFLNK
-#undef S_IFBLK
-#undef S_IFCHR
-#undef S_IFIFO
-#undef S_IFSOCK
-#define S_IFMT   0170000
-#define S_IFREG  0100000
-#define S_IFDIR  0040000
-#define S_IFLNK  0120000
-#define S_IFBLK  0060000
-#define S_IFCHR  0020000
-#define S_IFIFO  0010000
-#define S_IFSOCK 0140000
-#ifdef stat
-#undef stat
-#endif
-#define stat(path, buf) git_stat(path, buf)
+# undef S_IFMT
+# undef S_IFREG
+# undef S_IFDIR
+# undef S_IFLNK
+# undef S_IFBLK
+# undef S_IFCHR
+# undef S_IFIFO
+# undef S_IFSOCK
+# define S_IFMT   0170000
+# define S_IFREG  0100000
+# define S_IFDIR  0040000
+# define S_IFLNK  0120000
+# define S_IFBLK  0060000
+# define S_IFCHR  0020000
+# define S_IFIFO  0010000
+# define S_IFSOCK 0140000
+# ifdef stat
+#  undef stat
+# endif
+# define stat(path, buf) git_stat(path, buf)
 int git_stat(const char *, struct stat *);
-#ifdef fstat
-#undef fstat
-#endif
-#define fstat(fd, buf) git_fstat(fd, buf)
+# ifdef fstat
+#  undef fstat
+# endif
+# define fstat(fd, buf) git_fstat(fd, buf)
 int git_fstat(int, struct stat *);
-#ifdef lstat
-#undef lstat
-#endif
-#define lstat(path, buf) git_lstat(path, buf)
+# ifdef lstat
+#  undef lstat
+# endif
+# define lstat(path, buf) git_lstat(path, buf)
 int git_lstat(const char *, struct stat *);
 #endif
 
@@ -862,67 +862,67 @@ int git_lstat(const char *, struct stat *);
 	((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256))
 
 #ifdef NO_PREAD
-#define pread git_pread
+# define pread git_pread
 ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);
 #endif
 
 #ifdef NO_SETENV
-#define setenv gitsetenv
+# define setenv gitsetenv
 int gitsetenv(const char *, const char *, int);
 #endif
 
 #ifdef NO_MKDTEMP
-#define mkdtemp gitmkdtemp
+# define mkdtemp gitmkdtemp
 char *gitmkdtemp(char *);
 #endif
 
 #ifdef NO_UNSETENV
-#define unsetenv gitunsetenv
+# define unsetenv gitunsetenv
 int gitunsetenv(const char *);
 #endif
 
 #ifdef NO_STRCASESTR
-#define strcasestr gitstrcasestr
+# define strcasestr gitstrcasestr
 char *gitstrcasestr(const char *haystack, const char *needle);
 #endif
 
 #ifdef NO_STRLCPY
-#define strlcpy gitstrlcpy
+# define strlcpy gitstrlcpy
 size_t gitstrlcpy(char *, const char *, size_t);
 #endif
 
 #ifdef NO_STRTOUMAX
-#define strtoumax gitstrtoumax
+# define strtoumax gitstrtoumax
 uintmax_t gitstrtoumax(const char *, char **, int);
-#define strtoimax gitstrtoimax
+# define strtoimax gitstrtoimax
 intmax_t gitstrtoimax(const char *, char **, int);
 #endif
 
 #ifdef NO_HSTRERROR
-#define hstrerror githstrerror
+# define hstrerror githstrerror
 const char *githstrerror(int herror);
 #endif
 
 #ifdef NO_MEMMEM
-#define memmem gitmemmem
+# define memmem gitmemmem
 void *gitmemmem(const void *haystack, size_t haystacklen,
 		const void *needle, size_t needlelen);
 #endif
 
 #ifdef OVERRIDE_STRDUP
-#ifdef strdup
-#undef strdup
-#endif
-#define strdup gitstrdup
+# ifdef strdup
+#  undef strdup
+# endif
+# define strdup gitstrdup
 char *gitstrdup(const char *s);
 #endif
 
 #ifdef NO_GETPAGESIZE
-#define getpagesize() sysconf(_SC_PAGESIZE)
+# define getpagesize() sysconf(_SC_PAGESIZE)
 #endif
 
 #ifndef O_CLOEXEC
-#define O_CLOEXEC 0
+# define O_CLOEXEC 0
 #endif
 
 #ifdef FREAD_READS_DIRECTORIES
@@ -936,34 +936,34 @@ FILE *git_fopen(const char*, const char*);
 #endif
 
 #ifdef SNPRINTF_RETURNS_BOGUS
-#ifdef snprintf
-#undef snprintf
-#endif
-#define snprintf git_snprintf
+# ifdef snprintf
+#  undef snprintf
+# endif
+# define snprintf git_snprintf
 int git_snprintf(char *str, size_t maxsize,
 		 const char *format, ...);
-#ifdef vsnprintf
-#undef vsnprintf
-#endif
-#define vsnprintf git_vsnprintf
+# ifdef vsnprintf
+#  undef vsnprintf
+# endif
+# define vsnprintf git_vsnprintf
 int git_vsnprintf(char *str, size_t maxsize,
 		  const char *format, va_list ap);
 #endif
 
 #ifdef OPEN_RETURNS_EINTR
-#undef open
-#define open git_open_with_retry
+# undef open
+# define open git_open_with_retry
 int git_open_with_retry(const char *path, int flag, ...);
 #endif
 
 #ifdef __GLIBC_PREREQ
-#if __GLIBC_PREREQ(2, 1)
-#define HAVE_STRCHRNUL
-#endif
+# if __GLIBC_PREREQ(2, 1)
+#  define HAVE_STRCHRNUL
+# endif
 #endif
 
 #ifndef HAVE_STRCHRNUL
-#define strchrnul gitstrchrnul
+# define strchrnul gitstrchrnul
 static inline char *gitstrchrnul(const char *s, int c)
 {
 	while (*s && *s != c)
@@ -981,7 +981,7 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 #endif
 
 #ifdef NO_PTHREADS
-#define atexit git_atexit
+# define atexit git_atexit
 int git_atexit(void (*handler)(void));
 #endif
 
@@ -1252,7 +1252,7 @@ static inline size_t xsize_t(off_t len)
 }
 
 #ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 256
+# define HOST_NAME_MAX 256
 #endif
 
 #include "sane-ctype.h"
@@ -1325,7 +1325,7 @@ static inline int strtol_i(char const *s, int base, int *result)
 void git_stable_qsort(void *base, size_t nmemb, size_t size,
 		      int(*compar)(const void *, const void *));
 #ifdef INTERNAL_QSORT
-#define qsort git_stable_qsort
+# define qsort git_stable_qsort
 #endif
 
 #define QSORT(base, n, compar) sane_qsort((base), (n), sizeof(*(base)), compar)
@@ -1342,7 +1342,7 @@ static inline void sane_qsort(void *base, size_t nmemb, size_t size,
 #ifndef HAVE_ISO_QSORT_S
 int git_qsort_s(void *base, size_t nmemb, size_t size,
 		int (*compar)(const void *, const void *, void *), void *ctx);
-#define qsort_s git_qsort_s
+# define qsort_s git_qsort_s
 #endif
 
 #define QSORT_S(base, n, compar, ctx) do {			\
@@ -1351,7 +1351,7 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
 } while (0)
 
 #ifndef REG_STARTEND
-#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
+# error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
 #endif
 
 static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
@@ -1365,7 +1365,7 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
 
 #ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
 int git_regcomp(regex_t *preg, const char *pattern, int cflags);
-#define regcomp git_regcomp
+# define regcomp git_regcomp
 #endif
 
 #ifndef DIR_HAS_BSD_GROUP_SEMANTICS
@@ -1375,23 +1375,23 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);
 #endif
 
 #ifdef NO_NSEC
-#undef USE_NSEC
-#define ST_CTIME_NSEC(st) 0
-#define ST_MTIME_NSEC(st) 0
+# undef USE_NSEC
+# define ST_CTIME_NSEC(st) 0
+# define ST_MTIME_NSEC(st) 0
 #else
-#ifdef USE_ST_TIMESPEC
-#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))
-#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec))
-#else
-#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
-#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
-#endif
+# ifdef USE_ST_TIMESPEC
+#  define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))
+#  define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec))
+# else
+#  define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
+#  define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
+# endif
 #endif
 
 #ifdef UNRELIABLE_FSTAT
-#define fstat_is_reliable() 0
+# define fstat_is_reliable() 0
 #else
-#define fstat_is_reliable() 1
+# define fstat_is_reliable() 1
 #endif
 
 #ifndef va_copy
@@ -1400,11 +1400,11 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);
  * pointer into the stack frame, a simple assignment will work on
  * many systems.  But let's try to be more portable.
  */
-#ifdef __va_copy
-#define va_copy(dst, src) __va_copy(dst, src)
-#else
-#define va_copy(dst, src) ((dst) = (src))
-#endif
+# ifdef __va_copy
+#  define va_copy(dst, src) __va_copy(dst, src)
+# else
+#  define va_copy(dst, src) ((dst) = (src))
+# endif
 #endif
 
 /* usage.c: only to be used for testing BUG() implementation (see test-tool) */
@@ -1425,11 +1425,11 @@ void bug_fl(const char *file, int line, const char *fmt, ...);
 } while (0)
 
 #ifndef FSYNC_METHOD_DEFAULT
-#ifdef __APPLE__
-#define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY
-#else
-#define FSYNC_METHOD_DEFAULT FSYNC_METHOD_FSYNC
-#endif
+# ifdef __APPLE__
+#  define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY
+# else
+#  define FSYNC_METHOD_DEFAULT FSYNC_METHOD_FSYNC
+# endif
 #endif
 
 #ifndef SHELL_PATH
@@ -1445,12 +1445,12 @@ static inline void git_funlockfile(FILE *fh UNUSED)
 {
 	; /* nothing */
 }
-#undef flockfile
-#undef funlockfile
-#undef getc_unlocked
-#define flockfile(fh) git_flockfile(fh)
-#define funlockfile(fh) git_funlockfile(fh)
-#define getc_unlocked(fh) getc(fh)
+# undef flockfile
+# undef funlockfile
+# undef getc_unlocked
+# define flockfile(fh) git_flockfile(fh)
+# define funlockfile(fh) git_funlockfile(fh)
+# define getc_unlocked(fh) getc(fh)
 #endif
 
 #ifdef FILENO_IS_A_MACRO
@@ -1465,7 +1465,7 @@ int git_fileno(FILE *stream);
 int git_access(const char *path, int mode);
 # ifndef COMPAT_CODE_ACCESS
 #  ifdef access
-#  undef access
+#   undef access
 #  endif
 #  define access(path, mode) git_access(path, mode)
 # endif
@@ -1510,9 +1510,9 @@ int common_exit(const char *file, int line, int code);
  */
 #ifdef SUPPRESS_ANNOTATED_LEAKS
 void unleak_memory(const void *ptr, size_t len);
-#define UNLEAK(var) unleak_memory(&(var), sizeof(var))
+# define UNLEAK(var) unleak_memory(&(var), sizeof(var))
 #else
-#define UNLEAK(var) do {} while (0)
+# define UNLEAK(var) do {} while (0)
 #endif
 
 #define z_const
@@ -1565,9 +1565,9 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)
  * everywhere.
  */
 #if defined(__GNUC__) /* clang sets this, too */
-#define OFFSETOF_VAR(ptr, member) offsetof(__typeof__(*ptr), member)
+# define OFFSETOF_VAR(ptr, member) offsetof(__typeof__(*ptr), member)
 #else /* !__GNUC__ */
-#define OFFSETOF_VAR(ptr, member) \
+# define OFFSETOF_VAR(ptr, member) \
 	((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))
 #endif /* !__GNUC__ */
Karthik Nayak June 18, 2024, 8:20 p.m. UTC | #6
Junio C Hamano <gitster@pobox.com> writes:

> Karthik Nayak <karthik.188@gmail.com> writes:
>
>>>> s/# define/#define/
>>>
>>> This is in fact intentional. We aren't strictly following this in our
>>> codebase, but when nesting preprocessor macros into ifdefs then we often
>>> indent the inner macros with spaces.
>>>
>>> Patrick
>>
>> That's something I didn't know. Thanks.
>
> Unlike borrowed sources in compat/, in our codebase, such
> indentation is minority.  IOW "often indent" -> "sometimes indent".
>
> A quick look at an early part of git-compat-util.h would show that
> even within a single file we are not consistent at all.
>
> #if __STDC_VERSION__ - 0 < 199901L
> #error "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."
> #endif
>
> #ifdef USE_MSVC_CRTDBG
> #include <stdlib.h>
> #include <crtdbg.h>
> #endif
>
> #define _FILE_OFFSET_BITS 64
>
> #if defined(__GNUC__) && defined(__GNUC_MINOR__)
> # define GIT_GNUC_PREREQ(maj, min) \
> 	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
> #else
>  #define GIT_GNUC_PREREQ(maj, min) 0
> #endif
>
> #ifndef FLEX_ARRAY
> #if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
> #elif defined(__GNUC__)
> # if (__GNUC__ >= 3)
> #  define FLEX_ARRAY /* empty */
> # else
> #  define FLEX_ARRAY 0 /* older GNU extension */
> # endif
> #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
> # define FLEX_ARRAY /* empty */
> #endif
> ...
>
>
> We may want to eventually fix this, but we need to decide what the
> desirable layout is.  I am not sure if the indented version is
> easier to read and maintain, but one thing that is sure is that a
> mixed mess is harder than either.  In the above excerpt, you cannot
> tell if I quoted everything related to FLEX_ARRAY (in other words,
> if "#ifndef FLEX_ARRAY" is already closed in the excerpt) without
> carefully looking.

Perhaps putting the options next to each other is good way to think of
about the _desired layout_.

#ifndef FLEX_ARRAY
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
#elif defined(__GNUC__)
# if (__GNUC__ >= 3)
#  define FLEX_ARRAY /* empty */
# else
#  define FLEX_ARRAY 0 /* older GNU extension */
# endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEX_ARRAY /* empty */
#endif

#ifndef FLEX_ARRAY
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
#elif defined(__GNUC__)
  #if (__GNUC__ >= 3)
    #define FLEX_ARRAY /* empty */
  #else
    #define FLEX_ARRAY 0 /* older GNU extension */
  #endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  #define FLEX_ARRAY /* empty */
#endif

Somehow I feel the latter makes it a bit easier to grasp blocks, but
overall I think its more important that we pick one and perhaps add it
to 'Documentation/CodingGuidelines'.

Also, I did look at your response patch, but will leave it for someone
with perl experience to review.
diff mbox series

Patch

diff --git a/add-interactive.c b/add-interactive.c
index a0961096cd..49042b3026 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "add-interactive.h"
 #include "color.h"
diff --git a/add-patch.c b/add-patch.c
index 86181770f2..99e037c1e2 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "add-interactive.h"
 #include "advice.h"
diff --git a/apply.c b/apply.c
index 528939abb6..ff939f908a 100644
--- a/apply.c
+++ b/apply.c
@@ -7,6 +7,8 @@ 
  *
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "base85.h"
diff --git a/archive-tar.c b/archive-tar.c
index 8ae30125f8..e7b3489e1e 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (c) 2005, 2006 Rene Scharfe
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/archive-zip.c b/archive-zip.c
index fd1d3f816d..9f32730181 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (c) 2006 Rene Scharfe
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "archive.h"
diff --git a/archive.c b/archive.c
index 5287fcdd8e..7bd60d0632 100644
--- a/archive.c
+++ b/archive.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
diff --git a/attr.c b/attr.c
index 300f994ba6..b5ed83c90e 100644
--- a/attr.c
+++ b/attr.c
@@ -6,6 +6,8 @@ 
  * an insanely large number of attributes.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
diff --git a/bisect.c b/bisect.c
index 4ea703bec1..135f94ba09 100644
--- a/bisect.c
+++ b/bisect.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
diff --git a/blame.c b/blame.c
index a80f5e2e61..d403c46a35 100644
--- a/blame.c
+++ b/blame.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "refs.h"
 #include "object-store-ll.h"
diff --git a/branch.c b/branch.c
index df5d24fec6..c887ea2151 100644
--- a/branch.c
+++ b/branch.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
diff --git a/builtin.h b/builtin.h
index 7eda9b2486..14fa017160 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,6 +1,14 @@ 
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
+/*
+ * TODO: Almost all of our builtins access `the_repository` by necessity
+ * because they do not get passed a pointer to it. We should adapt the function
+ * signature of those main functions to accept a `struct repository *` and then
+ * remove the macro here.
+ */
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 
 /*
diff --git a/builtin/blame.c b/builtin/blame.c
index e09ff0155a..de89fff3f8 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -5,7 +5,7 @@ 
  * See COPYING for licensing conditions
  */
 
-#include "git-compat-util.h"
+#include "builtin.h"
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
diff --git a/builtin/log.c b/builtin/log.c
index ccbda8a005..00305bea51 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -4,7 +4,7 @@ 
  * (C) Copyright 2006 Linus Torvalds
  *		 2006 Junio Hamano
  */
-#include "git-compat-util.h"
+#include "builtin.h"
 #include "abspath.h"
 #include "config.h"
 #include "environment.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index eb46b88637..da8673199b 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (c) 2011, Google Inc.
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "bulk-checkin.h"
 #include "environment.h"
diff --git a/bundle-uri.c b/bundle-uri.c
index 91b3319a5c..804fbcfbfa 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "bundle-uri.h"
 #include "bundle.h"
diff --git a/bundle.c b/bundle.c
index 95367c2d0a..82c285b905 100644
--- a/bundle.c
+++ b/bundle.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "lockfile.h"
 #include "bundle.h"
diff --git a/cache-tree.c b/cache-tree.c
index 3290a1b8dd..50610c3f3c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "hex.h"
diff --git a/checkout.c b/checkout.c
index cfaea4bd10..0b1cf8b40b 100644
--- a/checkout.c
+++ b/checkout.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "object-name.h"
 #include "remote.h"
diff --git a/chunk-format.c b/chunk-format.c
index cdc7f39b70..2dde24e6a3 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "chunk-format.h"
 #include "csum-file.h"
diff --git a/combine-diff.c b/combine-diff.c
index 4960d904ac..829a44e416 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "object-store-ll.h"
 #include "commit.h"
diff --git a/commit-graph.c b/commit-graph.c
index 98cbd53eea..e1070ee6e7 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "csum-file.h"
diff --git a/commit-reach.c b/commit-reach.c
index 384aee1ab3..dabc2972e4 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit.h"
 #include "commit-graph.h"
diff --git a/commit.c b/commit.c
index 1d08951007..4956803e11 100644
--- a/commit.c
+++ b/commit.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "tag.h"
 #include "commit.h"
diff --git a/common-main.c b/common-main.c
index b86f40600f..8e68ac9e42 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "exec-cmd.h"
 #include "gettext.h"
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index 3ef0936f6f..f147da706a 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../../git-compat-util.h"
 #include "../../json-writer.h"
 #include "../../repository.h"
diff --git a/config.c b/config.c
index abce05b774..7951029644 100644
--- a/config.c
+++ b/config.c
@@ -5,6 +5,9 @@ 
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
diff --git a/connected.c b/connected.c
index 8f89376dbc..87cc4b57a1 100644
--- a/connected.c
+++ b/connected.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/convert.c b/convert.c
index f2b9f01354..d8737fe0f2 100644
--- a/convert.c
+++ b/convert.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
diff --git a/csum-file.c b/csum-file.c
index f4be0804b7..8abbf01325 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -7,6 +7,9 @@ 
  * files. Useful when you write a file that you want to be
  * able to verify hasn't been messed with afterwards.
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "progress.h"
 #include "csum-file.h"
diff --git a/delta-islands.c b/delta-islands.c
index 89d51b72e3..ffe1ca2814 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "object.h"
 #include "commit.h"
diff --git a/diagnose.c b/diagnose.c
index 4d096c857f..cc2d535b60 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "diagnose.h"
 #include "compat/disk.h"
diff --git a/diff-lib.c b/diff-lib.c
index 3fb8d79fef..b0d0f711e8 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/diff.c b/diff.c
index 60d1f7be81..d4579d5f76 100644
--- a/diff.c
+++ b/diff.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "base85.h"
diff --git a/diffcore-break.c b/diffcore-break.c
index 49ba38aa7c..831b66b5c3 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "diffcore.h"
 #include "hash.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5abb958651..ae504007cf 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -2,6 +2,9 @@ 
  *
  * Copyright (C) 2005 Junio C Hamano
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
diff --git a/dir.c b/dir.c
index 5de421c29c..b7a6625ebd 100644
--- a/dir.c
+++ b/dir.c
@@ -5,6 +5,9 @@ 
  * Copyright (C) Linus Torvalds, 2005-2006
  *		 Junio Hamano, 2005-2006
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
diff --git a/entry.c b/entry.c
index b8c257f6f9..fe1f74d140 100644
--- a/entry.c
+++ b/entry.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "object-store-ll.h"
 #include "dir.h"
diff --git a/environment.c b/environment.c
index 701d515135..5cea2c9f54 100644
--- a/environment.c
+++ b/environment.c
@@ -7,6 +7,9 @@ 
  * even if you might want to know where the git directory etc
  * are.
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "branch.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index eba9e420ea..e6e14b3874 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "repository.h"
 #include "config.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 7d144b803a..b8bca89c0c 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
diff --git a/fsck.c b/fsck.c
index dd0a33028e..432996cbb6 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "date.h"
 #include "dir.h"
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 45471b5b74..f1b1631111 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "simple-ipc.h"
diff --git a/git.c b/git.c
index 683bb69194..e35af9b0e5 100644
--- a/git.c
+++ b/git.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "config.h"
 #include "environment.h"
diff --git a/hash-lookup.c b/hash-lookup.c
index 9aa6b82eb7..5f808caa51 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hash.h"
 #include "hash-lookup.h"
diff --git a/hash.h b/hash.h
index 39a0164be3..cb85d26a2f 100644
--- a/hash.h
+++ b/hash.h
@@ -4,6 +4,8 @@ 
 #include "hash-ll.h"
 #include "repository.h"
 
-#define the_hash_algo the_repository->hash_algo
+#ifdef USE_THE_REPOSITORY_VARIABLE
+# define the_hash_algo the_repository->hash_algo
+#endif
 
 #endif
diff --git a/help.c b/help.c
index 1d057aa607..10fdb1a03d 100644
--- a/help.c
+++ b/help.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/hex.c b/hex.c
index bc9e86a978..5ca78a7744 100644
--- a/hex.c
+++ b/hex.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hash.h"
 #include "hex.h"
diff --git a/http-backend.c b/http-backend.c
index 5b65287ac9..7c0b3be968 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
diff --git a/http-push.c b/http-push.c
index a97df4a1fb..7315a694aa 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "hex.h"
diff --git a/http-walker.c b/http-walker.c
index b7110b6f82..e417a7f51c 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "repository.h"
 #include "hex.h"
diff --git a/http.c b/http.c
index 67cc47d28f..6536816e81 100644
--- a/http.c
+++ b/http.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "git-curl-compat.h"
 #include "hex.h"
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index c5f363ca6f..00611107d2 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "gettext.h"
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 4346f8da45..49e2fa6f97 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "dir.h"
 #include "gettext.h"
diff --git a/list-objects.c b/list-objects.c
index 11ad8be411..985d008799 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "tag.h"
 #include "commit.h"
diff --git a/log-tree.c b/log-tree.c
index 41416de4e3..223a4d9463 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit-reach.h"
 #include "config.h"
diff --git a/loose.c b/loose.c
index f6faa6216a..a8bf772172 100644
--- a/loose.c
+++ b/loose.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hash.h"
 #include "path.h"
diff --git a/ls-refs.c b/ls-refs.c
index 398afe4ce3..2dd925b43d 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/mailmap.c b/mailmap.c
index b2efe29b3d..534a3eb4f0 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "string-list.h"
diff --git a/match-trees.c b/match-trees.c
index 50c42e2061..f17c74d483 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hex.h"
 #include "match-trees.h"
diff --git a/merge-blobs.c b/merge-blobs.c
index 2f659fd014..0ad0390fea 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "merge-ll.h"
 #include "blob.h"
diff --git a/merge-ort.c b/merge-ort.c
index eaede6cead..691db9050e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,6 +14,8 @@ 
  * "cale", "peedy", or "ins" instead of "ort"?)
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "merge-ort.h"
 
diff --git a/merge-recursive.c b/merge-recursive.c
index 8ff29ed09e..46ee364af7 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,6 +3,9 @@ 
  * Fredrik Kuivinen.
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "merge-recursive.h"
 
diff --git a/merge.c b/merge.c
index 752a937fa9..fe3efa4b24 100644
--- a/merge.c
+++ b/merge.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hash.h"
diff --git a/midx-write.c b/midx-write.c
index 55a6b63bac..9a194e8aac 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
diff --git a/midx.c b/midx.c
index 1e75f1a7eb..3992b05465 100644
--- a/midx.c
+++ b/midx.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "dir.h"
diff --git a/negotiator/default.c b/negotiator/default.c
index 518b3c43b2..e3fa5c3324 100644
--- a/negotiator/default.c
+++ b/negotiator/default.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "default.h"
 #include "../commit.h"
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index b7e008c2fd..f109928ad0 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "skipping.h"
 #include "../commit.h"
diff --git a/notes-cache.c b/notes-cache.c
index 038db01ca0..ecfdf6e43b 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "notes-cache.h"
 #include "object-store-ll.h"
diff --git a/notes-merge.c b/notes-merge.c
index 801941c2d1..d95e683414 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "commit.h"
diff --git a/notes-utils.c b/notes-utils.c
index e33aa86c4b..bca71274be 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
diff --git a/notes.c b/notes.c
index afe2e2882e..b6a13d0980 100644
--- a/notes.c
+++ b/notes.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
diff --git a/object-file-convert.c b/object-file-convert.c
index f684038f7f..958f61f094 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "strbuf.h"
diff --git a/object-file.c b/object-file.c
index 72318c8dd4..a6555ed68c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -6,6 +6,9 @@ 
  * This handles basic git object files - packing, unpacking,
  * creation etc.
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
diff --git a/object-name.c b/object-name.c
index 523af6f64f..d7509514bc 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "object-name.h"
 #include "advice.h"
diff --git a/object.c b/object.c
index 93b5d97fdb..0c0fcb76c0 100644
--- a/object.c
+++ b/object.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/oid-array.c b/oid-array.c
index 1f36651754..9cac974395 100644
--- a/oid-array.c
+++ b/oid-array.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "oid-array.h"
 #include "hash-lookup.h"
diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c
index 75e668a057..951c9c082f 100644
--- a/oss-fuzz/fuzz-commit-graph.c
+++ b/oss-fuzz/fuzz-commit-graph.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit-graph.h"
 #include "repository.h"
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 59d2e3a387..37a8ad0fb3 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 184d28f05c..7eafdce4ee 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit.h"
 #include "gettext.h"
diff --git a/pack-check.c b/pack-check.c
index e7b214fcbd..e883dae3f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "hex.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index fc63aa76a2..de922b47d2 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "pack-revindex.h"
diff --git a/pack-write.c b/pack-write.c
index eef625fa5b..d07f03d0ab 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/packfile.c b/packfile.c
index ec7312cd20..813584646f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/parse-options-cb.c b/parse-options-cb.c
index d99d688d3c..3fb7ce68ca 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "branch.h"
diff --git a/path.c b/path.c
index adfb3d3eb7..19f7684f38 100644
--- a/path.c
+++ b/path.c
@@ -1,6 +1,9 @@ 
 /*
  * Utilities for paths and pathnames
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
diff --git a/pathspec.c b/pathspec.c
index 2133b9fe60..fe1f0f41af 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "parse.h"
diff --git a/pretty.c b/pretty.c
index 22a81506b7..2c14a88abc 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
diff --git a/progress.c b/progress.c
index c83cb60bf1..0d44c18edc 100644
--- a/progress.c
+++ b/progress.c
@@ -9,6 +9,8 @@ 
  */
 
 #define GIT_TEST_PROGRESS_ONLY
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "pager.h"
 #include "progress.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 2ca7c2ae48..317e1b127f 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/range-diff.c b/range-diff.c
index c45b6d849c..5f01605550 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/reachable.c b/reachable.c
index 1224b30008..46613a6bb6 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/read-cache.c b/read-cache.c
index 085b22faf3..48bf24f87c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,6 +3,9 @@ 
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "bulk-checkin.h"
 #include "config.h"
diff --git a/rebase-interactive.c b/rebase-interactive.c
index c343e16fcd..e93b385523 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit.h"
 #include "editor.h"
diff --git a/ref-filter.c b/ref-filter.c
index f7fb0c7e0e..8c5e673fc0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/reflog-walk.c b/reflog-walk.c
index 5f09552c5c..c7070b13b0 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "commit.h"
 #include "refs.h"
diff --git a/reflog.c b/reflog.c
index 3c80950186..5ca944529b 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "object-store-ll.h"
diff --git a/refs.c b/refs.c
index 6e7caefdcf..727ed6c1d6 100644
--- a/refs.c
+++ b/refs.c
@@ -2,6 +2,8 @@ 
  * The backend-independent part of the reference module.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
diff --git a/refs/files-backend.c b/refs/files-backend.c
index b484b5880d..35931bc71e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../git-compat-util.h"
 #include "../copy.h"
 #include "../environment.h"
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 5ab1b21d10..a0666407cd 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../git-compat-util.h"
 #include "../config.h"
 #include "../dir.h"
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 57df2aba66..6e34eb2188 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../git-compat-util.h"
 #include "../abspath.h"
 #include "../chdir-notify.h"
diff --git a/refspec.c b/refspec.c
index d60932f4de..c2e3e24351 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hash.h"
diff --git a/remote-curl.c b/remote-curl.c
index 6008d7e87c..1930f83cc7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "git-curl-compat.h"
 #include "config.h"
diff --git a/remote.c b/remote.c
index 1064171085..5fab7f0970 100644
--- a/remote.c
+++ b/remote.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
diff --git a/repository.c b/repository.c
index 95d10cc4a0..9825a30899 100644
--- a/repository.c
+++ b/repository.c
@@ -16,6 +16,14 @@ 
 #include "promisor-remote.h"
 #include "refs.h"
 
+/*
+ * We do not define `USE_THE_REPOSITORY_VARIABLE` in this file because we do
+ * not want to rely on functions that implicitly use `the_repository`. This
+ * means that the `extern` declaration of `the_repository` isn't visible here,
+ * which makes sparse unhappy. We thus declare it here.
+ */
+extern struct repository *the_repository;
+
 /* The main repository */
 static struct repository the_repo;
 struct repository *the_repository = &the_repo;
diff --git a/repository.h b/repository.h
index a35cd77c35..29727edec6 100644
--- a/repository.h
+++ b/repository.h
@@ -197,7 +197,9 @@  struct repository {
 	unsigned different_commondir:1;
 };
 
+#ifdef USE_THE_REPOSITORY_VARIABLE
 extern struct repository *the_repository;
+#endif
 
 /*
  * Define a custom repository layout. Any field can be NULL, which
diff --git a/rerere.c b/rerere.c
index c7e1f8fd25..597256fa5b 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "config.h"
diff --git a/reset.c b/reset.c
index 937f11c0f4..9550dea03d 100644
--- a/reset.c
+++ b/reset.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "cache-tree.h"
 #include "gettext.h"
diff --git a/resolve-undo.c b/resolve-undo.c
index 4e6f0e4676..8c9911affb 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "dir.h"
 #include "hash.h"
diff --git a/revision.c b/revision.c
index 7ddf0f151a..40da255953 100644
--- a/revision.c
+++ b/revision.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
diff --git a/run-command.c b/run-command.c
index 31b20123d8..f5fde92b7c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "run-command.h"
 #include "environment.h"
diff --git a/scalar.c b/scalar.c
index 331b91dbdb..a1cb4b45b5 100644
--- a/scalar.c
+++ b/scalar.c
@@ -2,6 +2,8 @@ 
  * The Scalar command-line interface.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "gettext.h"
diff --git a/send-pack.c b/send-pack.c
index 37f59d4f66..b42e6986df 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
diff --git a/sequencer.c b/sequencer.c
index 823691e379..8083fe20bf 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
diff --git a/serve.c b/serve.c
index aa651b73e9..33608ea4d5 100644
--- a/serve.c
+++ b/serve.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "repository.h"
 #include "config.h"
diff --git a/server-info.c b/server-info.c
index 6feaa457c5..97e839c33d 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/setup.c b/setup.c
index 20f380825b..7e1169eb86 100644
--- a/setup.c
+++ b/setup.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "copy.h"
diff --git a/shallow.c b/shallow.c
index a0b181ba8a..31a6ca40fe 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hex.h"
 #include "repository.h"
diff --git a/split-index.c b/split-index.c
index 058a8f448e..120c8190b1 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hash.h"
diff --git a/streaming.c b/streaming.c
index 10adf625b2..38839511af 100644
--- a/streaming.c
+++ b/streaming.c
@@ -1,6 +1,9 @@ 
 /*
  * Copyright (c) 2011, Google Inc.
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "convert.h"
 #include "environment.h"
diff --git a/submodule-config.c b/submodule-config.c
index ad43a282da..9b0bb0b9f4 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "dir.h"
 #include "environment.h"
diff --git a/submodule.c b/submodule.c
index caf3aa5600..ab99a30253 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index af43ee1cb5..1f18d57007 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "git-compat-util.h"
 #include "pack-bitmap.h"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 1281e66876..f7f9b62002 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "bloom.h"
 #include "hex.h"
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index dc89ecfd71..5cdef3ebef 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 02b0b46c3f..3f0c7d0ed0 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hash.h"
 #include "hex.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 4f215fea02..1b7f37a84f 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "read-cache-ll.h"
 #include "repository.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index f472691a3c..a6720faf9c 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index 9ff67c3967..4f010d5324 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "dir.h"
 #include "hex.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index e8bd793e58..14b2b0c12c 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "object-name.h"
 #include "object-store.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 8280984d08..02bfe92e8d 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -3,6 +3,8 @@ 
  * a `git fsmonitor--daemon` daemon.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "parse-options.h"
 #include "fsmonitor-ipc.h"
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 5f33bb7b8f..40f5df4412 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "environment.h"
 #include "name-hash.h"
diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c
index d0db5ff26f..e0e2048320 100644
--- a/t/helper/test-match-trees.c
+++ b/t/helper/test-match-trees.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "match-trees.h"
diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c
index bd30244a54..c03cfa5ecf 100644
--- a/t/helper/test-oidmap.c
+++ b/t/helper/test-oidmap.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "object-name.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 67a964ef90..f8f9afbb5b 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "strbuf.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 1ba226f1f9..5dd374379c 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "commit.h"
 #include "commit-reach.h"
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index e803c43ece..d285c656bd 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "config.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8c7a83f578..d9e980d04c 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "commit-graph.h"
 #include "repository.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 4acae41bb9..83effc2b5f 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "midx.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index ad24300170..637b8b294e 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "refs.h"
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 0c7c5aa4dd..c6a074df3d 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "commit-graph.h"
 #include "commit.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index f346951bc2..071f5bd1e2 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -8,6 +8,8 @@ 
  * published by the Free Software Foundation.
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "commit.h"
 #include "diff.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 737cbe475b..64fff6e9e3 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index 4b809d9dca..cbe93f2f9e 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "config.h"
 #include "hash.h"
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index ecd40ded99..6ca069ce63 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "repository.h"
 #include "setup.h"
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index 7197969a08..22e518d229 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "test-tool-utils.h"
 #include "parse-options.h"
diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index 1adac29a57..cd955ec63e 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "strvec.h"
 #include "run-command.h"
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index 7e3da380a9..b37dd2c5d6 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
index 3c856a8cf2..a4a75db735 100644
--- a/t/unit-tests/t-example-decorate.c
+++ b/t/unit-tests/t-example-decorate.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-lib.h"
 #include "object.h"
 #include "decorate.h"
diff --git a/tag.c b/tag.c
index 52bbe50819..d24170e340 100644
--- a/tag.c
+++ b/tag.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "tag.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 3509258be5..a8e4553f27 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "tmp-objdir.h"
 #include "abspath.h"
diff --git a/transport-helper.c b/transport-helper.c
index 9820947ab2..09b3560ffd 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "transport.h"
 #include "quote.h"
diff --git a/transport.c b/transport.c
index 83ddea8fbc..b9c8827ed9 100644
--- a/transport.c
+++ b/transport.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "config.h"
diff --git a/tree-walk.c b/tree-walk.c
index 535a3a2539..a033397965 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "tree-walk.h"
 #include "dir.h"
diff --git a/tree.c b/tree.c
index 7973d3f9a8..ad86ad1ba9 100644
--- a/tree.c
+++ b/tree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hex.h"
 #include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 304ea2ed86..7dc884fafd 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "strvec.h"
diff --git a/upload-pack.c b/upload-pack.c
index b726f7a57d..0052c6a4dc 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "environment.h"
diff --git a/walker.c b/walker.c
index 946d86b04e..0fafdc97cf 100644
--- a/walker.c
+++ b/walker.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "hex.h"
diff --git a/worktree.c b/worktree.c
index 70844d023a..f3c4c8ec54 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
diff --git a/wt-status.c b/wt-status.c
index 5051f5e599..8815df419e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "advice.h"
 #include "wt-status.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 16ed8ac492..d5dc88661e 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,3 +1,5 @@ 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "gettext.h"
 #include "config.h"