Re: [PATCH 1/8] git-apply: work from subdirectory.
- From
Junio C Hamano <junkio@cox.net>
- Date
- Nov 27, 2005, 04:06 UTC
- Message-ID
- <7v4q5yohta.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <Pine.LNX.4.64.0511260932080.13959@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
> This breaks git-apply when used to just do a "diffstat", or > when used on a non-git repository.
You are right. Something like this?
An off-topic note (that's why this message is CC'd to larsi). People may notice messages in this thread have accumulated a modest number of References: entries. I read git list via new.gmane.org NNTP server (running fetchnews locally to slurp from there) and noticed droppage on my end --- whose cause turns out to be that gmane NNTP server chops References: entries in the middle and fetchnews rejects such messages, and I am sure I am _not_ going to see this message on my local machine. Has anybody else noticed this problem?
-- >8 --
[PATCH] apply: only do GIT_DIR discovery when running with --index.
It does not have to be run in git repository unless we are
applying or checking the patch to the index file.Signed-off-by: Junio C Hamano <junkio@cox.net> ---
diff --git a/apply.c b/apply.c index ae06d41..1742ab2 100644 --- a/apply.c +++ b/apply.c @@ -17,7 +17,7 @@ // --index-info shows the old and new index info for paths if available. // static const char *prefix; -static int prefix_length; +static int prefix_length = -1; static int allow_binary_replacement = 0; static int check_index = 0; @@ -1709,7 +1709,7 @@ static int use_patch(struct patch *p) return 0; x = x->next; } - if (prefix && *prefix) { + if (0 < prefix_length) { int pathlen = strlen(pathname); if (pathlen <= prefix_length || memcmp(prefix, pathname, prefix_length)) @@ -1793,10 +1793,6 @@ int main(int argc, char **argv) int i; int read_stdin = 1; - prefix = setup_git_directory(); - prefix_length = prefix ? strlen(prefix) : 0; - git_config(git_default_config); - for (i = 1; i < argc; i++) { const char *arg = argv[i]; int fd; @@ -1858,7 +1854,14 @@ int main(int argc, char **argv) line_termination = 0; continue; } - arg = prefix_filename(prefix, prefix_length, arg); + + if (check_index && prefix_length < 0) { + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; + git_config(git_default_config); + } + if (0 < prefix_length) + arg = prefix_filename(prefix, prefix_length, arg); fd = open(arg, O_RDONLY); if (fd < 0)