git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git apply: binary files differ can be applied with -pN (N>1).

From
Jiang Xin <worldhello.net@gmail.com>
Date
Nov 24, 2010, 06:53 UTC
Message-ID
<4CECB673.9090809@gmail.com>
In-Reply-To
<4CECA0AE.90505@gmail.com>
How to reproduce the bug:
1. Generate a patch file against two directory with binary diff.
================================================================
$ mkdir hello-1.0 hello-2.0

$ dd if=/bin/ls of=hello-1.0/binary.dat count=1 bs=32 1+0 records in 1+0 records out 32 bytes (32 B) copied, 0.00121276 s, 26.4 kB/s

$ dd if=/bin/ls of=hello-2.0/binary.dat count=1 bs=64 1+0 records in 1+0 records out 64 bytes (64 B) copied, 0.00030288 s, 211 kB/s

$ git diff --no-index --binary hello-1.0 hello-2.0 > patch.txt
2. The patch file has patch level 2
===================================
$ cat patch.txt 
diff --git a/hello-1.0/binary.dat b/hello-2.0/binary.dat
index dc2e37f81e0fa88308bec48cd5195b6542e61a20..bf948689934caf2d874ff8168cb716fbc2a127c3 100644
GIT binary patch
delta 37
hcmY#zn4qBGzyJX+<}pH93=9qo77QFfQiegA0RUZd1MdI;

delta 4
LcmZ=zn4kav0;B;E

3. Apply the patch failed
=========================

$ cd hello-1.0

$ git apply --check -p2 ../patch.txt
fatal: git diff header lacks filename information when removing 2 leading pathname components (line 3)


于 2010年11月24日 13:20, Jiang Xin 写道:
> When patch file generated against two non-git directories using
> 'git diff --binary --no-index' without '--no-prefix', the patch
> file has patch level greater then 1, and should be applied with
> '-p2' option. But it does not work if there are binary differ
> in the patch file, it is because in one case the patch level is
> not properly handled.
> 
> Signed-off-by: Jiang Xin <jiangxin@ossxp.com>
> ---
>  builtin/apply.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/builtin/apply.c b/builtin/apply.c
> index 23c18c5..d603e37 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -1126,6 +1126,7 @@ static char *git_header_name(char *line, int llen)
>  	 * form.
>  	 */
>  	for (len = 0 ; ; len++) {
> +		int nslash = p_value;
>  		switch (name[len]) {
>  		default:
>  			continue;
> @@ -1137,7 +1138,7 @@ static char *git_header_name(char *line, int llen)
>  				char c = *second++;
>  				if (c == '\n')
>  					return NULL;
> -				if (c == '/')
> +				if (c == '/' && --nslash <= 0)
>  					break;
>  			}
>  			if (second[len] == '\n' && !memcmp(name, second, len)) {
-- 
蒋鑫

北京群英汇信息技术有限公司
邮件: worldhello.net@gmail.com
网址: http://www.ossxp.com/
    http://blog.ossxp.com/
电话: 010-51262007, 13910430470
传真: 010-51262007
Previous: Jiang XinNext: Junio C Hamano
Message 2 of 5 in “git apply: binary files differ can be applied with -pN (N>1).”
  1. git apply: binary files differ can be applied with -pN (N>1).Jiang Xin, Nov 24, 2010
  2. Jiang XinNov 24, 2010
  3. Junio C HamanoNov 24, 2010
  4. Jiang XinNov 25, 2010
  5. Jiang XinNov 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.