mirror of
https://github.com/git/git.git
synced 2024-12-12 03:14:11 +08:00
e7da938570
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
35 lines
764 B
C
35 lines
764 B
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
|
|
#include "test-tool.h"
|
|
#include "repository.h"
|
|
#include "setup.h"
|
|
#include "submodule-config.h"
|
|
|
|
static void die_usage(const char **argv, const char *msg)
|
|
{
|
|
fprintf(stderr, "%s\n", msg);
|
|
fprintf(stderr, "Usage: %s <submodulepath> <config name>\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
|
|
int cmd__submodule_nested_repo_config(int argc, const char **argv)
|
|
{
|
|
struct repository subrepo;
|
|
|
|
if (argc < 3)
|
|
die_usage(argv, "Wrong number of arguments.");
|
|
|
|
setup_git_directory();
|
|
|
|
if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid())) {
|
|
die_usage(argv, "Submodule not found.");
|
|
}
|
|
|
|
/* Read the config of _child_ submodules. */
|
|
print_config_from_gitmodules(&subrepo, argv[2]);
|
|
|
|
submodule_free(the_repository);
|
|
|
|
return 0;
|
|
}
|