Skip to content

Commit

Permalink
global: introduce USE_THE_REPOSITORY_VARIABLE macro
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pks-t authored and gitster committed Jun 14, 2024
1 parent 7abbca0 commit e7da938
Show file tree
Hide file tree
Showing 160 changed files with 347 additions and 3 deletions.
2 changes: 2 additions & 0 deletions add-interactive.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "add-interactive.h"
#include "color.h"
Expand Down
2 changes: 2 additions & 0 deletions add-patch.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
Expand Down
2 changes: 2 additions & 0 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*
*/

#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
Expand Down
3 changes: 3 additions & 0 deletions archive-tar.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions archive-zip.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions archive.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
Expand Down
2 changes: 2 additions & 0 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions bisect.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "commit.h"
Expand Down
2 changes: 2 additions & 0 deletions blame.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "refs.h"
#include "object-store-ll.h"
Expand Down
2 changes: 2 additions & 0 deletions branch.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
Expand Down
8 changes: 8 additions & 0 deletions builtin.h
Original file line number Diff line number Diff line change
@@ -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"

/*
Expand Down
2 changes: 1 addition & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions bulk-checkin.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions bundle-uri.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "bundle-uri.h"
#include "bundle.h"
Expand Down
2 changes: 2 additions & 0 deletions bundle.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "lockfile.h"
#include "bundle.h"
Expand Down
2 changes: 2 additions & 0 deletions cache-tree.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
Expand Down
2 changes: 2 additions & 0 deletions checkout.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "object-name.h"
#include "remote.h"
Expand Down
2 changes: 2 additions & 0 deletions chunk-format.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "chunk-format.h"
#include "csum-file.h"
Expand Down
2 changes: 2 additions & 0 deletions combine-diff.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "object-store-ll.h"
#include "commit.h"
Expand Down
2 changes: 2 additions & 0 deletions commit-graph.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "csum-file.h"
Expand Down
2 changes: 2 additions & 0 deletions commit-reach.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "commit.h"
#include "commit-graph.h"
Expand Down
2 changes: 2 additions & 0 deletions commit.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
Expand Down
2 changes: 2 additions & 0 deletions common-main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "exec-cmd.h"
#include "gettext.h"
Expand Down
2 changes: 2 additions & 0 deletions compat/win32/trace2_win32_process_info.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "../../git-compat-util.h"
#include "../../json-writer.h"
#include "../../repository.h"
Expand Down
3 changes: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions connected.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
Expand Down
2 changes: 2 additions & 0 deletions convert.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
Expand Down
3 changes: 3 additions & 0 deletions csum-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions delta-islands.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "object.h"
#include "commit.h"
Expand Down
2 changes: 2 additions & 0 deletions diagnose.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "diagnose.h"
#include "compat/disk.h"
Expand Down
3 changes: 3 additions & 0 deletions diff-lib.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions diff.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions diffcore-break.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions diffcore-rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions entry.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "object-store-ll.h"
#include "dir.h"
Expand Down
3 changes: 3 additions & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions fetch-pack.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
Expand Down
2 changes: 2 additions & 0 deletions fmt-merge-msg.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
Expand Down
2 changes: 2 additions & 0 deletions fsck.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "date.h"
#include "dir.h"
Expand Down
2 changes: 2 additions & 0 deletions fsmonitor-ipc.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "gettext.h"
#include "simple-ipc.h"
Expand Down
2 changes: 2 additions & 0 deletions git.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "config.h"
#include "environment.h"
Expand Down
2 changes: 2 additions & 0 deletions hash-lookup.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "hash.h"
#include "hash-lookup.h"
Expand Down
4 changes: 3 additions & 1 deletion hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions help.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "builtin.h"
Expand Down
2 changes: 2 additions & 0 deletions hex.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "hash.h"
#include "hex.h"
Expand Down
2 changes: 2 additions & 0 deletions http-backend.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
Expand Down
2 changes: 2 additions & 0 deletions http-push.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
Expand Down
2 changes: 2 additions & 0 deletions http-walker.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "repository.h"
#include "hex.h"
Expand Down
2 changes: 2 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "hex.h"
Expand Down
2 changes: 2 additions & 0 deletions list-objects-filter-options.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
Expand Down
2 changes: 2 additions & 0 deletions list-objects-filter.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "dir.h"
#include "gettext.h"
Expand Down
2 changes: 2 additions & 0 deletions list-objects.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"
Expand Down
2 changes: 2 additions & 0 deletions log-tree.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "commit-reach.h"
#include "config.h"
Expand Down
Loading

0 comments on commit e7da938

Please sign in to comment.