Rev 3781: Add iter_patched_from_hunks to reduce API friction (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Oct 16 21:43:24 BST 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3781
revision-id: pqm at pqm.ubuntu.com-20081016204321-ayg99pvl7sr7y6qu
parent: pqm at pqm.ubuntu.com-20081016131807-r3p1hsepd24feegv
parent: aaron at aaronbentley.com-20081016190448-2a4ilw7bqsw08190
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-10-16 21:43:21 +0100
message:
Add iter_patched_from_hunks to reduce API friction (abentley)
modified:
bzrlib/patches.py patches.py-20050727183609-378c1cc5972ce908
bzrlib/tests/test_patches.py test_patches.py-20051231203844-f4974d20f6aea09c
------------------------------------------------------------
revno: 3363.18.4
revision-id: aaron at aaronbentley.com-20081016190448-2a4ilw7bqsw08190
parent: aaron at aaronbentley.com-20081014030136-8h0rtrxhq8q1d1zu
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: direct-patching
timestamp: Thu 2008-10-16 15:04:48 -0400
message:
Updates from review (and a doc update)
modified:
bzrlib/patches.py patches.py-20050727183609-378c1cc5972ce908
------------------------------------------------------------
revno: 3363.18.3
revision-id: aaron at aaronbentley.com-20081014030136-8h0rtrxhq8q1d1zu
parent: aaron at aaronbentley.com-20081014025051-hd8sbbq3yeqrb49t
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: direct-patching
timestamp: Mon 2008-10-13 23:01:36 -0400
message:
Add tests for iter_patched_from_hunks
modified:
bzrlib/patches.py patches.py-20050727183609-378c1cc5972ce908
bzrlib/tests/test_patches.py test_patches.py-20051231203844-f4974d20f6aea09c
------------------------------------------------------------
revno: 3363.18.2
revision-id: aaron at aaronbentley.com-20081014025051-hd8sbbq3yeqrb49t
parent: aaron at aaronbentley.com-20081010231442-6be32m59zo304a90
parent: aaron at aaronbentley.com-20081014024517-pu1q1kz1v51rvk9f
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: direct-patching
timestamp: Mon 2008-10-13 22:50:51 -0400
message:
Merge merge-into2 into direct-patching
added:
bzrlib/tests/blackbox/test_dump_btree.py test_dump_btree.py-20081008203335-zkpcq230b6vubszz-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
bzrlib/tree.py tree.py-20050309040759-9d5f2496be663e77
doc/developers/ppa.txt ppa.txt-20080722055539-606u7t2z32t3ae4w-1
setup.py setup.py-20050314065409-02f8a0a6e3f9bc70
------------------------------------------------------------
revno: 3363.18.1
revision-id: aaron at aaronbentley.com-20081010231442-6be32m59zo304a90
parent: aaron at aaronbentley.com-20081010225929-08pkzo68wbfr3yqg
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: merge-into2
timestamp: Fri 2008-10-10 19:14:42 -0400
message:
Allow patching directly from parsed hunks
modified:
bzrlib/patches.py patches.py-20050727183609-378c1cc5972ce908
=== modified file 'bzrlib/patches.py'
--- a/bzrlib/patches.py 2008-09-08 12:59:00 +0000
+++ b/bzrlib/patches.py 2008-10-16 19:04:48 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2004 - 2006 Aaron Bentley, Canonical Ltd
+# Copyright (C) 2004 - 2006, 2008 Aaron Bentley, Canonical Ltd
# <aaron.bentley at utoronto.ca>
#
# This program is free software; you can redistribute it and/or modify
@@ -393,13 +393,23 @@
"""Iterate through a series of lines with a patch applied.
This handles a single file, and does exact, not fuzzy patching.
"""
- if orig_lines is not None:
- orig_lines = orig_lines.__iter__()
+ patch_lines = iter_lines_handle_nl(iter(patch_lines))
+ get_patch_names(patch_lines)
+ return iter_patched_from_hunks(orig_lines, iter_hunks(patch_lines))
+
+
+def iter_patched_from_hunks(orig_lines, hunks):
+ """Iterate through a series of lines with a patch applied.
+ This handles a single file, and does exact, not fuzzy patching.
+
+ :param orig_lines: The unpatched lines.
+ :param hunks: An iterable of Hunk instances.
+ """
seen_patch = []
- patch_lines = iter_lines_handle_nl(patch_lines.__iter__())
- get_patch_names(patch_lines)
line_no = 1
- for hunk in iter_hunks(patch_lines):
+ if orig_lines is not None:
+ orig_lines = iter(orig_lines)
+ for hunk in hunks:
while line_no < hunk.orig_pos:
orig_line = orig_lines.next()
yield orig_line
=== modified file 'bzrlib/tests/test_patches.py'
--- a/bzrlib/tests/test_patches.py 2008-05-08 04:18:41 +0000
+++ b/bzrlib/tests/test_patches.py 2008-10-14 03:01:36 +0000
@@ -31,6 +31,7 @@
get_patch_names,
hunk_from_header,
iter_patched,
+ iter_patched_from_hunks,
parse_line,
parse_patch,
parse_patches)
@@ -187,6 +188,28 @@
count += 1
self.assertEqual(count, len(mod_lines))
+ def test_iter_patched_from_hunks(self):
+ """Test a few patch files, and make sure they work."""
+ files = [
+ ('diff-2', 'orig-2', 'mod-2'),
+ ('diff-3', 'orig-3', 'mod-3'),
+ ('diff-4', 'orig-4', 'mod-4'),
+ ('diff-5', 'orig-5', 'mod-5'),
+ ('diff-6', 'orig-6', 'mod-6'),
+ ]
+ for diff, orig, mod in files:
+ parsed = parse_patch(self.datafile(diff))
+ orig_lines = list(self.datafile(orig))
+ mod_lines = list(self.datafile(mod))
+ iter_patched = iter_patched_from_hunks(orig_lines, parsed.hunks)
+ patched_file = IterableFile(iter_patched)
+ lines = []
+ count = 0
+ for patch_line in patched_file:
+ self.assertEqual(patch_line, mod_lines[count])
+ count += 1
+ self.assertEqual(count, len(mod_lines))
+
def testFirstLineRenumber(self):
"""Make sure we handle lines at the beginning of the hunk"""
patch = parse_patch(self.datafile("insert_top.patch"))
More information about the bazaar-commits
mailing list