techtonik / python-patch

Library to parse and apply unified diffs
https://pypi.python.org/pypi/patch
106 stars 63 forks source link

newlines at the end of source and target filenames #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. test.py file as follows:

import patch
patch.apply_patch(patch.read_patch('my.patch'))

2. Run script with "C:\python26\python.exe test.py"

What is the expected output? What do you see instead?

Expected: 

WARNING:root:successfully patched htdocs/index.php

Received:

WARNING:root:source/target file does not exist
--- htdocs/index.php

+++ htdocs/index.php

What version of the product are you using? On what operating system?
Using patch-8.06-2, Python 2.6.2, Win XP SP3.

Fix seems to be simple, change line 133 from:

          files["source"].append(match.group(1))

to:

          files["source"].append(match.group(1).strip())

Not sure why this hasn't affected anyone before now.

Original issue reported on code.google.com by ja...@twistedfish.com on 14 May 2009 at 4:31

GoogleCodeExporter commented 9 years ago
Thanks for report. Can you attach your.patch here for inclusion in test-suite. 
Do you
remember which tool was used to produce it?

Original comment by techtonik@gmail.com on 28 May 2009 at 5:13

GoogleCodeExporter commented 9 years ago
Fixed in r46.

Original comment by techtonik@gmail.com on 24 Aug 2009 at 9:37

GoogleCodeExporter commented 9 years ago
There are more problems with whitespaces in filenames, because various patching 
engines 
tend to stick additional information on the same line with filename. Different 
patching 
engines (hg, svn) have different unified patch formats for this info and take 
filename 
from other fields to be recognized correctly.

Please note also that there were no API (not yet), because python-patch is 
still an 
utility - not a library. API will hopefully appear with the next release, but 
won't be 
documented until it is intuitive, convenient and stable.

apply_file() and read_file() functions you've used are gone already. So, the 
correct 
invocation would be something like:

import patch
p = patch.fromfile("my.patch")
p.apply()

Original comment by techtonik@gmail.com on 24 Aug 2009 at 9:50

GoogleCodeExporter commented 9 years ago
I have tried patch.py from trunk and updated my code, all my patches seem to be
working correctly now.

Original comment by ja...@twistedfish.com on 25 Aug 2009 at 8:28

GoogleCodeExporter commented 9 years ago
Good to know. Thanks. New version is available from downloads section - I've 
made 
changes to API - moved module functions to Patch class. You may want to look at 
those.

Original comment by techtonik@gmail.com on 25 Aug 2009 at 1:31

GoogleCodeExporter commented 9 years ago
This issue was updated by revision r62.

need to strip filename also for target filename
as it is used when source filename is not found

Original comment by techtonik@gmail.com on 26 Dec 2009 at 9:20