From owner-freebsd-current@FreeBSD.ORG Thu May 23 13:07:56 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D228CF73 for ; Thu, 23 May 2013 13:07:56 +0000 (UTC) (envelope-from se@freebsd.org) Received: from nm9-vm0.bullet.mail.ird.yahoo.com (nm9-vm0.bullet.mail.ird.yahoo.com [77.238.189.197]) by mx1.freebsd.org (Postfix) with SMTP id 1A53DF80 for ; Thu, 23 May 2013 13:07:55 +0000 (UTC) Received: from [77.238.189.232] by nm9.bullet.mail.ird.yahoo.com with NNFMP; 23 May 2013 13:07:53 -0000 Received: from [46.228.39.86] by tm13.bullet.mail.ird.yahoo.com with NNFMP; 23 May 2013 13:07:52 -0000 Received: from [127.0.0.1] by smtp123.mail.ir2.yahoo.com with NNFMP; 23 May 2013 13:07:52 -0000 X-Yahoo-Newman-Id: 926323.33426.bm@smtp123.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: jRO2es4VM1nVykVof6dVzLEykXH70PJBg5McpxxgQhPZysQ 8Wv7aaerUJ1vLamO2JfoAUdgnIZ5iCbvGhGO2iWg71aMiICh724q4rUwkxL0 60IzdovIdtyMuZOETGKg874aOzZnrj3vZgiDQkzkhqfv3i8u0G3CKclQmNKp MHc9HJlzhi8FpiXZ.MTr9ICe1GEIE5Wuz4e3CoO78IC9At0UAhXo3jqNPFuZ IMYeeRkbw5oNdgu13oAQkcj6BtxWG3sk8_zc5KxH3AV9tm8kCHGJ3uXzYu1l pvPyHWjxdpvzWWdHQNstDwnMA4gmOX48jdc.puf3Ty_j_8koIIn9V79GwxfL M3DQvR6Fp42cwc_nHPmlmZseKOo.4XNy6x5xQKIs9TNHXEmG03g0i3WPeKKk H0GY.40cNDmc95lG.d8yLQNDaJUtnLK7YTRIgedbS7tQxGrB1Bd3RfTP9rKQ HFgEcdoloNl_BKDVjGGeyIjzwy0XIt_m8TODC5qlDb9D48Ch_WVKfwGceV8n HLC7.ff5RpqV6ohVzCPSIsMcUqBqMv1veNjeteUraDMRX8NFvCHXekBFnNiQ - X-Yahoo-SMTP: iDf2N9.swBDAhYEh7VHfpgq0lnq. X-Rocket-Received: from StefanEsser.freebsd.org (se@87.158.30.123 with ) by smtp123.mail.ir2.yahoo.com with SMTP; 23 May 2013 13:07:52 +0000 UTC Received: by StefanEsser.freebsd.org (Postfix, from userid 200) id D2CBA4E4; Thu, 23 May 2013 15:07:51 +0200 (CEST) Date: Thu, 23 May 2013 15:07:51 +0200 From: Stefan Esser To: freebsd-current@freebsd.org Subject: [PATCH] Analysis of bug in BSD patch (was: Re: Bug in BSD patch) Message-ID: <20130523130751.GA53009@StefanEsser.freebsd.org> References: <519DBC27.9030600@gmx.com> <519DF73E.40307@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <519DF73E.40307@freebsd.org> X-Identity-Key: id3 X-Account-Key: account4 X-Mozilla-Draft-Info: internal/draft; vcard=0; receipt=0; DSN=0; uuencode=0 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 X-Enigmail-Version: 1.5.1 X-UID: 3020 Cc: se@localhost.FreeBSD.org, delphij@freebsd.org, gabor@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 May 2013 13:07:56 -0000 Am 23.05.2013 13:02, schrieb Stefan Esser: > This appears to be a problem with the new BSD patch in -CURRENT: > > # gnupatch -d /usr/ports/textproc/texi2html/work/texi2html-5.0 -E -p0 \ > -V simple -C < files/patch-texi2html.pl > Hmm... Looks like a unified diff to me... > The text leading up to this was: > -------------------------- > |--- texi2html.pl 2012-07-09 10:54:41.000000000 +0200 > |+++ /usr/local/bin/texi2html 2012-07-09 10:53:16.000000000 +0200 > -------------------------- > Patching file texi2html.pl using Plan A... > Hunk #1 succeeded at 1933. > done > > # bsdpatch -d /usr/ports/textproc/texi2html/work/texi2html-5.0 -E -p0 \ > -V simple -C < files/patch-texi2html.pl > Hmm... Looks like a unified diff to me... > The text leading up to this was: > -------------------------- > |--- texi2html.pl 2012-07-09 10:54:41.000000000 +0200 > |+++ /usr/local/bin/texi2html 2012-07-09 10:53:16.000000000 +0200 > -------------------------- > Patching file /usr/local/bin/texi2html using Plan A... > Reversed (or previously applied) patch detected! Assume -R? [y] > > Obviously, BSD patch does not select the file with the shortest > path name as the target. I have not checked the source code, but > you should definitely open a PR for this bug! Further information: The implemented logic does not follow the logic explained in the man page. Instead of using the file with the least order of path name components, shortest filename and finally shortest basename (with the search stopping as soon as one of these conditions is true), it uses the first file name to check as the reference, and only chooses another file name if *all* of the above comparisons are in favour of the latter file. This is wrong, because files with less components will only be considered, if both of the other conditions are true as well. In fact, the first filename to be checked has good chances to be selected in the end, since it only needs to be better with regard to any one of the criteria ... The following patch fixes the behaviour and makes it compliant with both the man page and GNU patch: Index: pch.c =================================================================== --- pch.c (revision 250926) +++ pch.c (working copy) @@ -1537,10 +1537,16 @@ continue; if ((tmp = num_components(names[i].path)) > min_components) continue; - min_components = tmp; + if (tmp < min_components) { + min_components = tmp; + best = names[i].path; + } if ((tmp = strlen(basename(names[i].path))) > min_baselen) continue; - min_baselen = tmp; + if (tmp < min_baselen) { + min_baselen = tmp; + best = names[i].path; + } if ((tmp = strlen(names[i].path)) > min_len) continue; min_len = tmp; Please review this patch - I'd like to commit it to HEAD if there are no objections. Regards, STefan