Skip to content

Commit 633142d

Browse files
committed
Merge branch 'jn/paginate-fix'
* jn/paginate-fix: t7006 (pager): add missing TTY prerequisites merge-file: run setup_git_directory_gently() sooner var: run setup_git_directory_gently() sooner ls-remote: run setup_git_directory_gently() sooner index-pack: run setup_git_directory_gently() sooner config: run setup_git_directory_gently() sooner bundle: run setup_git_directory_gently() sooner apply: run setup_git_directory_gently() sooner grep: run setup_git_directory_gently() sooner shortlog: run setup_git_directory_gently() sooner git wrapper: allow setup_git_directory_gently() be called earlier setup: remember whether repository was found git wrapper: introduce startup_info struct Conflicts: builtin/index-pack.c
2 parents 693fefe + 41bf3bc commit 633142d

14 files changed

Lines changed: 120 additions & 47 deletions

File tree

builtin/apply.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,11 +3606,11 @@ static int option_parse_directory(const struct option *opt,
36063606
return 0;
36073607
}
36083608

3609-
int cmd_apply(int argc, const char **argv, const char *unused_prefix)
3609+
int cmd_apply(int argc, const char **argv, const char *prefix_)
36103610
{
36113611
int i;
36123612
int errs = 0;
3613-
int is_not_gitdir;
3613+
int is_not_gitdir = !startup_info->have_repository;
36143614
int binary;
36153615
int force_apply = 0;
36163616

@@ -3683,7 +3683,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
36833683
OPT_END()
36843684
};
36853685

3686-
prefix = setup_git_directory_gently(&is_not_gitdir);
3686+
prefix = prefix_;
36873687
prefix_length = prefix ? strlen(prefix) : 0;
36883688
git_config(git_apply_config, NULL);
36893689
if (apply_default_whitespace)

builtin/bundle.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ static const char builtin_bundle_usage[] =
1818
int cmd_bundle(int argc, const char **argv, const char *prefix)
1919
{
2020
struct bundle_header header;
21-
int nongit;
2221
const char *cmd, *bundle_file;
2322
int bundle_fd = -1;
2423
char buffer[PATH_MAX];
@@ -31,7 +30,6 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
3130
argc -= 2;
3231
argv += 2;
3332

34-
prefix = setup_git_directory_gently(&nongit);
3533
if (prefix && bundle_file[0] != '/') {
3634
snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
3735
bundle_file = buffer;
@@ -54,11 +52,11 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
5452
return !!list_bundle_refs(&header, argc, argv);
5553
}
5654
if (!strcmp(cmd, "create")) {
57-
if (nongit)
55+
if (!startup_info->have_repository)
5856
die("Need a repository to create a bundle.");
5957
return !!create_bundle(&header, bundle_file, argc, argv);
6058
} else if (!strcmp(cmd, "unbundle")) {
61-
if (nongit)
59+
if (!startup_info->have_repository)
6260
die("Need a repository to unbundle.");
6361
return !!unbundle(&header, bundle_fd) ||
6462
list_bundle_refs(&header, argc, argv);

builtin/config.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,10 @@ static int get_colorbool(int print)
331331
return get_colorbool_found ? 0 : 1;
332332
}
333333

334-
int cmd_config(int argc, const char **argv, const char *unused_prefix)
334+
int cmd_config(int argc, const char **argv, const char *prefix)
335335
{
336-
int nongit;
336+
int nongit = !startup_info->have_repository;
337337
char *value;
338-
const char *prefix = setup_git_directory_gently(&nongit);
339338

340339
config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);
341340

builtin/grep.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
839839
struct string_list path_list = STRING_LIST_INIT_NODUP;
840840
int i;
841841
int dummy;
842-
int nongit = 0, use_index = 1;
842+
int use_index = 1;
843843
struct option options[] = {
844844
OPT_BOOLEAN(0, "cached", &cached,
845845
"search in index instead of in the work tree"),
@@ -930,8 +930,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
930930
OPT_END()
931931
};
932932

933-
prefix = setup_git_directory_gently(&nongit);
934-
935933
/*
936934
* 'git grep -h', unlike 'git grep -h <pattern>', is a request
937935
* to show usage information and exit.
@@ -976,7 +974,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
976974
PARSE_OPT_STOP_AT_NON_OPTION |
977975
PARSE_OPT_NO_INTERNAL_HELP);
978976

979-
if (use_index && nongit)
977+
if (use_index && !startup_info->have_repository)
980978
/* die the same way as if we did it at the beginning */
981979
setup_git_directory();
982980

builtin/index-pack.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,12 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
880880
char *index_name_buf = NULL, *keep_name_buf = NULL;
881881
struct pack_idx_entry **idx_objects;
882882
unsigned char pack_sha1[20];
883-
int nongit;
884883

885884
if (argc == 2 && !strcmp(argv[1], "-h"))
886885
usage(index_pack_usage);
887886

888887
read_replace_refs = 0;
889888

890-
prefix = setup_git_directory_gently(&nongit);
891889
git_config(git_index_pack_config, NULL);
892890
if (prefix && chdir(prefix))
893891
die("Cannot come back to cwd");

builtin/ls-remote.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
3232
{
3333
int i;
3434
const char *dest = NULL;
35-
int nongit;
3635
unsigned flags = 0;
3736
int quiet = 0;
3837
const char *uploadpack = NULL;
@@ -42,8 +41,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
4241
struct transport *transport;
4342
const struct ref *ref;
4443

45-
setup_git_directory_gently(&nongit);
46-
4744
for (i = 1; i < argc; i++) {
4845
const char *arg = argv[i];
4946

builtin/merge-file.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
2828
xmparam_t xmp = {{0}};
2929
int ret = 0, i = 0, to_stdout = 0;
3030
int quiet = 0;
31-
int nongit;
3231
struct option options[] = {
3332
OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
3433
OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3),
@@ -50,8 +49,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
5049
xmp.style = 0;
5150
xmp.favor = 0;
5251

53-
prefix = setup_git_directory_gently(&nongit);
54-
if (!nongit) {
52+
if (startup_info->have_repository) {
5553
/* Read the configuration file */
5654
git_config(git_xmerge_config, NULL);
5755
if (0 <= git_xmerge_style)

builtin/shortlog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
249249
{
250250
static struct shortlog log;
251251
static struct rev_info rev;
252-
int nongit;
252+
int nongit = !startup_info->have_repository;
253253

254254
static const struct option options[] = {
255255
OPT_BOOLEAN('n', "numbered", &log.sort_by_number,
@@ -265,7 +265,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
265265

266266
struct parse_opt_ctx_t ctx;
267267

268-
prefix = setup_git_directory_gently(&nongit);
269268
git_config(git_default_config, NULL);
270269
shortlog_init(&log);
271270
init_revisions(&rev, prefix);

builtin/var.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,9 @@ static int show_config(const char *var, const char *value, void *cb)
7474

7575
int cmd_var(int argc, const char **argv, const char *prefix)
7676
{
77-
const char *val;
78-
int nongit;
79-
if (argc != 2) {
77+
const char *val = NULL;
78+
if (argc != 2)
8079
usage(var_usage);
81-
}
82-
83-
setup_git_directory_gently(&nongit);
84-
val = NULL;
8580

8681
if (strcmp(argv[1], "-l") == 0) {
8782
git_config(show_config, NULL);

cache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,12 @@ int split_cmdline(char *cmdline, const char ***argv);
11021102
/* Takes a negative value returned by split_cmdline */
11031103
const char *split_cmdline_strerror(int cmdline_errno);
11041104

1105+
/* git.c */
1106+
struct startup_info {
1107+
int have_repository;
1108+
};
1109+
extern struct startup_info *startup_info;
1110+
11051111
/* builtin/merge.c */
11061112
int checkout_fast_forward(const unsigned char *from, const unsigned char *to);
11071113

0 commit comments

Comments
 (0)