/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 bzrlib/patches.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
binary_files_re = 'Binary files (.*) and (.*) differ\n'
33
33
 
34
 
 
35
34
def get_patch_names(iter_lines):
36
 
    line = iter_lines.next()
37
35
    try:
 
36
        line = iter_lines.next()
38
37
        match = re.match(binary_files_re, line)
39
38
        if match is not None:
40
39
            raise BinaryFiles(match.group(1), match.group(2))
318
317
                if isinstance(line, ContextLine):
319
318
                    pos += 1
320
319
 
 
320
 
321
321
def parse_patch(iter_lines, allow_dirty=False):
322
322
    '''
323
323
    :arg iter_lines: iterable of lines to parse
336
336
        return patch
337
337
 
338
338
 
339
 
def iter_file_patch(iter_lines, allow_dirty=False, keep_dirty=False):
 
339
def iter_file_patch(iter_lines, allow_dirty=False):
340
340
    '''
341
341
    :arg iter_lines: iterable of lines to parse for patches
342
342
    :kwarg allow_dirty: If True, allow comments and other non-patch text
352
352
    # (as allow_dirty does).
353
353
    regex = re.compile(binary_files_re)
354
354
    saved_lines = []
355
 
    dirty_head = []
356
355
    orig_range = 0
357
356
    beginning = True
358
 
 
359
357
    for line in iter_lines:
360
 
        if line.startswith('=== '):
361
 
            if len(saved_lines) > 0:
362
 
                if keep_dirty and len(dirty_head) > 0:
363
 
                    yield {'saved_lines': saved_lines,
364
 
                           'dirty_head': dirty_head}
365
 
                    dirty_head = []
366
 
                else:
367
 
                    yield saved_lines
368
 
                saved_lines = []
369
 
            dirty_head.append(line)
370
 
            continue
371
 
        if line.startswith('*** '):
 
358
        if line.startswith('=== ') or line.startswith('*** '):
372
359
            continue
373
360
        if line.startswith('#'):
374
361
            continue
382
369
                # parse the patch
383
370
                beginning = False
384
371
            elif len(saved_lines) > 0:
385
 
                if keep_dirty and len(dirty_head) > 0:
386
 
                    yield {'saved_lines': saved_lines,
387
 
                           'dirty_head': dirty_head}
388
 
                    dirty_head = []
389
 
                else:
390
 
                    yield saved_lines
 
372
                yield saved_lines
391
373
            saved_lines = []
392
374
        elif line.startswith('@@'):
393
375
            hunk = hunk_from_header(line)
394
376
            orig_range = hunk.orig_range
395
377
        saved_lines.append(line)
396
378
    if len(saved_lines) > 0:
397
 
        if keep_dirty and len(dirty_head) > 0:
398
 
            yield {'saved_lines': saved_lines,
399
 
                   'dirty_head': dirty_head}
400
 
        else:
401
 
            yield saved_lines
 
379
        yield saved_lines
402
380
 
403
381
 
404
382
def iter_lines_handle_nl(iter_lines):
422
400
        yield last_line
423
401
 
424
402
 
425
 
def parse_patches(iter_lines, allow_dirty=False, keep_dirty=False):
 
403
def parse_patches(iter_lines, allow_dirty=False):
426
404
    '''
427
405
    :arg iter_lines: iterable of lines to parse for patches
428
406
    :kwarg allow_dirty: If True, allow text that's not part of the patch at
429
407
        selected places.  This includes comments before and after a patch
430
408
        for instance.  Default False.
431
 
    :kwarg keep_dirty: If True, returns a dict of patches with dirty headers.
432
 
        Default False.
433
409
    '''
434
 
    patches = []
435
 
    for patch_lines in iter_file_patch(iter_lines, allow_dirty, keep_dirty):
436
 
        if 'dirty_head' in patch_lines:
437
 
            patches.append({'patch': parse_patch(
438
 
                patch_lines['saved_lines'], allow_dirty),
439
 
                            'dirty_head': patch_lines['dirty_head']})
440
 
        else:
441
 
            patches.append(parse_patch(patch_lines, allow_dirty))
442
 
    return patches
 
410
    return [parse_patch(f.__iter__(), allow_dirty) for f in
 
411
                        iter_file_patch(iter_lines, allow_dirty)]
443
412
 
444
413
 
445
414
def difference_index(atext, btext):