/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/patches.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    )
23
23
 
24
24
import re
25
 
import sys
26
25
 
27
26
 
28
27
binary_files_re = b'Binary files (.*) and (.*) differ\n'
185
184
    def as_bytes(self):
186
185
        return self.get_str(b"-")
187
186
 
 
187
 
188
188
NO_NL = b'\\ No newline at end of file\n'
189
 
__pychecker__="no-returnvalues"
 
189
__pychecker__ = "no-returnvalues"
 
190
 
190
191
 
191
192
def parse_line(line):
192
193
    if line.startswith(b"\n"):
199
200
        return RemoveLine(line[1:])
200
201
    else:
201
202
        raise MalformedLine("Unknown line type", line)
202
 
__pychecker__=""
 
203
 
 
204
 
 
205
__pychecker__ = ""
203
206
 
204
207
 
205
208
class Hunk(object):
218
221
        else:
219
222
            tail_str = b' ' + self.tail
220
223
        return b"@@ -%s +%s @@%s\n" % (self.range_str(self.orig_pos,
221
 
                                                     self.orig_range),
222
 
                                      self.range_str(self.mod_pos,
223
 
                                                     self.mod_range),
224
 
                                      tail_str)
 
224
                                                      self.orig_range),
 
225
                                       self.range_str(self.mod_pos,
 
226
                                                      self.mod_range),
 
227
                                       tail_str)
225
228
 
226
229
    def range_str(self, pos, range):
227
230
        """Return a file range, special-casing for 1-line files.
246
249
    __bytes__ = as_bytes
247
250
 
248
251
    def shift_to_mod(self, pos):
249
 
        if pos < self.orig_pos-1:
 
252
        if pos < self.orig_pos - 1:
250
253
            return 0
251
 
        elif pos > self.orig_pos+self.orig_range:
 
254
        elif pos > self.orig_pos + self.orig_range:
252
255
            return self.mod_range - self.orig_range
253
256
        else:
254
257
            return self.shift_to_mod_lines(pos)
255
258
 
256
259
    def shift_to_mod_lines(self, pos):
257
 
        position = self.orig_pos-1
 
260
        position = self.orig_pos - 1
258
261
        shift = 0
259
262
        for line in self.lines:
260
263
            if isinstance(line, InsertLine):
340
343
        for hunk in self.hunks:
341
344
            for line in hunk.lines:
342
345
                if isinstance(line, InsertLine):
343
 
                     inserts+=1;
 
346
                    inserts += 1
344
347
                elif isinstance(line, RemoveLine):
345
 
                     removes+=1;
 
348
                    removes += 1
346
349
        return (inserts, removes, len(self.hunks))
347
350
 
348
351
    def stats_str(self):
366
369
        :rtype: iterator of (int, InsertLine)
367
370
        """
368
371
        for hunk in self.hunks:
369
 
            pos = hunk.mod_pos - 1;
 
372
            pos = hunk.mod_pos - 1
370
373
            for line in hunk.lines:
371
374
                if isinstance(line, InsertLine):
372
375
                    yield (pos, line)
402
405
        first patch are stripped away in iter_hunks() if it is also passed
403
406
        allow_dirty=True.  Default False.
404
407
    '''
405
 
    ### FIXME: Docstring is not quite true.  We allow certain comments no
 
408
    # FIXME: Docstring is not quite true.  We allow certain comments no
406
409
    # matter what, If they startwith '===', '***', or '#' Someone should
407
410
    # reexamine this logic and decide if we should include those in
408
411
    # allow_dirty or restrict those to only being before the patch is found
511
514
        length = len(btext)
512
515
    for i in range(length):
513
516
        if atext[i] != btext[i]:
514
 
            return i;
 
517
            return i
515
518
    return None
516
519
 
517
520
 
547
550
            elif isinstance(hunk_line, (ContextLine, RemoveLine)):
548
551
                orig_line = next(orig_lines)
549
552
                if orig_line != hunk_line.contents:
550
 
                    raise PatchConflict(line_no, orig_line, b"".join(seen_patch))
 
553
                    raise PatchConflict(line_no, orig_line,
 
554
                                        b"".join(seen_patch))
551
555
                if isinstance(hunk_line, ContextLine):
552
556
                    yield orig_line
553
557
                else: