Skip to content

Commit 0ab43ed

Browse files
committed
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
2 parents dca32b8 + 528d3e4 commit 0ab43ed

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

builtin/add.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ int cmd_add(int argc,
385385
char *ps_matched = NULL;
386386
struct lock_file lock_file = LOCK_INIT;
387387

388-
repo_config(repo, add_config, NULL);
388+
if (repo)
389+
repo_config(repo, add_config, NULL);
389390

390391
argc = parse_options(argc, argv, prefix, builtin_add_options,
391392
builtin_add_usage, PARSE_OPT_KEEP_ARGV0);

builtin/annotate.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
* Copyright (C) 2006 Ryan Anderson
55
*/
66

7-
#define USE_THE_REPOSITORY_VARIABLE
87
#include "git-compat-util.h"
98
#include "builtin.h"
109
#include "strvec.h"
1110

1211
int cmd_annotate(int argc,
1312
const char **argv,
1413
const char *prefix,
15-
struct repository *repo UNUSED)
14+
struct repository *repo)
1615
{
1716
struct strvec args = STRVEC_INIT;
1817
const char **args_copy;
@@ -29,7 +28,7 @@ int cmd_annotate(int argc,
2928
CALLOC_ARRAY(args_copy, args.nr + 1);
3029
COPY_ARRAY(args_copy, args.v, args.nr);
3130

32-
ret = cmd_blame(args.nr, args_copy, prefix, the_repository);
31+
ret = cmd_blame(args.nr, args_copy, prefix, repo);
3332

3433
strvec_clear(&args);
3534
free(args_copy);

builtin/archive.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright (c) 2006 Franck Bui-Huu
33
* Copyright (c) 2006 Rene Scharfe
44
*/
5-
#define USE_THE_REPOSITORY_VARIABLE
65
#include "builtin.h"
76
#include "archive.h"
87
#include "gettext.h"
@@ -79,7 +78,7 @@ static int run_remote_archiver(int argc, const char **argv,
7978
int cmd_archive(int argc,
8079
const char **argv,
8180
const char *prefix,
82-
struct repository *repo UNUSED)
81+
struct repository *repo)
8382
{
8483
const char *exec = "git-upload-archive";
8584
char *output = NULL;
@@ -110,7 +109,7 @@ int cmd_archive(int argc,
110109

111110
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
112111

113-
ret = write_archive(argc, argv, prefix, the_repository, output, 0);
112+
ret = write_archive(argc, argv, prefix, repo, output, 0);
114113

115114
out:
116115
free(output);

git.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ static int handle_alias(int *argcp, const char ***argv)
444444
static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
445445
{
446446
int status, help;
447+
int no_repo = 1;
447448
struct stat st;
448449
const char *prefix;
449450
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
455456

456457
if (run_setup & RUN_SETUP) {
457458
prefix = setup_git_directory();
459+
no_repo = 0;
458460
} else if (run_setup & RUN_SETUP_GENTLY) {
459-
int nongit_ok;
460-
prefix = setup_git_directory_gently(&nongit_ok);
461+
prefix = setup_git_directory_gently(&no_repo);
461462
} else {
462463
prefix = NULL;
463464
}
@@ -480,7 +481,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
480481
trace2_cmd_name(p->cmd);
481482

482483
validate_cache_entries(repo->index);
483-
status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
484+
status = p->fn(argc, argv, prefix, no_repo ? NULL : repo);
484485
validate_cache_entries(repo->index);
485486

486487
if (status)

0 commit comments

Comments
 (0)