archive: remove the_repository global variable

As part of the effort to get rid of global state due to the global the_repository variable, replace the_repository with the repository argument that gets passed down through the builtin function. The repo might be NULL, but we should be safe in write_archive() because it detects if we are outside of a repository and calls setup_git_directory() which will error. Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Cai committed Oct 10, 2024 at 21:13 UTC 528d3e4d53dd24b9efad3213736f1d6212c80454
1 file changed +2 -3
builtin/archive.c
+2 -3
@@ -2,7 +2,6 @@
2 * Copyright (c) 2006 Franck Bui-Huu
3 * Copyright (c) 2006 Rene Scharfe
4 */
5 -#define USE_THE_REPOSITORY_VARIABLE
5 #include "builtin.h"
6 #include "archive.h"
7 #include "gettext.h"
@@ -79,7 +78,7 @@ static int run_remote_archiver(int argc, const char **argv,
78 int cmd_archive(int argc,
79 const char **argv,
80 const char *prefix,
82 - struct repository *repo UNUSED)
81 + struct repository *repo)
82 {
83 const char *exec = "git-upload-archive";
84 char *output = NULL;
@@ -110,7 +109,7 @@ int cmd_archive(int argc,
109
110 setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
111
113 - ret = write_archive(argc, argv, prefix, the_repository, output, 0);
112 + ret = write_archive(argc, argv, prefix, repo, output, 0);
113
114 out:
115 free(output);