~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

Factor out _type_equality_funcs to a new function

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 
 
18
 
from bzrlib.errors import (
19
 
    BinaryFiles,
20
 
    MalformedHunkHeader,
21
 
    MalformedLine,
22
 
    MalformedPatchHeader,
23
 
    PatchConflict,
24
 
    PatchSyntax,
25
 
    )
26
 
 
27
17
import re
28
18
 
29
19
 
30
20
binary_files_re = 'Binary files (.*) and (.*) differ\n'
31
21
 
 
22
 
 
23
class BinaryFiles(Exception):
 
24
 
 
25
    def __init__(self, orig_name, mod_name):
 
26
        self.orig_name = orig_name
 
27
        self.mod_name = mod_name
 
28
        Exception.__init__(self, 'Binary files section encountered.')
 
29
 
 
30
 
 
31
class PatchSyntax(Exception):
 
32
    def __init__(self, msg):
 
33
        Exception.__init__(self, msg)
 
34
 
 
35
 
 
36
class MalformedPatchHeader(PatchSyntax):
 
37
    def __init__(self, desc, line):
 
38
        self.desc = desc
 
39
        self.line = line
 
40
        msg = "Malformed patch header.  %s\n%r" % (self.desc, self.line)
 
41
        PatchSyntax.__init__(self, msg)
 
42
 
 
43
 
 
44
class MalformedHunkHeader(PatchSyntax):
 
45
    def __init__(self, desc, line):
 
46
        self.desc = desc
 
47
        self.line = line
 
48
        msg = "Malformed hunk header.  %s\n%r" % (self.desc, self.line)
 
49
        PatchSyntax.__init__(self, msg)
 
50
 
 
51
 
 
52
class MalformedLine(PatchSyntax):
 
53
    def __init__(self, desc, line):
 
54
        self.desc = desc
 
55
        self.line = line
 
56
        msg = "Malformed line.  %s\n%s" % (self.desc, self.line)
 
57
        PatchSyntax.__init__(self, msg)
 
58
 
 
59
 
 
60
class PatchConflict(Exception):
 
61
    def __init__(self, line_no, orig_line, patch_line):
 
62
        orig = orig_line.rstrip('\n')
 
63
        patch = str(patch_line).rstrip('\n')
 
64
        msg = 'Text contents mismatch at line %d.  Original has "%s",'\
 
65
            ' but patch says it should be "%s"' % (line_no, orig, patch)
 
66
        Exception.__init__(self, msg)
 
67
 
 
68
 
32
69
def get_patch_names(iter_lines):
33
70
    try:
34
71
        line = iter_lines.next()