* [PATCH] Remove .git auto detection from setup_git_env()
@ 2010-02-05 11:47 Nguyễn Thái Ngọc Duy
2010-02-05 15:12 ` Jeff King
0 siblings, 1 reply; 5+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-05 11:47 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
When GIT_DIR environment variable is not specified, .git will be
searched if a repository is needed. Currently this can be done in two
places: setup_git_directory_gently() and setup_git_env().
The one in setup_git_env() is no longer correct and should IMHO have
been removed since the introduction of setup_git_directory_gently() in
d288a70. Having two ways of auto detection may lead to obscure errors
because .git may be misdetected by setup_git_env(),
automatically called via git_path(), which is all over the place.
This patch makes setup_git_env() die if GIT_DIR is not explictly
set. That's setup_git_directory_gently()'s job. If you ever want to
touch things inside $GIT_DIR, you should have already called
setup_git_directory_gently().
This patch breaks commands (in a good way) and obviously not for
mainline. I still have to go through "make test" to see how many are
impacted. But I think this is a good change. Am I missing something?
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
environment.c | 4 +---
setup.c | 4 +++-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/environment.c b/environment.c
index 739ec27..b609569 100644
--- a/environment.c
+++ b/environment.c
@@ -67,9 +67,7 @@ static void setup_git_env(void)
{
git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir)
- git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
- if (!git_dir)
- git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ die("GIT_DIR not properly set");
git_object_dir = getenv(DB_ENVIRONMENT);
if (!git_object_dir) {
git_object_dir = xmalloc(strlen(git_dir) + 9);
diff --git a/setup.c b/setup.c
index 710e2f3..ae1ba52 100644
--- a/setup.c
+++ b/setup.c
@@ -396,8 +396,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
die("Repository setup failed");
break;
}
- if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
+ if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {
+ set_git_dir(DEFAULT_GIT_DIR_ENVIRONMENT);
break;
+ }
if (is_git_directory(".")) {
inside_git_dir = 1;
if (!work_tree_env)
--
1.7.0.rc0.54.gd33ef
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove .git auto detection from setup_git_env()
2010-02-05 11:47 [PATCH] Remove .git auto detection from setup_git_env() Nguyễn Thái Ngọc Duy
@ 2010-02-05 15:12 ` Jeff King
2010-02-05 17:22 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2010-02-05 15:12 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
On Fri, Feb 05, 2010 at 06:47:48PM +0700, Nguyễn Thái Ngọc Duy wrote:
> When GIT_DIR environment variable is not specified, .git will be
> searched if a repository is needed. Currently this can be done in two
> places: setup_git_directory_gently() and setup_git_env().
>
> The one in setup_git_env() is no longer correct and should IMHO have
> been removed since the introduction of setup_git_directory_gently() in
> d288a70. Having two ways of auto detection may lead to obscure errors
> because .git may be misdetected by setup_git_env(),
> automatically called via git_path(), which is all over the place.
>
> This patch makes setup_git_env() die if GIT_DIR is not explictly
> set. That's setup_git_directory_gently()'s job. If you ever want to
> touch things inside $GIT_DIR, you should have already called
> setup_git_directory_gently().
>
> This patch breaks commands (in a good way) and obviously not for
> mainline. I still have to go through "make test" to see how many are
> impacted. But I think this is a good change. Am I missing something?
It has been a while since I looked at this code, but I think this is a
good direction forward. I remember trying something like this and
getting discouraged at all of the ensuing breakage. So if you can track
down all of the fallouts and fix them, I think we will be better off in
the long run.
-Peff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove .git auto detection from setup_git_env()
2010-02-05 15:12 ` Jeff King
@ 2010-02-05 17:22 ` Junio C Hamano
2010-02-05 17:27 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2010-02-05 17:22 UTC (permalink / raw)
To: Jeff King; +Cc: Nguyễn Thái Ngọc Duy, git, René Scharfe
Jeff King <peff@peff.net> writes:
> It has been a while since I looked at this code, but I think this is a
> good direction forward. I remember trying something like this and
> getting discouraged at all of the ensuing breakage. So if you can track
> down all of the fallouts and fix them, I think we will be better off in
> the long run.
I agree.
This topic started from "We broke 'git grep' in .git directory" and I
think it is the sanest to revert 3081623 (grep --no-index: allow use of
"git grep" outside a git repository, 2010-01-15) which nobody has used so
far in any released version of git, until we sort this out at least.
Every time we touch work-tree related codepath (like René's patch does) we
seem to inadvertently break something else. It's too late for that kind
of fixes for this cycle and "grep --no-index" should go.
-- >8 --
Subject: [PATCH] Revert 308162372d0aa202ff45743e02253e20a4fac4d7
It seems that we have bad interaction with the code related to
GIT_WORK_TREE and "grep --no-index", and broke running grep inside
the .git directory. For now, just revert it and resurrect it after
1.7.0 ships.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Documentation/RelNotes-1.7.0.txt | 3 --
builtin-grep.c | 33 ------------------------
t/t7002-grep.sh | 52 --------------------------------------
3 files changed, 0 insertions(+), 88 deletions(-)
diff --git a/Documentation/RelNotes-1.7.0.txt b/Documentation/RelNotes-1.7.0.txt
index 255666f..f632662 100644
--- a/Documentation/RelNotes-1.7.0.txt
+++ b/Documentation/RelNotes-1.7.0.txt
@@ -133,9 +133,6 @@ Updates since v1.6.6
* "git grep" does not rely on external grep anymore. It can use more than
one threads to accelerate the operation.
- * "git grep" learned "--no-index" option, to search inside contents that
- are not managed by git.
-
* "git grep" learned "--quiet" option.
* "git log" and friends learned "--glob=heads/*" syntax that is a more
diff --git a/builtin-grep.c b/builtin-grep.c
index 0ef849c..bff1e68 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -14,7 +14,6 @@
#include "userdiff.h"
#include "grep.h"
#include "quote.h"
-#include "dir.h"
#ifndef NO_PTHREADS
#include "thread-utils.h"
@@ -646,24 +645,6 @@ static int grep_object(struct grep_opt *opt, const char **paths,
die("unable to grep from object of type %s", typename(obj->type));
}
-static int grep_directory(struct grep_opt *opt, const char **paths)
-{
- struct dir_struct dir;
- int i, hit = 0;
-
- memset(&dir, 0, sizeof(dir));
- setup_standard_excludes(&dir);
-
- fill_directory(&dir, paths);
- for (i = 0; i < dir.nr; i++) {
- hit |= grep_file(opt, dir.entries[i]->name);
- if (hit && opt->status_only)
- break;
- }
- free_grep_patterns(opt);
- return hit;
-}
-
static int context_callback(const struct option *opt, const char *arg,
int unset)
{
@@ -762,8 +743,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
struct option options[] = {
OPT_BOOLEAN(0, "cached", &cached,
"search in index instead of in the work tree"),
- OPT_BOOLEAN(0, "index", &use_index,
- "--no-index finds in contents not managed by git"),
OPT_GROUP(""),
OPT_BOOLEAN('v', "invert-match", &opt.invert,
"show non-matching lines"),
@@ -950,18 +929,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
paths[1] = NULL;
}
- if (!use_index) {
- int hit;
- if (cached)
- die("--cached cannot be used with --no-index.");
- if (list.nr)
- die("--no-index cannot be used with revs.");
- hit = grep_directory(&opt, paths);
- if (use_threads)
- hit |= wait_all();
- return !hit;
- }
-
if (!list.nr) {
int hit;
if (!cached)
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index bf4d4dc..7144f81 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -434,56 +434,4 @@ test_expect_success 'grep -Fi' '
test_cmp expected actual
'
-test_expect_success 'outside of git repository' '
- rm -fr non &&
- mkdir -p non/git/sub &&
- echo hello >non/git/file1 &&
- echo world >non/git/sub/file2 &&
- echo ".*o*" >non/git/.gitignore &&
- {
- echo file1:hello &&
- echo sub/file2:world
- } >non/expect.full &&
- echo file2:world >non/expect.sub
- (
- GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
- export GIT_CEILING_DIRECTORIES &&
- cd non/git &&
- test_must_fail git grep o &&
- git grep --no-index o >../actual.full &&
- test_cmp ../expect.full ../actual.full
- cd sub &&
- test_must_fail git grep o &&
- git grep --no-index o >../../actual.sub &&
- test_cmp ../../expect.sub ../../actual.sub
- )
-'
-
-test_expect_success 'inside git repository but with --no-index' '
- rm -fr is &&
- mkdir -p is/git/sub &&
- echo hello >is/git/file1 &&
- echo world >is/git/sub/file2 &&
- echo ".*o*" >is/git/.gitignore &&
- {
- echo file1:hello &&
- echo sub/file2:world
- } >is/expect.full &&
- : >is/expect.empty &&
- echo file2:world >is/expect.sub
- (
- cd is/git &&
- git init &&
- test_must_fail git grep o >../actual.full &&
- test_cmp ../expect.empty ../actual.full &&
- git grep --no-index o >../actual.full &&
- test_cmp ../expect.full ../actual.full &&
- cd sub &&
- test_must_fail git grep o >../../actual.sub &&
- test_cmp ../../expect.empty ../../actual.sub &&
- git grep --no-index o >../../actual.sub &&
- test_cmp ../../expect.sub ../../actual.sub
- )
-'
-
test_done
--
1.7.0.rc1.204.gb96e5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove .git auto detection from setup_git_env()
2010-02-05 17:22 ` Junio C Hamano
@ 2010-02-05 17:27 ` Junio C Hamano
2010-02-05 20:29 ` René Scharfe
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2010-02-05 17:27 UTC (permalink / raw)
To: Junio C Hamano
Cc: Jeff King, Nguyễn Thái Ngọc Duy, git,
René Scharfe
Junio C Hamano <gitster@pobox.com> writes:
> This topic started from "We broke 'git grep' in .git directory" and I
> think it is the sanest to revert 3081623 (grep --no-index: allow use of
> "git grep" outside a git repository, 2010-01-15) which nobody has used so
> far in any released version of git, until we sort this out at least.
Sorry; spoke too fast. We'd also need to revert the one to git.c (7e62265
(grep: prepare to run outside of a work tree, 2010-01-15) as well.
diff --git a/builtin-grep.c b/builtin-grep.c
index bff1e68..26d4deb 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -739,7 +739,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
const char **paths = NULL;
int i;
int dummy;
- int nongit = 0, use_index = 1;
struct option options[] = {
OPT_BOOLEAN(0, "cached", &cached,
"search in index instead of in the work tree"),
@@ -825,8 +824,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
OPT_END()
};
- prefix = setup_git_directory_gently(&nongit);
-
/*
* 'git grep -h', unlike 'git grep -h <pattern>', is a request
* to show usage information and exit.
@@ -864,10 +861,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
PARSE_OPT_STOP_AT_NON_OPTION |
PARSE_OPT_NO_INTERNAL_HELP);
- if (use_index && nongit)
- /* die the same way as if we did it at the beginning */
- setup_git_directory();
-
/* First unrecognized non-option token */
if (argc > 0 && !opt.pattern_list) {
append_grep_pattern(&opt, argv[0], "command line", 0,
diff --git a/git.c b/git.c
index b3e23f1..4c3028c 100644
--- a/git.c
+++ b/git.c
@@ -317,7 +317,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "fsck-objects", cmd_fsck, RUN_SETUP },
{ "gc", cmd_gc, RUN_SETUP },
{ "get-tar-commit-id", cmd_get_tar_commit_id },
- { "grep", cmd_grep, USE_PAGER },
+ { "grep", cmd_grep, RUN_SETUP | USE_PAGER },
{ "hash-object", cmd_hash_object },
{ "help", cmd_help },
{ "index-pack", cmd_index_pack },
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove .git auto detection from setup_git_env()
2010-02-05 17:27 ` Junio C Hamano
@ 2010-02-05 20:29 ` René Scharfe
0 siblings, 0 replies; 5+ messages in thread
From: René Scharfe @ 2010-02-05 20:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, git
Am 05.02.2010 18:27, schrieb Junio C Hamano:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> This topic started from "We broke 'git grep' in .git directory" and I
>> think it is the sanest to revert 3081623 (grep --no-index: allow use of
>> "git grep" outside a git repository, 2010-01-15) which nobody has used so
>> far in any released version of git, until we sort this out at least.
>
> Sorry; spoke too fast. We'd also need to revert the one to git.c (7e62265
> (grep: prepare to run outside of a work tree, 2010-01-15) as well.
> { "fsck-objects", cmd_fsck, RUN_SETUP },
> { "gc", cmd_gc, RUN_SETUP },
> { "get-tar-commit-id", cmd_get_tar_commit_id },
> - { "grep", cmd_grep, USE_PAGER },
> + { "grep", cmd_grep, RUN_SETUP | USE_PAGER },
> { "hash-object", cmd_hash_object },
> { "help", cmd_help },
> { "index-pack", cmd_index_pack },
There is one other command with only the USE_PAGER flag turned on, which
also seems to have been broken by the change to remove the RUN_SETUP
flag: shortlog. But that was done in March 2008 (abe549e1, "shortlog:
do not require to run from inside a git repository"), so it's no regression.
René
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-02-05 20:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-05 11:47 [PATCH] Remove .git auto detection from setup_git_env() Nguyễn Thái Ngọc Duy
2010-02-05 15:12 ` Jeff King
2010-02-05 17:22 ` Junio C Hamano
2010-02-05 17:27 ` Junio C Hamano
2010-02-05 20:29 ` René Scharfe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).