From nobody@FreeBSD.org  Tue Sep 15 20:35:27 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 790F6106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 15 Sep 2009 20:35:27 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 677AC8FC19
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 15 Sep 2009 20:35:27 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n8FKZR4P015789
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 15 Sep 2009 20:35:27 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n8FKZRie015788;
	Tue, 15 Sep 2009 20:35:27 GMT
	(envelope-from nobody)
Message-Id: <200909152035.n8FKZRie015788@www.freebsd.org>
Date: Tue, 15 Sep 2009 20:35:27 GMT
From: "deeptech71@gmail.com" <deeptech71@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: patch(1) assumes that a file appears only once in the patch in check-only mode
X-Send-Pr-Version: www-3.1
X-GNATS-Notify: dt71@gmx.com

>Number:         138858
>Category:       bin
>Synopsis:       patch(1) assumes that a file appears only once in the patch in check-only mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 15 20:40:03 UTC 2009
>Closed-Date:    
>Last-Modified:  Mon Dec 30 03:58:40 UTC 2013
>Originator:     deeptech71@gmail.com
>Release:        ~CURRENT
>Organization:
>Environment:
FreeBSD x 8.0-BETA2 FreeBSD 8.0-BETA2 #0 r196195M: Fri Aug 14 02:25:06 UTC 2009 devhc@:/usr/obj/usr/src/sys/HQ  i386
>Description:
There are patches that should be applied in a strict order to be successful (ie., on a set of files, apply patch#1 first, then apply patch#2 on the result yielded by applying patch#1). I concatenate the patches (in correct order), and pipe them to patch(1). But, as always, I check what would happen if the patches were applied (use the -C option). The test run can show wrong results if the concatenated patch references a file multiple times near a common line, probably because in the check-only mode, patch(1) tries to apply each hunk on the original, unmodified files.
>How-To-Repeat:
diff -u orig mod1 > mod1.patch # mod1 changes line N of orig
diff -u orig mod2 > mod2.patch # mod2 changes line N of orig, too !

cat mod1.patch mod2.patch | patch -Cs # looks OK
cat mod1.patch mod2.patch | patch -s # fail !
>Fix:
(If this won't be fixed soon, it would be nice to have this documented in the manpages.)

>Release-Note:
>Audit-Trail:

From: "deeptech71@gmail.com" <deeptech71@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/138858: patch(1) assumes that a file appears only once in the 
	patch in check-only mode
Date: Sat, 21 Nov 2009 09:50:15 +0000

 --00032555b392f4353f0478de8469
 Content-Type: text/plain; charset=ISO-8859-1
 
 let me be more concise:
 put words.txt and con.patch in one directory, cd to that directory, then:
 
 # cat con.patch | patch -p1 -Cs
 
 the test run says that the patch looks OK (applies cleanly), so we
 proceed with actual patching:
 
 # cat con.patch | patch -p1 -C
 
 but the patch actually fails, so the test run lied !
 
 --00032555b392f4353f0478de8469
 Content-Type: text/plain; charset=US-ASCII; name="words.txt"
 Content-Disposition: attachment; filename="words.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g2a9cc8h0
 
 bG9yZXAKaXBzdW0KZG9sb3IKaW50ZWdlcgpzaXQKYW1ldAprdGh4YnllCg==
 --00032555b392f4353f0478de8469
 Content-Type: application/octet-stream; name="con.patch"
 Content-Disposition: attachment; filename="con.patch"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g2a9cq111
 
 ZGlmZiAtcnUgb3JpZ2luYWwvd29yZHMudHh0IGQxL3dvcmRzLnR4dAotLS0gb3JpZ2luYWwvd29y
 ZHMudHh0CTIwMDktMTEtMjEgMTA6MzA6NTIuMDAwMDAwMDAwICswMDAwCisrKyBkMS93b3Jkcy50
 eHQJMjAwOS0xMS0yMSAxMDozMToxMi4wMDAwMDAwMDAgKzAwMDAKQEAgLTEsNyArMSw3IEBACiBs
 b3JlcAogaXBzdW0KIGRvbG9yCi1pbnRlZ2VyCitmbG9hdAogc2l0CiBhbWV0CiBrdGh4YnllCmRp
 ZmYgLXJ1IG9yaWdpbmFsL3dvcmRzLnR4dCBkMi93b3Jkcy50eHQKLS0tIG9yaWdpbmFsL3dvcmRz
 LnR4dAkyMDA5LTExLTIxIDEwOjMwOjUyLjAwMDAwMDAwMCArMDAwMAorKysgZDIvd29yZHMudHh0
 CTIwMDktMTEtMjEgMTA6MzE6MjguMDAwMDAwMDAwICswMDAwCkBAIC0xLDcgKzEsNyBAQAogbG9y
 ZXAKIGlwc3VtCiBkb2xvcgotaW50ZWdlcgorZG91YmxlCiBzaXQKIGFtZXQKIGt0aHhieWUK
 --00032555b392f4353f0478de8469--

From: "deeptech71@gmail.com" <deeptech71@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/138858: patch(1) assumes that a file appears only once in the
 patch in check-only mode
Date: Thu, 1 Sep 2011 06:50:36 +0200

 i've just noticed that in my 2nd message i've screwed up the command
 flags. restating everything:
 
 put words.txt and con.patch in one directory, cd to that directory, and then do:
 $ cat con.patch | patch -sp1 --check
 the --check flag means "do not actually edit files, just check to see
 what would happen". the above test run says that the patch applies
 cleanly. now do:
 $ cat con.patch | patch -sp1
 notice that now the patch actually fails, so the test run lied.
>Unformatted:
