From: Junio C Hamano <junio@siamese.dyndns.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: "GIT_INDEX_FILE" environment variable
Date: Thu, 21 Apr 2005 17:21:10 -0700 [thread overview]
Message-ID: <7vis2fbr0p.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.58.0504211100330.2344@ppc970.osdl.org> (Linus Torvalds's message of "Thu, 21 Apr 2005 11:09:52 -0700 (PDT)")
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
LT> Add support for a "GIT_INDEX_FILE" environment variable.
LT> We use that to specify alternative index files, which can be useful
LT> if you want to (for example) generate a temporary index file to do
LT> some specific operation that you don't want to mess with your main
LT> one with.
LT> It defaults to the regular ".git/index" if it hasn't been specified.
This is all good. I have a related issue I'd like to hear your
opinion about.
When I am not in the top-level directory, relative to the tree
structure $GIT_INDEX_FILE describes, obviously I cannot just say
"show-diff path-pattern" (or even just "show-diff") without
first chdir'ing to the top. My current workaround I use in the
jit-show-diff wrapper script is quite ugly:
- Starting from dir="${PWD-"$(pwd)"}", repeatedly do
dir=$(dirname dir) until I find a $dir/.git directory. Call
the first directory I find that has .git subdirectory
$GIT_PROJECT_TOP.
- At the same time, inspect GIT_INDEX_FILE and
SHA1_FILE_DIRECTORY environment variables. If they are not
set, set them to $GIT_PROJECT_TOP/.git/index and
$GIT_PROJECT_TOP/.git/objects, respectively and export them.
- Figure out the name of the current working directory relative
to $GIT_PROJECT_TOP. I'll call this value $R for brevity in
the following description.
- chdir to $GIT_PROJECT_TOP and run "show-diff" with the
original flags and _all_ the user supplied paths prefixed
with $R.
To illustrate what I just said:
$ /bin/ls -aF
./ ../ .git/ a/
$ /bin/ls -aF .git
. ../ HEAD index objects/
$ cd a
$ /bin/ls -aF
. ../ bar foo/
$ show-diff -r foo ; # of course this does not work.
$ jit-show-diff -r foo
The wrapper figures out that .. is the project top to chdir
to, and $R is "a/". Using these values, it eventually calls:
cd .. ; show-diff -r "a/foo"
This is not so hard to arrange in the wrapper, but this is quite
brittle. The show-diff command happens to take only -r, -z, and
-q flag parameters so the wrapper can prefix $R to all the other
paramters, but for other git core commands when to prefix $R and
when not to soon becomes a maintenance nightmare.
I am thinking about an alternative way of doing the above by
some modifications to the git core. I think the root of this
problem is that there is no equivalent to GIT_INDEX_FILE and
SHA1_FILE_DIRECTORY that tells the core git where the project
top directory (i.e. the root of the working tree that
corresponds to what $GIT_INDEX_FILE describes) is.
I am wondering if this alternative is acceptable by you before I
spend too much time on it.
- A new environment variable GIT_WORKING_TREE points at the
root of the working tree.
- Each git core command [*1*] that looks at the working tree is
modified to take the user supplied pathname as a path
relative to the current working directory, and use
GIT_WORKING_TREE value to figure out which path the user is
talking about, relative to the tree structure GIT_INDEX_FILE
describes.
There is no need for jit-show-diff-wrapper when the above change
happens. The user (or Cogito) has to set and export
GIT_WORKING_TREE once, and whereever the user happens to be the
core git command would just work as expected.
What do you think?
[Footnotes]
*1* Yes I am aware that there are tons of them that need this
surgery if we wanted to take this approach.
next prev parent reply other threads:[~2005-04-22 0:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-21 18:09 "GIT_INDEX_FILE" environment variable Linus Torvalds
2005-04-21 18:11 ` Davide Libenzi
2005-04-21 18:37 ` Linus Torvalds
2005-04-22 0:21 ` Junio C Hamano [this message]
2005-04-22 5:05 ` Linus Torvalds
2005-04-22 6:23 ` Junio C Hamano
2005-04-22 10:35 ` Petr Baudis
2005-04-22 19:24 ` Linus Torvalds
2005-04-22 20:20 ` Junio C Hamano
2005-04-22 22:14 ` Linus Torvalds
2005-04-22 22:31 ` Junio C Hamano
2005-04-22 22:33 ` Petr Baudis
2005-04-22 22:55 ` Linus Torvalds
2005-04-22 9:14 ` Zach Welch
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=7vis2fbr0p.fsf@assigned-by-dhcp.cox.net \
--to=junio@siamese.dyndns.org \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.org \
/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.