/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

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