Skip to content

Commit 237e6db

Browse files
committed
Merge branch 'jk/startup-info' into maint
The startup_info data, which records if we are working inside a repository (among other things), are now uniformly available to Git subcommand implementations, and Git avoids attempting to touch references when we are not in a repository. * jk/startup-info: use setup_git_directory() in test-* programs grep: turn off gitlink detection for --no-index mailmap: do not resolve blobs in a non-repository remote: don't resolve HEAD in non-repository setup: set startup_info->have_repository more reliably setup: make startup_info available everywhere
2 parents f55f97c + 11e6b3f commit 237e6db

13 files changed

+54
-26
lines changed

builtin/grep.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,14 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
522522
}
523523

524524
static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
525-
int exc_std)
525+
int exc_std, int use_index)
526526
{
527527
struct dir_struct dir;
528528
int i, hit = 0;
529529

530530
memset(&dir, 0, sizeof(dir));
531+
if (!use_index)
532+
dir.flags |= DIR_NO_GITLINKS;
531533
if (exc_std)
532534
setup_standard_excludes(&dir);
533535

@@ -902,7 +904,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
902904
int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
903905
if (list.nr)
904906
die(_("--no-index or --untracked cannot be used with revs."));
905-
hit = grep_directory(&opt, &pathspec, use_exclude);
907+
hit = grep_directory(&opt, &pathspec, use_exclude, use_index);
906908
} else if (0 <= opt_exclude) {
907909
die(_("--[no-]exclude-standard cannot be used for tracked contents."));
908910
} else if (!list.nr) {

builtin/init-db.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
322322
set_git_dir(real_path(git_dir));
323323
git_link = NULL;
324324
}
325+
startup_info->have_repository = 1;
325326
return 0;
326327
}
327328

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ int split_cmdline(char *cmdline, const char ***argv);
17711771
/* Takes a negative value returned by split_cmdline */
17721772
const char *split_cmdline_strerror(int cmdline_errno);
17731773

1774-
/* git.c */
1774+
/* setup.c */
17751775
struct startup_info {
17761776
int have_repository;
17771777
const char *prefix;

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ int grafts_replace_parents = 1;
6464
int core_apply_sparse_checkout;
6565
int merge_log_config = -1;
6666
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
67-
struct startup_info *startup_info;
6867
unsigned long pack_size_limit_cfg;
6968

7069
#ifndef PROTECT_HFS_DEFAULT

git.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const char git_more_info_string[] =
1515
"concept guides. See 'git help <command>' or 'git help <concept>'\n"
1616
"to read about a specific subcommand or concept.");
1717

18-
static struct startup_info git_startup_info;
1918
static int use_pager = -1;
2019
static char *orig_cwd;
2120
static const char *env_names[] = {
@@ -637,8 +636,6 @@ int main(int argc, char **av)
637636
const char *cmd;
638637
int done_help = 0;
639638

640-
startup_info = &git_startup_info;
641-
642639
cmd = git_extract_argv0_path(argv[0]);
643640
if (!cmd)
644641
cmd = "git-help";

mailmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ int read_mailmap(struct string_list *map, char **repo_abbrev)
250250
git_mailmap_blob = "HEAD:.mailmap";
251251

252252
err |= read_mailmap_file(map, ".mailmap", repo_abbrev);
253-
err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev);
253+
if (startup_info->have_repository)
254+
err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev);
254255
err |= read_mailmap_file(map, git_mailmap_file, repo_abbrev);
255256
return err;
256257
}

remote.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,19 @@ static void read_config(void)
455455
{
456456
static int loaded;
457457
struct object_id oid;
458-
const char *head_ref;
459458
int flag;
460459

461460
if (loaded)
462461
return;
463462
loaded = 1;
464463

465464
current_branch = NULL;
466-
head_ref = resolve_ref_unsafe("HEAD", 0, oid.hash, &flag);
467-
if (head_ref && (flag & REF_ISSYMREF) &&
468-
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
469-
current_branch = make_branch(head_ref, 0);
465+
if (startup_info->have_repository) {
466+
const char *head_ref = resolve_ref_unsafe("HEAD", 0, oid.hash, &flag);
467+
if (head_ref && (flag & REF_ISSYMREF) &&
468+
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
469+
current_branch = make_branch(head_ref, 0);
470+
}
470471
}
471472
git_config(handle_config, NULL);
472473
alias_all_urls();

setup.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ static int inside_work_tree = -1;
77
static int work_tree_config_is_bogus;
88
static struct string_list unknown_extensions = STRING_LIST_INIT_DUP;
99

10+
static struct startup_info the_startup_info;
11+
struct startup_info *startup_info = &the_startup_info;
12+
1013
/*
1114
* The input parameter must contain an absolute path, and it must already be
1215
* normalized.
@@ -905,10 +908,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
905908
else
906909
setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
907910

908-
if (startup_info) {
909-
startup_info->have_repository = !nongit_ok || !*nongit_ok;
910-
startup_info->prefix = prefix;
911-
}
911+
startup_info->have_repository = !nongit_ok || !*nongit_ok;
912+
startup_info->prefix = prefix;
913+
912914
return prefix;
913915
}
914916

@@ -984,7 +986,9 @@ int check_repository_format_version(const char *var, const char *value, void *cb
984986

985987
int check_repository_format(void)
986988
{
987-
return check_repository_format_gently(get_git_dir(), NULL);
989+
check_repository_format_gently(get_git_dir(), NULL);
990+
startup_info->have_repository = 1;
991+
return 0;
988992
}
989993

990994
/*

sha1_name.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,9 +1353,6 @@ static char *resolve_relative_path(const char *rel)
13531353
if (!starts_with(rel, "./") && !starts_with(rel, "../"))
13541354
return NULL;
13551355

1356-
if (!startup_info)
1357-
die("BUG: startup_info struct is not initialized.");
1358-
13591356
if (!is_inside_work_tree())
13601357
die("relative path syntax can't be used outside working tree.");
13611358

t/t1506-rev-parse-diagnosis.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ test_expect_success 'relative path when cwd is outside worktree' '
166166
grep "relative path syntax can.t be used outside working tree." error
167167
'
168168

169-
test_expect_success 'relative path when startup_info is NULL' '
170-
test_must_fail test-match-trees HEAD:./file.txt HEAD:./file.txt 2>error &&
171-
grep "BUG: startup_info struct is not initialized." error
172-
'
173-
174169
test_expect_success '<commit>:file correctly diagnosed after a pathname' '
175170
test_must_fail git rev-parse file.txt HEAD:file.txt 1>actual 2>error &&
176171
test_i18ngrep ! "exists on disk" error &&

0 commit comments

Comments
 (0)