* [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
@ 2007-11-03 10:03 Nguyễn Thái Ngọc Duy
2007-11-03 11:38 ` Johannes Schindelin
2007-11-03 13:18 ` Nguyễn Thái Ngọc Duy
0 siblings, 2 replies; 11+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2007-11-03 10:03 UTC (permalink / raw)
To: git
Without this, work_tree handling code in setup_git_directory
will be activated. If you stay in root work tree (no prefix),
it does not harm. It does if you work from a subdirectory though.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Turns out my patch on NEED_WORK_TREE is fixing a wrong place.
setup.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c
index 145eca5..6f8f769 100644
--- a/setup.c
+++ b/setup.c
@@ -240,6 +240,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (chdir(work_tree_env) < 0)
die ("Could not chdir to %s", work_tree_env);
strcat(buffer, "/");
+ inside_work_tree = 1;
return retval;
}
if (nongit_ok) {
--
1.5.3.rc4.3.gab089
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-03 10:03 [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently Nguyễn Thái Ngọc Duy
@ 2007-11-03 11:38 ` Johannes Schindelin
[not found] ` <fcaeb9bf0711030457se2f5f5bpd9aa463e878cd621@mail.gmail.com>
2007-11-03 13:18 ` Nguyễn Thái Ngọc Duy
1 sibling, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2007-11-03 11:38 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
[-- Attachment #1: Type: TEXT/PLAIN, Size: 918 bytes --]
Hi,
On Sat, 3 Nov 2007, Nguyễn Thái Ngọc Duy wrote:
> Without this, work_tree handling code in setup_git_directory
> will be activated. If you stay in root work tree (no prefix),
> it does not harm. It does if you work from a subdirectory though.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> Turns out my patch on NEED_WORK_TREE is fixing a wrong place.
>
> setup.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 145eca5..6f8f769 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -240,6 +240,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
> if (chdir(work_tree_env) < 0)
> die ("Could not chdir to %s", work_tree_env);
> strcat(buffer, "/");
> + inside_work_tree = 1;
I really have to wonder why this is needed, as it should be deduced
(correctly!) when you ask is_inside_work_tree().
Ciao,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
[not found] ` <fcaeb9bf0711030457se2f5f5bpd9aa463e878cd621@mail.gmail.com>
@ 2007-11-03 12:16 ` Johannes Schindelin
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2007-11-03 12:16 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: git
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1940 bytes --]
Hi,
On Sat, 3 Nov 2007, Nguyen Thai Ngoc Duy wrote:
> On 11/3/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> > On Sat, 3 Nov 2007, Nguyễn Thái Ngọc Duy wrote:
> >
> > > Without this, work_tree handling code in setup_git_directory will be
> > > activated. If you stay in root work tree (no prefix), it does not
> > > harm. It does if you work from a subdirectory though.
> > >
> > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> > > ---
> > > Turns out my patch on NEED_WORK_TREE is fixing a wrong place.
> > >
> > > setup.c | 1 +
> > > 1 files changed, 1 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/setup.c b/setup.c
> > > index 145eca5..6f8f769 100644
> > > --- a/setup.c
> > > +++ b/setup.c
> > > @@ -240,6 +240,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
> > > if (chdir(work_tree_env) < 0)
> > > die ("Could not chdir to %s", work_tree_env);
> > > strcat(buffer, "/");
> > > + inside_work_tree = 1;
> >
> > I really have to wonder why this is needed, as it should be deduced
> > (correctly!) when you ask is_inside_work_tree().
>
> Because setup_git_directory() does not? From what I see,
> setup_git_directory() calls setup_git_directory_gently() then check
> for inside_work_tree variable almost immediately
> (check_repository_format() does not seem to ask
> is_inside_work_tree()).
Ah, I see the problem.
>From your commit message I assumed that you fixed the wrong spot... Which
you did not. It would have helped me if the message had read:
When both GIT_DIR and GIT_WORK_TREE are set, and
setup_git_directory_gently() changes the current working
directory accordingly, it should also set inside_work_tree = 1.
Your fix is the proper one, but it not only fixes setup_git_directory(),
but all callers of setup_git_directory_gently().
Thanks,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-03 10:03 [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently Nguyễn Thái Ngọc Duy
2007-11-03 11:38 ` Johannes Schindelin
@ 2007-11-03 13:18 ` Nguyễn Thái Ngọc Duy
2007-11-03 13:25 ` Johannes Schindelin
2007-11-04 4:33 ` Junio C Hamano
1 sibling, 2 replies; 11+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2007-11-03 13:18 UTC (permalink / raw)
To: git; +Cc: Johannes Schindelin
When both GIT_DIR and GIT_WORK_TREE are set, and
setup_git_directory_gently() changes the current working
directory accordingly, it should also set inside_work_tree = 1.
Without this, work_tree handling code in setup_git_directory()
will be activated. If you stay in root work tree (no prefix),
it does not harm. It does if you work from a subdirectory though.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Updated commit message accordingly
setup.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c
index 145eca5..6f8f769 100644
--- a/setup.c
+++ b/setup.c
@@ -240,6 +240,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (chdir(work_tree_env) < 0)
die ("Could not chdir to %s", work_tree_env);
strcat(buffer, "/");
+ inside_work_tree = 1;
return retval;
}
if (nongit_ok) {
--
1.5.3.rc4.3.gab089
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-03 13:18 ` Nguyễn Thái Ngọc Duy
@ 2007-11-03 13:25 ` Johannes Schindelin
2007-11-04 4:33 ` Junio C Hamano
1 sibling, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2007-11-03 13:25 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
[-- Attachment #1: Type: TEXT/PLAIN, Size: 559 bytes --]
Hi,
On Sat, 3 Nov 2007, Nguyễn Thái Ngọc Duy wrote:
> When both GIT_DIR and GIT_WORK_TREE are set, and
> setup_git_directory_gently() changes the current working
> directory accordingly, it should also set inside_work_tree = 1.
>
> Without this, work_tree handling code in setup_git_directory()
> will be activated. If you stay in root work tree (no prefix),
> it does not harm. It does if you work from a subdirectory though.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> Updated commit message accordingly
Thanks,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-03 13:18 ` Nguyễn Thái Ngọc Duy
2007-11-03 13:25 ` Johannes Schindelin
@ 2007-11-04 4:33 ` Junio C Hamano
2007-11-04 7:03 ` Nguyen Thai Ngoc Duy
1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2007-11-04 4:33 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git, Johannes Schindelin
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> When both GIT_DIR and GIT_WORK_TREE are set, and
> setup_git_directory_gently() changes the current working
> directory accordingly, it should also set inside_work_tree = 1.
>
> Without this, work_tree handling code in setup_git_directory()
> will be activated. If you stay in root work tree (no prefix),
> it does not harm. It does if you work from a subdirectory though.
Please add automated test script for this, thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-04 4:33 ` Junio C Hamano
@ 2007-11-04 7:03 ` Nguyen Thai Ngoc Duy
2007-11-07 20:42 ` Junio C Hamano
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2007-11-04 7:03 UTC (permalink / raw)
To: Junio C Hamano, Johannes Schindelin; +Cc: git
On Sat, Nov 03, 2007 at 09:33:40PM -0700, Junio C Hamano wrote:
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
> > When both GIT_DIR and GIT_WORK_TREE are set, and
> > setup_git_directory_gently() changes the current working
> > directory accordingly, it should also set inside_work_tree = 1.
> >
> > Without this, work_tree handling code in setup_git_directory()
> > will be activated. If you stay in root work tree (no prefix),
> > it does not harm. It does if you work from a subdirectory though.
>
> Please add automated test script for this, thanks.
>
Thank you for reminding. I tried to put a test in
t1501-worktree.sh and found out core.worktree can override
inside_work_tree previously set by setup_git_directory_gently(),
activating the worktree code in setup_git_directory() again.
This made me think setup_git_directory_gently() should use
get_git_work_tree() instead. But then git_work_tree_cfg may not be
initialized when get_git_work_tree() is called (starting from
setup_git_directory(), git_work_tree_cfg is initialized in
check_repository_format_version(), which is called _after_
setup_git_directory_gently()).
The interaction between these variables and functions is really beyond
my knowledge. Johannes, can you have a look at this? In theory the
following test should pass:
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 7ee3820..bdb7720 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -103,6 +103,11 @@ test_expect_success 'repo finds its work tree from work tree, too' '
test sub/dir/tracked = "$(git ls-files)")
'
+test_expect_success 'Try a command from subdir in worktree' '
+ (cd repo.git/work/sub &&
+ GIT_DIR=../.. GIT_WORK_TREE=.. git blame dir/tracked)
+'
+
test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
cd repo.git/work/sub/dir &&
GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
--
Duy
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-04 7:03 ` Nguyen Thai Ngoc Duy
@ 2007-11-07 20:42 ` Junio C Hamano
2007-11-07 20:54 ` Johannes Schindelin
2007-11-09 11:32 ` Johannes Schindelin
2007-11-09 11:34 ` [PATCH] builtin-blame: set up the work_tree before the first file access Johannes Schindelin
2 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2007-11-07 20:42 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: Johannes Schindelin, git
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
> On Sat, Nov 03, 2007 at 09:33:40PM -0700, Junio C Hamano wrote:
>>
>> Please add automated test script for this, thanks.
>
> Thank you for reminding. I tried to put a test in
> t1501-worktree.sh and found out core.worktree can override
> inside_work_tree previously set by setup_git_directory_gently(),
> activating the worktree code in setup_git_directory() again.
>
> This made me think setup_git_directory_gently() should use
> get_git_work_tree() instead. But then git_work_tree_cfg may not be
> initialized when get_git_work_tree() is called (starting from
> setup_git_directory(), git_work_tree_cfg is initialized in
> check_repository_format_version(), which is called _after_
> setup_git_directory_gently()).
>
> The interaction between these variables and functions is really beyond
> my knowledge. Johannes, can you have a look at this? In theory the
> following test should pass:
>
> diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
> index 7ee3820..bdb7720 100755
> --- a/t/t1501-worktree.sh
> +++ b/t/t1501-worktree.sh
> @@ -103,6 +103,11 @@ test_expect_success 'repo finds its work tree from work tree, too' '
> test sub/dir/tracked = "$(git ls-files)")
> '
>
> +test_expect_success 'Try a command from subdir in worktree' '
> + (cd repo.git/work/sub &&
> + GIT_DIR=../.. GIT_WORK_TREE=.. git blame dir/tracked)
> +'
> +
> test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
> cd repo.git/work/sub/dir &&
> GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
I am wondering what happened to this thread...
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-07 20:42 ` Junio C Hamano
@ 2007-11-07 20:54 ` Johannes Schindelin
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2007-11-07 20:54 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Nguyen Thai Ngoc Duy, git
Hi,
On Wed, 7 Nov 2007, Junio C Hamano wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
>
> > On Sat, Nov 03, 2007 at 09:33:40PM -0700, Junio C Hamano wrote:
> >>
> >> Please add automated test script for this, thanks.
> >
> > Thank you for reminding. I tried to put a test in
> > t1501-worktree.sh and found out core.worktree can override
> > inside_work_tree previously set by setup_git_directory_gently(),
> > activating the worktree code in setup_git_directory() again.
> >
> > This made me think setup_git_directory_gently() should use
> > get_git_work_tree() instead. But then git_work_tree_cfg may not be
> > initialized when get_git_work_tree() is called (starting from
> > setup_git_directory(), git_work_tree_cfg is initialized in
> > check_repository_format_version(), which is called _after_
> > setup_git_directory_gently()).
> >
> > The interaction between these variables and functions is really beyond
> > my knowledge. Johannes, can you have a look at this? In theory the
> > following test should pass:
> >
> > diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
> > index 7ee3820..bdb7720 100755
> > --- a/t/t1501-worktree.sh
> > +++ b/t/t1501-worktree.sh
> > @@ -103,6 +103,11 @@ test_expect_success 'repo finds its work tree from work tree, too' '
> > test sub/dir/tracked = "$(git ls-files)")
> > '
> >
> > +test_expect_success 'Try a command from subdir in worktree' '
> > + (cd repo.git/work/sub &&
> > + GIT_DIR=../.. GIT_WORK_TREE=.. git blame dir/tracked)
> > +'
> > +
> > test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
> > cd repo.git/work/sub/dir &&
> > GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
>
> I am wondering what happened to this thread...
It is still in my inbox, waiting for a time where I can actually
concentrate.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently
2007-11-04 7:03 ` Nguyen Thai Ngoc Duy
2007-11-07 20:42 ` Junio C Hamano
@ 2007-11-09 11:32 ` Johannes Schindelin
2007-11-09 11:34 ` [PATCH] builtin-blame: set up the work_tree before the first file access Johannes Schindelin
2 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2007-11-09 11:32 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: Junio C Hamano, git
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2323 bytes --]
Hi,
On Sun, 4 Nov 2007, Nguyen Thai Ngoc Duy wrote:
> On Sat, Nov 03, 2007 at 09:33:40PM -0700, Junio C Hamano wrote:
> > Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> >
> > > When both GIT_DIR and GIT_WORK_TREE are set, and
> > > setup_git_directory_gently() changes the current working
> > > directory accordingly, it should also set inside_work_tree = 1.
> > >
> > > Without this, work_tree handling code in setup_git_directory()
> > > will be activated. If you stay in root work tree (no prefix),
> > > it does not harm. It does if you work from a subdirectory though.
> >
> > Please add automated test script for this, thanks.
> >
>
> Thank you for reminding. I tried to put a test in
> t1501-worktree.sh and found out core.worktree can override
> inside_work_tree previously set by setup_git_directory_gently(),
> activating the worktree code in setup_git_directory() again.
>
> This made me think setup_git_directory_gently() should use
> get_git_work_tree() instead. But then git_work_tree_cfg may not be
> initialized when get_git_work_tree() is called (starting from
> setup_git_directory(), git_work_tree_cfg is initialized in
> check_repository_format_version(), which is called _after_
> setup_git_directory_gently()).
>
> The interaction between these variables and functions is really beyond
> my knowledge. Johannes, can you have a look at this? In theory the
> following test should pass:
>
> diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
> index 7ee3820..bdb7720 100755
> --- a/t/t1501-worktree.sh
> +++ b/t/t1501-worktree.sh
> @@ -103,6 +103,11 @@ test_expect_success 'repo finds its work tree from work tree, too' '
> test sub/dir/tracked = "$(git ls-files)")
> '
>
> +test_expect_success 'Try a command from subdir in worktree' '
> + (cd repo.git/work/sub &&
> + GIT_DIR=../.. GIT_WORK_TREE=.. git blame dir/tracked)
> +'
> +
> test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
> cd repo.git/work/sub/dir &&
> GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
This does not really test work_tree, but if blame uses the work_tree
machinery correctly.
I will send out a patch to builtin-blame.c in a minute.
However, this test case still fails, since blame needs a HEAD revision!
And in t1501 there is no commit done yet.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] builtin-blame: set up the work_tree before the first file access
2007-11-04 7:03 ` Nguyen Thai Ngoc Duy
2007-11-07 20:42 ` Junio C Hamano
2007-11-09 11:32 ` Johannes Schindelin
@ 2007-11-09 11:34 ` Johannes Schindelin
2 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2007-11-09 11:34 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: Junio C Hamano, git
We check in cmd_blame() if the specified path is there, but we
failed to set up the working tree before that.
While at it, make setup_work_tree() just return if it was run
before.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
IMO both this patch and the recent patch to call setup_work_tree()
are needed. Only the second call to setup_work_tree() will know
if there was no revision specified, and the first one will know if
a -- has been seen.
builtin-blame.c | 1 +
setup.c | 10 ++++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index 55a3c0b..ba80bf8 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -2295,6 +2295,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
else if (i != argc - 1)
usage(blame_usage); /* garbage at end */
+ setup_work_tree();
if (!has_path_in_work_tree(path))
die("cannot stat path %s: %s",
path, strerror(errno));
diff --git a/setup.c b/setup.c
index 084d722..1421a2c 100644
--- a/setup.c
+++ b/setup.c
@@ -207,12 +207,18 @@ static const char *set_work_tree(const char *dir)
}
void setup_work_tree(void) {
- const char *work_tree = get_git_work_tree();
- const char *git_dir = get_git_dir();
+ const char *work_tree, *git_dir;
+ static int initialized = 0;
+
+ if (initialized)
+ return;
+ work_tree = get_git_work_tree();
+ git_dir = get_git_dir();
if (!is_absolute_path(git_dir))
set_git_dir(make_absolute_path(git_dir));
if (!work_tree || chdir(work_tree))
die("This operation must be run in a work tree");
+ initialized = 1;
}
/*
--
1.5.3.5.1645.g1f4df
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-11-09 11:34 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-03 10:03 [PATCH] Add missing inside_work_tree setting in setup_git_directory_gently Nguyễn Thái Ngọc Duy
2007-11-03 11:38 ` Johannes Schindelin
[not found] ` <fcaeb9bf0711030457se2f5f5bpd9aa463e878cd621@mail.gmail.com>
2007-11-03 12:16 ` Johannes Schindelin
2007-11-03 13:18 ` Nguyễn Thái Ngọc Duy
2007-11-03 13:25 ` Johannes Schindelin
2007-11-04 4:33 ` Junio C Hamano
2007-11-04 7:03 ` Nguyen Thai Ngoc Duy
2007-11-07 20:42 ` Junio C Hamano
2007-11-07 20:54 ` Johannes Schindelin
2007-11-09 11:32 ` Johannes Schindelin
2007-11-09 11:34 ` [PATCH] builtin-blame: set up the work_tree before the first file access Johannes Schindelin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.