{"thread":{"id":"7511","subject":"[PATCH] Honor -p<n> when applying git diffs","startedAt":"2007-04-04T15:19:14Z","lastAt":"2007-04-05T05:15:16Z","messageCount":2,"participants":["Shawn O. Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"38623","messageId":"20070404151914.GA4910@spearce.org","threadId":"7511","inReplyTo":null,"subject":"[PATCH] Honor -p<n> when applying git diffs","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-04-04T15:19:14Z","receivedAt":"2007-04-04T15:19:14Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If the user is trying to apply a Git generated diff file and they\nhave specified a -p<n> option, where <n> is not 1, the user probably\nhas a good reason for doing this.  Such as they are me, trying to\napply a patch generated in git.git for the git-gui subdirectory to\nthe git-gui.git repository, where there is no git-gui subdirectory\npresent.\n\nUsers shouldn't supply -p2 unless they mean it.  But if they are\nsupplying it, they probably have thought about how to make this\npatch apply to their working directory, and want to risk whatever\nresults may come from that.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-apply.c       |    4 ++--\n t/t4120-apply-popt.sh |   25 +++++++++++++++++++++++++\n 2 files changed, 27 insertions(+), 2 deletions(-)\n create mode 100755 t/t4120-apply-popt.sh\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 27a182b..a5d6126 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -417,7 +417,7 @@ static int gitdiff_hdrend(const char *line, struct patch *patch)\n static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, const char *oldnew)\n {\n \tif (!orig_name && !isnull)\n-\t\treturn find_name(line, NULL, 1, TERM_TAB);\n+\t\treturn find_name(line, NULL, p_value, TERM_TAB);\n \n \tif (orig_name) {\n \t\tint len;\n@@ -427,7 +427,7 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,\n \t\tlen = strlen(name);\n \t\tif (isnull)\n \t\t\tdie(\"git-apply: bad git-diff - expected /dev/null, got %s on line %d\", name, linenr);\n-\t\tanother = find_name(line, NULL, 1, TERM_TAB);\n+\t\tanother = find_name(line, NULL, p_value, TERM_TAB);\n \t\tif (!another || memcmp(another, name, len))\n \t\t\tdie(\"git-apply: bad git-diff - inconsistent %s filename on line %d\", oldnew, linenr);\n \t\tfree(another);\ndiff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh\nnew file mode 100755\nindex 0000000..2f672f3\n--- /dev/null\n+++ b/t/t4120-apply-popt.sh\n@@ -0,0 +1,25 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Shawn O. Pearce\n+#\n+\n+test_description='git-apply -p handling.'\n+\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\tmkdir sub &&\n+\techo A >sub/file1 &&\n+\tcp sub/file1 file1 &&\n+\tgit add sub/file1 &&\n+\techo B >sub/file1 &&\n+\tgit diff >patch.file &&\n+\trm sub/file1 &&\n+\trmdir sub\n+'\n+\n+test_expect_success 'apply git diff with -p2' '\n+\tgit apply -p2 patch.file\n+'\n+\n+test_done\n-- \n1.5.1.rc3.672.gf5329\n"},{"id":"38672","messageId":"7vr6qzwgez.fsf@assigned-by-dhcp.cox.net","threadId":"7511","inReplyTo":"20070404151914.GA4910@spearce.org","subject":"Re: [PATCH] Honor -p<n> when applying git diffs","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-05T05:15:16Z","receivedAt":"2007-04-05T05:15:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> If the user is trying to apply a Git generated diff file and they\n> have specified a -p<n> option, where <n> is not 1, the user probably\n> has a good reason for doing this.  Such as they are me, trying to\n> apply a patch generated in git.git for the git-gui subdirectory to\n> the git-gui.git repository, where there is no git-gui subdirectory\n> present.\n\nGood point.\n"}]}