>>>>> "LT" == Linus Torvalds <[EMAIL PROTECTED]> 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.

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to