Rev 2725: Patch parser handles diff -p patches in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Aug 17 20:28:48 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2725
revision-id: pqm at pqm.ubuntu.com-20070817192843-0jaoxooskia72irk
parent: pqm at pqm.ubuntu.com-20070817174934-5094ol577uv7ys4u
parent: abentley at panoramicfeedback.com-20070817175635-01tlqb2646s2spi5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-08-17 20:28:43 +0100
message:
Patch parser handles diff -p patches
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/patches.py patches.py-20050727183609-378c1cc5972ce908
bzrlib/tests/test_patches.py test_patches.py-20051231203844-f4974d20f6aea09c
------------------------------------------------------------
revno: 1551.2.49.1.40.1.22.1.42.1.31.1.39.1.17.1.77.1.3.1.9
merged: abentley at panoramicfeedback.com-20070817175635-01tlqb2646s2spi5
parent: abentley at panoramicfeedback.com-20070817173455-hc215yl5h4tgvorl
parent: pqm at pqm.ubuntu.com-20070817174934-5094ol577uv7ys4u
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: Aaron's mergeable stuff
timestamp: Fri 2007-08-17 13:56:35 -0400
message:
Merge from bzr.dev
------------------------------------------------------------
revno: 1551.2.49.1.40.1.22.1.42.1.31.1.39.1.17.1.77.1.3.1.8
merged: abentley at panoramicfeedback.com-20070817173455-hc215yl5h4tgvorl
parent: abentley at panoramicfeedback.com-20070817153024-f7p1aro8fzjrkybw
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: Aaron's mergeable stuff
timestamp: Fri 2007-08-17 13:34:55 -0400
message:
Update NEWS
------------------------------------------------------------
revno: 1551.2.49.1.40.1.22.1.42.1.31.1.39.1.17.1.77.1.3.1.7
merged: abentley at panoramicfeedback.com-20070817153024-f7p1aro8fzjrkybw
parent: abentley at panoramicfeedback.com-20070817134721-2urlrk8nqt19jvom
parent: pqm at pqm.ubuntu.com-20070817104128-30oe09d0jeoii7fx
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: Aaron's mergeable stuff
timestamp: Fri 2007-08-17 11:30:24 -0400
message:
merge bzr.dev
------------------------------------------------------------
revno: 1551.2.49.1.40.1.22.1.42.1.31.1.39.1.17.1.77.1.3.1.6
merged: abentley at panoramicfeedback.com-20070817134721-2urlrk8nqt19jvom
parent: abentley at panoramicfeedback.com-20070816182313-6zd5awxp1ssuu2ku
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: Aaron's mergeable stuff
timestamp: Fri 2007-08-17 09:47:21 -0400
message:
Add support for diff -p-style diffs to patch parser
=== modified file 'NEWS'
--- a/NEWS 2007-08-17 15:20:57 +0000
+++ b/NEWS 2007-08-17 17:56:35 +0000
@@ -17,9 +17,11 @@
* Suppress warning "integer argument expected, got float" from Paramiko,
which sometimes caused false test failures. (Martin Pool)
- * Fix bug in bunle 4 that could cause attempts to write data to wrong
+ * Fix bug in bundle 4 that could cause attempts to write data to wrong
versionedfile. (Aaron Bentley)
+ * Diffs generated using "diff -p" no longer break the patch parser.
+
IMPROVEMENTS:
* ``pull`` and ``merge`` are much faster at installing bundle format 4.
=== modified file 'bzrlib/patches.py'
--- a/bzrlib/patches.py 2007-05-12 19:05:12 +0000
+++ b/bzrlib/patches.py 2007-08-17 17:56:35 +0000
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import re
class PatchSyntax(Exception):
@@ -94,11 +95,11 @@
def hunk_from_header(line):
- if not line.startswith("@@") or not line.endswith("@@\n") \
- or not len(line) > 4:
- raise MalformedHunkHeader("Does not start and end with @@.", line)
+ matches = re.match(r'\@\@ ([^@]*) \@\@( (.*))?\n', line)
+ if matches is None:
+ raise MalformedHunkHeader("Does not match format.", line)
try:
- (orig, mod) = line[3:-4].split(" ")
+ (orig, mod) = matches.group(1).split(" ")
except (ValueError, IndexError), e:
raise MalformedHunkHeader(str(e), line)
if not orig.startswith('-') or not mod.startswith('+'):
@@ -110,7 +111,8 @@
raise MalformedHunkHeader(str(e), line)
if mod_range < 0 or orig_range < 0:
raise MalformedHunkHeader("Hunk range is negative", line)
- return Hunk(orig_pos, orig_range, mod_pos, mod_range)
+ tail = matches.group(3)
+ return Hunk(orig_pos, orig_range, mod_pos, mod_range, tail)
class HunkLine:
@@ -170,18 +172,24 @@
class Hunk:
- def __init__(self, orig_pos, orig_range, mod_pos, mod_range):
+ def __init__(self, orig_pos, orig_range, mod_pos, mod_range, tail=None):
self.orig_pos = orig_pos
self.orig_range = orig_range
self.mod_pos = mod_pos
self.mod_range = mod_range
+ self.tail = tail
self.lines = []
def get_header(self):
- return "@@ -%s +%s @@\n" % (self.range_str(self.orig_pos,
- self.orig_range),
- self.range_str(self.mod_pos,
- self.mod_range))
+ if self.tail is None:
+ tail_str = ''
+ else:
+ tail_str = ' ' + self.tail
+ return "@@ -%s +%s @@%s\n" % (self.range_str(self.orig_pos,
+ self.orig_range),
+ self.range_str(self.mod_pos,
+ self.mod_range),
+ tail_str)
def range_str(self, pos, range):
"""Return a file range, special-casing for 1-line files.
=== modified file 'bzrlib/tests/test_patches.py'
--- a/bzrlib/tests/test_patches.py 2007-03-03 05:47:31 +0000
+++ b/bzrlib/tests/test_patches.py 2007-08-17 13:47:21 +0000
@@ -74,6 +74,13 @@
assert (hunk.mod_range == 0)
assert (str(hunk) == header)
+ def testPDiff(self):
+ """Parse a hunk header produced by diff -p"""
+ header = "@@ -407,7 +292,7 @@ bzr 0.18rc1 2007-07-10\n"
+ hunk = hunk_from_header(header)
+ self.assertEqual('bzr 0.18rc1 2007-07-10', hunk.tail)
+ self.assertEqual(header, str(hunk))
+
def makeMalformed(self, header):
self.assertRaises(MalformedHunkHeader, hunk_from_header, header)
More information about the bazaar-commits
mailing list