bugGNU patch - Bugs: bug #28367, NEW filename always used even when...


bug #28367: NEW filename always used even when not best name

Submitted by:  Tim Waugh <twaugh>
Submitted on:  Mon 21 Dec 2009 04:39:25 PM UTC  
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  Andreas Gruenbacher <agruen>
Open/Closed:  Closed

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 24 Dec 2009 02:07:03 PM UTC, comment #2:

Thanks, that fixes it.

Tim Waugh <twaugh>
Project Member
Tue 22 Dec 2009 11:26:54 PM UTC, comment #1:

Could you please have a look at patch-2.6-4-ge2218ac.tar.gz in ftp://alpha.gnu.org/gnu/patch/? This version does not exhibit the bug anymore.

(Disclaimer: this part of the code is horrible, and I may have broken something else this time without noticing.)

Andreas Gruenbacher <agruen>
Project AdministratorIn charge of this item.
Mon 21 Dec 2009 04:39:25 PM UTC, original submission:

When a patch adds a new file, the NEW (+++) filename is always used even if it is not the "best" name as defined by the POSIX algorithm.

Original bug report:

How to reproduce:
rm -rf a b
mkdir a b
touch a/file
echo content > b/file.new
diff -u a/file b/file.new > test.patch
mkdir c
cd c
patch -p1 -i ../test.patch

Actual result:

Expected result:

Here's what the patch header looks like:

--- a/file
+++ b/file.new

Let's walk through the algorithm:

  • both names have sufficient pathname components to satisfy '-p1', so both are considered
  • there is no Index: line
  • none either OLD nor NEW file exists
  • there are no RCS files around
  • we aren't conforming to POSIX so don't have to prompt to find out the name
  • both OLD and NEW have the same number of pathname components so both are considered
  • the OLD filename has the shortest basename

We're left with only one candidate: OLD, i.e. "a/file". But patch is using NEW i.e. "b/file.new".

Tim Waugh <twaugh>
Project Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by agruen (Posted a comment)
  • -email is unavailable- added by twaugh (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-12-28 agruen StatusIn Progress => Fixed
        Open/ClosedOpen => Closed
    2009-12-22 agruen StatusNone => In Progress
        Assigned toNone => agruen

    Back to the top

    Powered by Savane 3.3