Skip to content

Commit e7da938

Browse files
pks-tgitster
authored andcommitted
global: introduce USE_THE_REPOSITORY_VARIABLE macro
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7abbca0 commit e7da938

File tree

160 files changed

+347
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+347
-3
lines changed

add-interactive.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "add-interactive.h"
35
#include "color.h"

add-patch.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "add-interactive.h"
35
#include "advice.h"

apply.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*
88
*/
99

10+
#define USE_THE_REPOSITORY_VARIABLE
11+
1012
#include "git-compat-util.h"
1113
#include "abspath.h"
1214
#include "base85.h"

archive-tar.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (c) 2005, 2006 Rene Scharfe
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "config.h"
69
#include "gettext.h"

archive-zip.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (c) 2006 Rene Scharfe
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "config.h"
69
#include "archive.h"

archive.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "abspath.h"
35
#include "config.h"

attr.c

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* an insanely large number of attributes.
77
*/
88

9+
#define USE_THE_REPOSITORY_VARIABLE
10+
911
#include "git-compat-util.h"
1012
#include "config.h"
1113
#include "environment.h"

bisect.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "commit.h"

blame.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "refs.h"
35
#include "object-store-ll.h"

branch.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "advice.h"
35
#include "config.h"

builtin.h

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#ifndef BUILTIN_H
22
#define BUILTIN_H
33

4+
/*
5+
* TODO: Almost all of our builtins access `the_repository` by necessity
6+
* because they do not get passed a pointer to it. We should adapt the function
7+
* signature of those main functions to accept a `struct repository *` and then
8+
* remove the macro here.
9+
*/
10+
#define USE_THE_REPOSITORY_VARIABLE
11+
412
#include "git-compat-util.h"
513

614
/*

builtin/blame.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* See COPYING for licensing conditions
66
*/
77

8-
#include "git-compat-util.h"
8+
#include "builtin.h"
99
#include "config.h"
1010
#include "color.h"
1111
#include "builtin.h"

builtin/log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (C) Copyright 2006 Linus Torvalds
55
* 2006 Junio Hamano
66
*/
7-
#include "git-compat-util.h"
7+
#include "builtin.h"
88
#include "abspath.h"
99
#include "config.h"
1010
#include "environment.h"

bulk-checkin.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (c) 2011, Google Inc.
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "bulk-checkin.h"
69
#include "environment.h"

bundle-uri.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "bundle-uri.h"
35
#include "bundle.h"

bundle.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "lockfile.h"
35
#include "bundle.h"

cache-tree.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "environment.h"
35
#include "hex.h"

checkout.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "object-name.h"
35
#include "remote.h"

chunk-format.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "chunk-format.h"
35
#include "csum-file.h"

combine-diff.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "object-store-ll.h"
35
#include "commit.h"

commit-graph.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "csum-file.h"

commit-reach.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "commit.h"
35
#include "commit-graph.h"

commit.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "tag.h"
35
#include "commit.h"

common-main.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "exec-cmd.h"
35
#include "gettext.h"

compat/win32/trace2_win32_process_info.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "../../git-compat-util.h"
24
#include "../../json-writer.h"
35
#include "../../repository.h"

config.c

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Copyright (C) Johannes Schindelin, 2005
66
*
77
*/
8+
9+
#define USE_THE_REPOSITORY_VARIABLE
10+
811
#include "git-compat-util.h"
912
#include "abspath.h"
1013
#include "advice.h"

connected.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "gettext.h"
35
#include "hex.h"

convert.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "advice.h"
35
#include "config.h"

csum-file.c

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* files. Useful when you write a file that you want to be
88
* able to verify hasn't been messed with afterwards.
99
*/
10+
11+
#define USE_THE_REPOSITORY_VARIABLE
12+
1013
#include "git-compat-util.h"
1114
#include "progress.h"
1215
#include "csum-file.h"

delta-islands.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "object.h"
35
#include "commit.h"

diagnose.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "diagnose.h"
35
#include "compat/disk.h"

diff-lib.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (C) 2005 Junio C Hamano
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "commit.h"
69
#include "diff.h"

diff.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (C) 2005 Junio C Hamano
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "abspath.h"
69
#include "base85.h"

diffcore-break.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (C) 2005 Junio C Hamano
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "diffcore.h"
69
#include "hash.h"

diffcore-rename.c

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
*
33
* Copyright (C) 2005 Junio C Hamano
44
*/
5+
6+
#define USE_THE_REPOSITORY_VARIABLE
7+
58
#include "git-compat-util.h"
69
#include "diff.h"
710
#include "diffcore.h"

dir.c

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Copyright (C) Linus Torvalds, 2005-2006
66
* Junio Hamano, 2005-2006
77
*/
8+
9+
#define USE_THE_REPOSITORY_VARIABLE
10+
811
#include "git-compat-util.h"
912
#include "abspath.h"
1013
#include "config.h"

entry.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "object-store-ll.h"
35
#include "dir.h"

environment.c

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* even if you might want to know where the git directory etc
88
* are.
99
*/
10+
11+
#define USE_THE_REPOSITORY_VARIABLE
12+
1013
#include "git-compat-util.h"
1114
#include "abspath.h"
1215
#include "branch.h"

fetch-pack.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "repository.h"
35
#include "config.h"

fmt-merge-msg.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "environment.h"

fsck.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "date.h"
35
#include "dir.h"

fsmonitor-ipc.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "gettext.h"
35
#include "simple-ipc.h"

git.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "builtin.h"
24
#include "config.h"
35
#include "environment.h"

hash-lookup.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "hash.h"
35
#include "hash-lookup.h"

hash.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "hash-ll.h"
55
#include "repository.h"
66

7-
#define the_hash_algo the_repository->hash_algo
7+
#ifdef USE_THE_REPOSITORY_VARIABLE
8+
# define the_hash_algo the_repository->hash_algo
9+
#endif
810

911
#endif

help.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "builtin.h"

hex.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "hash.h"
35
#include "hex.h"

http-backend.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "environment.h"

http-push.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "environment.h"
35
#include "hex.h"

http-walker.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "repository.h"
35
#include "hex.h"

http.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "git-curl-compat.h"
35
#include "hex.h"

list-objects-filter-options.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "gettext.h"

list-objects-filter.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "dir.h"
35
#include "gettext.h"

list-objects.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "tag.h"
35
#include "commit.h"

log-tree.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "commit-reach.h"
35
#include "config.h"

0 commit comments

Comments
 (0)