From charnier@xp11.frmug.org  Wed Apr  2 12:59:27 1997
Received: from frmug.org (frmug-gw.frmug.org [193.56.58.252])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id MAA23881
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 2 Apr 1997 12:59:23 -0800 (PST)
Received: (from uucp@localhost)
	by frmug.org (8.8.5/8.8.5/frmug-2.0) with UUCP id WAA27333
	for FreeBSD-gnats-submit@freebsd.org; Wed, 2 Apr 1997 22:59:12 +0200 (MET DST)
Received: (from charnier@localhost)
	by xp11.frmug.org (8.8.5/8.8.5/xp11-uucp-1.1) id WAA05260;
	Wed, 2 Apr 1997 22:52:57 +0200 (CEST)
Message-Id: <199704022052.WAA05260@xp11.frmug.org>
Date: Wed, 2 Apr 1997 22:52:57 +0200 (CEST)
From: Philippe Charnier <charnier@xp11.frmug.org>
Reply-To: charnier@xp11.frmug.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: `patch' creates files in wrong places (following Index)
X-Send-Pr-Version: 3.2

>Number:         3176
>Category:       gnu
>Synopsis:       `patch' creates files in wrong places
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr  2 13:00:01 PST 1997
>Closed-Date:    Fri May 9 17:56:59 MEST 1997
>Last-Modified:  Fri May  9 17:57:36 MEST 1997
>Originator:     Philippe Charnier
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:

	

>Description:

	

>How-To-Repeat:

mkdir -p a-1.0/b
then create the patch file (called file.patch):
	Index: b/file
	--- /dev/null   Wed Apr  2 20:33:10 1997
	+++ a-2.0/b/file        Wed Apr  2 21:58:35 1997
	@@ -0,0 +1 @@
	+version 2

cd a-1.0
patch -p1 -N < ../file.patch
	Hmm...  Looks like a unified diff to me...
	The text leading up to this was:
	--------------------------
	|Index: b/file
	|--- /dev/null  Wed Apr  2 20:33:10 1997
	|+++ a-2.0/b/file       Wed Apr  2 21:58:35 1997
	--------------------------
	(Creating file file...)                 <------------- should be b/file
	Patching file file using Plan A...
	Hunk #1 succeeded at 1.
	done

>Fix:
	
If the line `Index: b/file' is not provided, the command works as expected. If
not, the -p1 option is applied against Index. Maybe something like that:
in pch.c
  - indname = fetchname(indtmp, strippath, ok_to_create_file);
  + indname = fetchname(indtmp, 957, ok_to_create_file);

  - bestguess = fetchname(indtmp, strippath, TRUE);
  + bestguess = fetchname(indtmp, 957, TRUE);


Obtained when trying to patch perl (-p1 -N):

Index: lib/ExtUtils/Command.pm
*** /dev/null   Fri Mar 21 23:14:07 1997
--- perl5.003_94/lib/ExtUtils/Command.pm        Fri Mar 21 21:45:47 1997
***************

Creates ExtUtils/Command.pm instead of lib/ExtUtils/Command.pm

ps: /usr/src/gnu/usr.bin/patch/* contains $Log$ that should be removed.
>Release-Note:
>Audit-Trail:

From: j@uriah.heep.sax.de (J Wunsch)
To: charnier@xp11.frmug.org
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: gnu/3176: `patch' creates files in wrong places (following Index)
Date: Wed, 2 Apr 1997 23:47:14 +0200

 As Philippe Charnier wrote:
 
 > cd a-1.0
 > patch -p1 -N < ../file.patch
 > 	Hmm...  Looks like a unified diff to me...
 > 	The text leading up to this was:
 > 	--------------------------
 > 	|Index: b/file
 > 	|--- /dev/null  Wed Apr  2 20:33:10 1997
 > 	|+++ a-2.0/b/file       Wed Apr  2 21:58:35 1997
 > 	--------------------------
 > 	(Creating file file...)                 <------------- should be b/file
 > 	Patching file file using Plan A...
 > 	Hunk #1 succeeded at 1.
 > 	done
 > 
 > >Fix:
 
 > If the line `Index: b/file' is not provided, the command works as
 > expected. If not, the -p1 option is applied against Index.
 
 This is expected behaviour.
 
    ``The
      Index  line, if present, takes precedence over the context
      diff header.''
 
 Options like -p1 are applied after guessing the filename, so it will
 be applied to `b/file' in your case, stripping the `b/' of it, and
 leaving just `file'.
 
 ``Fixing'' this behaviour would royally screw CVS diffs that heavily
 rely on the Index: magic.
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)
State-Changed-From-To: open->closed 
State-Changed-By: joerg 
State-Changed-When: Fri May 9 17:56:59 MEST 1997 
State-Changed-Why:  
That's expected behaviour and documented in the man page.  See the 
audit trail for a discussion. 
>Unformatted:
