From: Johannes Sixt <j.sixt@viscovery.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org
Subject: Re: [PATCH] allow setting GIT_WORK_TREE to "no work tree"
Date: Fri, 08 Feb 2008 08:21:25 +0100 [thread overview]
Message-ID: <47AC02F5.9080705@viscovery.net> (raw)
In-Reply-To: <alpine.LSU.1.00.0802071855550.8543@racer.site>
Johannes Schindelin schrieb:
> Hi,
>
> On Wed, 6 Feb 2008, Johannes Sixt wrote:
>
>> Jeff King schrieb:
>>> In setup_git_directory_gently, we have a special rule that says "if
>>> GIT_DIR is set but GIT_WORK_TREE is not, then use the current working
>>> directory as the work tree." This is the intended behavior for the
>>> user perspective.
>>>
>>> However, setup_git_directory_gently sets GIT_DIR itself, meaning that
>>> further setups (either because we are executing a command via alias,
>>> or in a subprocess) will see the non-existent GIT_WORK_TREE and assume
>>> we fall into the "current working directory is the working tree"
>>> codepath.
>>>
>>> Instead, we now use a special value of GIT_WORK_TREE to indicate that
>>> we have already checked for a worktree and that there isn't one,
>>> setting it when we set GIT_DIR and checking for it in the special case
>>> path.
>>>
>>> The special value is a blank GIT_WORK_TREE; it could be any value, but
>>> this should not conflict with any user values (and as a bonus, you can
>>> now tell git "I don't have a work tree" with "GIT_WORK_TREE= git",
>>> though I suspect the use case for that is limited).
>> Hrm. Unfortunately, on Windows there is no such thing as an empty
>> environment string. setenv(x, "") *removes* the environment variable.
>
> That might be a shortcoming of our implementation of setenv():
No, it is not. It's Windows's putenv(), and it's even documented.
> -- snip --
> cd /git
>
> cat > a1.c << EOF
> #include <stdio.h>
> #include "compat/setenv.c"
> #include "compat/unsetenv.c"
>
> static void p()
> {
> const char *abc = getenv("ABC");
> printf("env ABC: %s\n", abc ? abc : "(null)");
> }
>
> int main()
> {
> p();
> gitsetenv("ABC", "Hello", 1);
> p();
> gitsetenv("ABC", "", 1);
> p();
> gitunsetenv("ABC");
> p();
> return 0;
> }
> EOF
>
> gcc -DNO_MMAP=1 -I. -Icompat -o a1.exe a1.c
>
> ABC="" ./a1.exe
> -- snap --
>
> This will show
>
> env ABC:
> env ABC: Hello
> env ABC: (null)
> env ABC: (null)
>
> So it seems that environment variables _can_ be empty. Just our
> relatively stupid implementation of setenv() does not do it.
>
> Maybe something like compat/unsetenv.c is needed in setenv(), too.
This only shows that, yes, variables _can_ be empty - if the setenv/putenv
implementation is "sane", like MSYS/bash's.
That said, we probably should modify environ directly in gitsetenv().
-- Hannes
next prev parent reply other threads:[~2008-02-08 7:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-06 10:26 [PATCH] allow setting GIT_WORK_TREE to "no work tree" Jeff King
2008-02-06 10:42 ` Johannes Sixt
2008-02-06 11:01 ` Jeff King
2008-02-06 20:54 ` Junio C Hamano
2008-02-06 20:59 ` Junio C Hamano
2008-02-07 5:13 ` Jeff King
2008-02-07 7:13 ` Jay Soffian
2008-02-07 12:33 ` Johannes Schindelin
2008-02-07 18:06 ` Jay Soffian
2008-02-07 9:10 ` Junio C Hamano
2008-02-07 19:02 ` Johannes Schindelin
2008-02-08 7:21 ` Johannes Sixt [this message]
2008-02-08 12:05 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47AC02F5.9080705@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.