Skip to content

Commit af05d67

Browse files
szedergitster
authored andcommitted
Always set *nongit_ok in setup_git_directory_gently()
setup_git_directory_gently() only modified the value of its *nongit_ok argument if we were not in a git repository. Now it will always set it to 0 when we are inside a repository. Also remove now unnecessary initializations in the callers of this function. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 660b9c3 commit af05d67

File tree

8 files changed

+16
-8
lines changed

8 files changed

+16
-8
lines changed

builtin-apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
29942994
int read_stdin = 1;
29952995
int inaccurate_eof = 0;
29962996
int errs = 0;
2997-
int is_not_gitdir = 0;
2997+
int is_not_gitdir;
29982998

29992999
const char *whitespace_option = NULL;
30003000

builtin-bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static const char *bundle_usage="git-bundle (create <bundle> <git-rev-list args>
1414
int cmd_bundle(int argc, const char **argv, const char *prefix)
1515
{
1616
struct bundle_header header;
17-
int nongit = 0;
17+
int nongit;
1818
const char *cmd, *bundle_file;
1919
int bundle_fd = -1;
2020
char buffer[PATH_MAX];

builtin-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int get_colorbool(int argc, const char **argv)
264264

265265
int cmd_config(int argc, const char **argv, const char *prefix)
266266
{
267-
int nongit = 0;
267+
int nongit;
268268
char* value;
269269
const char *file = setup_git_directory_gently(&nongit);
270270

builtin-diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ COMMON_DIFF_OPTIONS_HELP;
1616
int cmd_diff_files(int argc, const char **argv, const char *prefix)
1717
{
1818
struct rev_info rev;
19-
int nongit = 0;
19+
int nongit;
2020
int result;
2121

2222
prefix = setup_git_directory_gently(&nongit);

builtin-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
210210
int ents = 0, blobs = 0, paths = 0;
211211
const char *path = NULL;
212212
struct blobinfo blob[2];
213-
int nongit = 0;
213+
int nongit;
214214
int result = 0;
215215

216216
/*

builtin-ls-remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
3131
{
3232
int i;
3333
const char *dest = NULL;
34-
int nongit = 0;
34+
int nongit;
3535
unsigned flags = 0;
3636
const char *uploadpack = NULL;
3737
const char **pattern = NULL;

git.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ static int split_cmdline(char *cmdline, const char ***argv)
142142

143143
static int handle_alias(int *argcp, const char ***argv)
144144
{
145-
int nongit = 0, envchanged = 0, ret = 0, saved_errno = errno;
145+
int envchanged = 0, ret = 0, saved_errno = errno;
146146
const char *subdir;
147147
int count, option_count;
148148
const char** new_argv;
149149
const char *alias_command;
150150
char *alias_string;
151151

152-
subdir = setup_git_directory_gently(&nongit);
152+
subdir = setup_git_directory_gently(NULL);
153153

154154
alias_command = (*argv)[0];
155155
alias_string = alias_lookup(alias_command);

setup.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
325325
const char *gitdirenv;
326326
int len, offset;
327327

328+
/*
329+
* Let's assume that we are in a git repository.
330+
* If it turns out later that we are somewhere else, the value will be
331+
* updated accordingly.
332+
*/
333+
if (nongit_ok)
334+
*nongit_ok = 0;
335+
328336
/*
329337
* If GIT_DIR is set explicitly, we're not going
330338
* to do any discovery, but we still do repository

0 commit comments

Comments
 (0)