Re: Fix recent 'unpack_trees()'-related changes breaking 'git stash'
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Mar 15, 2008, 16:51 UTC
- Message-ID
- <alpine.LFD.1.00.0803150934100.3557@woody.linux-foundation.org>
- In-Reply-To
- <7v1w6cpox6.fsf@gitster.siamese.dyndns.org>
On Fri, 14 Mar 2008, Junio C Hamano wrote:
Show 6 quoted lines
> > It would be slightly simpler to write the above sequence like this: > > w_tree=$( ( > rm -f "$TMP-index" && > git read-tree --index-output="$TMP-index" -m $i_tree &&
Ack. That's an independent cleanup.
In fact, I would almost prefer to try to stop using GIT_INDEX_FILE entirely, and add it as a top-level git flag, so you can then make the rest be:
git --index-file "$TMP-index" add -u && git --index-file "$TMP-index" write-tree && rm -f "$TMP-index"
instead of doing that
Show 5 quoted lines
> GIT_INDEX_FILE="$TMP-index" && > export GIT_INDEX_FILE && > git add -u && > git write-tree && > rm -f "$TMP-index"
thing.
Something like the appended, in other words.
Oh, and that whole git.c argument parsing should be made to use the proper arg parser, too. But I'm too damn lazy and not comfy enough with 'parse_options()' usage. Somebody who is should take a look..
Linus
--- git-stash.sh | 9 +++------ git.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh index c2b6820..95b65dc 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -63,12 +63,9 @@ create_stash () { # state of the working tree w_tree=$( ( rm -f "$TMP-index" && - cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" && - GIT_INDEX_FILE="$TMP-index" && - export GIT_INDEX_FILE && - git read-tree -m $i_tree && - git add -u && - git write-tree && + git read-tree --index-output="$TMP-index" -m $i_tree && + git --index-file "$TMP-index" add -u && + git --index-file "$TMP-index" write-tree && rm -f "$TMP-index" ) ) || die "Cannot save the current worktree state" diff --git a/git.c b/git.c index 13de801..a615df9 100644 --- a/git.c +++ b/git.c @@ -55,6 +55,21 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1); if (envchanged) *envchanged = 1; + } else if (!strcmp(cmd, "--index-file")) { + if (*argc < 2) { + fprintf(stderr, "No directory given for --index-file.\n" ); + usage(git_usage_string); + } + setenv(INDEX_ENVIRONMENT, (*argv)[1], 1); + if (envchanged) + *envchanged = 1; + (*argv)++; + (*argc)--; + handled++; + } else if (!prefixcmp(cmd, "--index-file=")) { + setenv(INDEX_ENVIRONMENT, cmd + 13, 1); + if (envchanged) + *envchanged = 1; } else if (!strcmp(cmd, "--work-tree")) { if (*argc < 2) { fprintf(stderr, "No directory given for --work-tree.\n" );