Introduce `USE_THE_REPOSITORY_VARIABLE` macro
Use of the the_repository
variable is nowadays considered to be
deprecated, and over time we want to convert our codebase to stop using
it in favor of explicitly passing down the repository to functions via
parameters. This effort faces some important problems though.
-
It is hard to prove that a certain code unit does not use
the_repository
anymore when sending patch series. The reviewer has no way to verify that it's not used anymore without reading through the code itself. -
It is easy to sneak in new usages of
the_repository
by accident into a code unit that is alreadythe_repository
-clean. -
There are many functions which implicitly use
the_repository
, which is really hard to spot.
This patch series aims to address those problems by introducing a new
USE_THE_REPOSITORY_VARIABLE
macro. When unset, then the declarations
of the_repository
, the_hash_algo
and some functions that implicitly
depend on them will be hidden away. This makes it trivial to demonstrate
that a code unit is the_repository
-free by removing the definition of
any such macro.
The patch series doesn't aim to be perfect. There are still many
functions that implicitly depend on the_repository
which are not
hidden away. Those can be addressed over time, either by guarding them
as required or, even better, removing such functions altogether.
The series is structured as follows:
-
Patches 1 to 8 refactor "hash.h" such that its functions do not depend on
the_repository
anymore. As these are used almost everywhere, the whole patch series would be rather moot without such a refactoring as everything would depend onthe_repository
. -
Patch 9 introduces
USE_THE_REPOSITORY_VARIABLE
, guarding the declaration ofthe_repository
andthe_hash_algo
. -
Patch 11 merges "hash-ll.h" back into "hash.h" as the split is now mostly pointless.
-
Patches 12 to 20 refactor various users of "hex.h" to not use functions depending on
the_repository
anymore. -
Patch 21 guards declarations of functions that depend on
the_repository
in "hex.h".
The series depends on ps/ref-sotrage-migration at 25a0023f (builtin/refs: new command to migrate ref storage formats, 2024-06-06). This is moslty due to patch 10, which fixes a cyclic include that breaks the build once we merge "hash-ll.h" back into "hash.h".