1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

Merge branch 'jc/a-commands-without-the-repo'

Commands that can also work outside Git have learned to take the
repository instance "repo" when we know we are in a repository, and
NULL when we are not, in a parameter.  The uses of the_repository
variable in a few of them have been removed using the new calling
convention.

* jc/a-commands-without-the-repo:
  archive: remove the_repository global variable
  annotate: remove usage of the_repository global
  git: pass in repo to builtin based on setup_git_directory_gently
This commit is contained in:
Taylor Blau 2024-10-25 14:02:36 -04:00
commit 0ab43ed95c
4 changed files with 10 additions and 10 deletions

View file

@ -385,7 +385,8 @@ int cmd_add(int argc,
char *ps_matched = NULL; char *ps_matched = NULL;
struct lock_file lock_file = LOCK_INIT; struct lock_file lock_file = LOCK_INIT;
repo_config(repo, add_config, NULL); if (repo)
repo_config(repo, add_config, NULL);
argc = parse_options(argc, argv, prefix, builtin_add_options, argc = parse_options(argc, argv, prefix, builtin_add_options,
builtin_add_usage, PARSE_OPT_KEEP_ARGV0); builtin_add_usage, PARSE_OPT_KEEP_ARGV0);

View file

@ -4,7 +4,6 @@
* Copyright (C) 2006 Ryan Anderson * Copyright (C) 2006 Ryan Anderson
*/ */
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h" #include "git-compat-util.h"
#include "builtin.h" #include "builtin.h"
#include "strvec.h" #include "strvec.h"
@ -12,7 +11,7 @@
int cmd_annotate(int argc, int cmd_annotate(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
struct strvec args = STRVEC_INIT; struct strvec args = STRVEC_INIT;
const char **args_copy; const char **args_copy;
@ -29,7 +28,7 @@ int cmd_annotate(int argc,
CALLOC_ARRAY(args_copy, args.nr + 1); CALLOC_ARRAY(args_copy, args.nr + 1);
COPY_ARRAY(args_copy, args.v, args.nr); COPY_ARRAY(args_copy, args.v, args.nr);
ret = cmd_blame(args.nr, args_copy, prefix, the_repository); ret = cmd_blame(args.nr, args_copy, prefix, repo);
strvec_clear(&args); strvec_clear(&args);
free(args_copy); free(args_copy);

View file

@ -2,7 +2,6 @@
* Copyright (c) 2006 Franck Bui-Huu * Copyright (c) 2006 Franck Bui-Huu
* Copyright (c) 2006 Rene Scharfe * Copyright (c) 2006 Rene Scharfe
*/ */
#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "archive.h" #include "archive.h"
#include "gettext.h" #include "gettext.h"
@ -79,7 +78,7 @@ static int run_remote_archiver(int argc, const char **argv,
int cmd_archive(int argc, int cmd_archive(int argc,
const char **argv, const char **argv,
const char *prefix, const char *prefix,
struct repository *repo UNUSED) struct repository *repo)
{ {
const char *exec = "git-upload-archive"; const char *exec = "git-upload-archive";
char *output = NULL; char *output = NULL;
@ -110,7 +109,7 @@ int cmd_archive(int argc,
setvbuf(stderr, NULL, _IOLBF, BUFSIZ); setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
ret = write_archive(argc, argv, prefix, the_repository, output, 0); ret = write_archive(argc, argv, prefix, repo, output, 0);
out: out:
free(output); free(output);

7
git.c
View file

@ -444,6 +444,7 @@ static int handle_alias(int *argcp, const char ***argv)
static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo) static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
{ {
int status, help; int status, help;
int no_repo = 1;
struct stat st; struct stat st;
const char *prefix; const char *prefix;
int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY)); int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY));
@ -455,9 +456,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
if (run_setup & RUN_SETUP) { if (run_setup & RUN_SETUP) {
prefix = setup_git_directory(); prefix = setup_git_directory();
no_repo = 0;
} else if (run_setup & RUN_SETUP_GENTLY) { } else if (run_setup & RUN_SETUP_GENTLY) {
int nongit_ok; prefix = setup_git_directory_gently(&no_repo);
prefix = setup_git_directory_gently(&nongit_ok);
} else { } else {
prefix = NULL; prefix = NULL;
} }
@ -480,7 +481,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
trace2_cmd_name(p->cmd); trace2_cmd_name(p->cmd);
validate_cache_entries(repo->index); validate_cache_entries(repo->index);
status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL); status = p->fn(argc, argv, prefix, no_repo ? NULL : repo);
validate_cache_entries(repo->index); validate_cache_entries(repo->index);
if (status) if (status)