~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

  • Committer: Aaron Bentley
  • Date: 2006-05-25 17:56:25 UTC
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: abentley@panoramicfeedback.com-20060525175625-c239c2e6526ffe6e
Cleanups to prepare for review

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    along with this program; if not, write to the Free Software
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
 
18
 
18
19
class PatchSyntax(Exception):
19
20
    def __init__(self, msg):
20
21
        Exception.__init__(self, msg)
27
28
        msg = "Malformed patch header.  %s\n%r" % (self.desc, self.line)
28
29
        PatchSyntax.__init__(self, msg)
29
30
 
 
31
 
30
32
class MalformedHunkHeader(PatchSyntax):
31
33
    def __init__(self, desc, line):
32
34
        self.desc = desc
34
36
        msg = "Malformed hunk header.  %s\n%r" % (self.desc, self.line)
35
37
        PatchSyntax.__init__(self, msg)
36
38
 
 
39
 
37
40
class MalformedLine(PatchSyntax):
38
41
    def __init__(self, desc, line):
39
42
        self.desc = desc
41
44
        msg = "Malformed line.  %s\n%s" % (self.desc, self.line)
42
45
        PatchSyntax.__init__(self, msg)
43
46
 
 
47
 
44
48
def get_patch_names(iter_lines):
45
49
    try:
46
50
        line = iter_lines.next()
60
64
        raise MalformedPatchHeader("No mod line", "")
61
65
    return (orig_name, mod_name)
62
66
 
 
67
 
63
68
def parse_range(textrange):
64
69
    """Parse a patch range, handling the "1" special-case
65
70
 
215
220
                break
216
221
        return shift
217
222
 
 
223
 
218
224
def iter_hunks(iter_lines):
219
225
    hunk = None
220
226
    for line in iter_lines:
238
244
    if hunk is not None:
239
245
        yield hunk
240
246
 
 
247
 
241
248
class Patch:
242
249
    def __init__(self, oldname, newname):
243
250
        self.oldname = oldname
289
296
                if isinstance(line, ContextLine):
290
297
                    pos += 1
291
298
 
 
299
 
292
300
def parse_patch(iter_lines):
293
301
    (orig_name, mod_name) = get_patch_names(iter_lines)
294
302
    patch = Patch(orig_name, mod_name)
354
362
            return i;
355
363
    return None
356
364
 
 
365
 
357
366
class PatchConflict(Exception):
358
367
    def __init__(self, line_no, orig_line, patch_line):
359
368
        orig = orig_line.rstrip('\n')
394
403
    if orig_lines is not None:
395
404
        for line in orig_lines:
396
405
            yield line
397
 
                    
 
406
 
 
407
 
398
408
import unittest
399
409
import os.path
 
410
 
 
411
 
400
412
class PatchesTester(unittest.TestCase):
401
413
    def datafile(self, filename):
402
414
        data_path = os.path.join(os.path.dirname(__file__), "testdata", 
518
530
+__doc__ = An alternate Arch commandline interface
519
531
"""
520
532
        self.compare_parsed(patchtext)
521
 
        
522
 
 
523
533
 
524
534
    def testLineLookup(self):
525
535
        import sys