~gz/bzr-grep/no_match_fast_path

« back to all changes in this revision

Viewing changes to grep.py

  • Committer: Martin
  • Date: 2010-06-02 15:54:10 UTC
  • Revision ID: gzlist@googlemail.com-20100602155410-14jx7338rs1ujyg0
Make -Fi use regexps for re.IGNORECASE rather than double str.lower

Show diffs side-by-side

added added

removed removed

Lines of Context:
355
355
    found = False
356
356
    if opts.fixed_string:
357
357
        pattern = opts.pattern.encode(_user_encoding, 'replace')
358
 
        if opts.fixed_string and opts.ignore_case:
359
 
            pattern = opts.pattern.lower()
360
 
        if opts.ignore_case:
361
 
            for line in file:
362
 
                line = line.lower()
363
 
                if pattern in line:
364
 
                    found = True
365
 
                    break
366
 
        else: # don't ignore case
367
 
            for line in file:
368
 
                if pattern in line:
369
 
                    found = True
370
 
                    break
 
358
        for line in file:
 
359
            if pattern in line:
 
360
                found = True
 
361
                break
371
362
    else: # not fixed_string
372
363
        for line in file:
373
364
            if opts.patternc.search(line):
396
387
    patternc = opts.patternc
397
388
    eol_marker = opts.eol_marker
398
389
 
399
 
    if opts.fixed_string and opts.ignore_case:
400
 
        pattern = opts.pattern.lower()
401
 
 
402
390
    # test and skip binary files
403
391
    if '\x00' in file_text[:1024]:
404
392
        if opts.verbose:
427
415
        if opts.print_revno:
428
416
            if opts.fixed_string:
429
417
                for line in file_text.splitlines():
430
 
                    if opts.ignore_case:
431
 
                        line = line.lower()
432
418
                    if pattern in line:
433
419
                        found = True
434
420
                        break
440
426
        else:
441
427
            if opts.fixed_string:
442
428
                for line in file_text.splitlines():
443
 
                    if opts.ignore_case:
444
 
                        line = line.lower()
445
429
                    if pattern in line:
446
430
                        found = True
447
431
                        break
472
456
            pfmt = pfmt.encode(_te)
473
457
 
474
458
        if opts.fixed_string:
475
 
            if opts.ignore_case:
476
 
                for index, line in enumerate(file_text.splitlines()):
477
 
                    if pattern in line.lower():
478
 
                        line = line.decode(_te, 'replace')
479
 
                        if opts.show_color:
480
 
                            line = re_color_string(opts.sub_patternc, line, FG.BOLD_RED)
481
 
                        s = path + (pfmt % (revno, index+1, line)) + eol_marker
482
 
                        res_append(s)
483
 
                        outf_write(s)
484
 
            else: # don't ignore case
485
 
                found_str = color_string(pattern, FG.BOLD_RED)
486
 
                for index, line in enumerate(file_text.splitlines()):
487
 
                    if pattern in line:
488
 
                        line = line.decode(_te, 'replace')
489
 
                        if opts.show_color == True:
490
 
                            line = line.replace(pattern, found_str)
491
 
                        s = path + (pfmt % (revno, index+1, line)) + eol_marker
492
 
                        res_append(s)
493
 
                        outf_write(s)
 
459
            found_str = color_string(pattern, FG.BOLD_RED)
 
460
            for index, line in enumerate(file_text.splitlines()):
 
461
                if pattern in line:
 
462
                    line = line.decode(_te, 'replace')
 
463
                    if opts.show_color == True:
 
464
                        line = line.replace(pattern, found_str)
 
465
                    s = path + (pfmt % (revno, index+1, line)) + eol_marker
 
466
                    res_append(s)
 
467
                    outf_write(s)
494
468
        else:
495
469
            for index, line in enumerate(file_text.splitlines()):
496
470
                if patternc.search(line):
509
483
            pfmt = pfmt.encode(_te)
510
484
 
511
485
        if opts.fixed_string:
512
 
            if opts.ignore_case:
513
 
                for line in file_text.splitlines():
514
 
                    if pattern in line.lower():
515
 
                        line = line.decode(_te, 'replace')
516
 
                        if opts.show_color:
517
 
                            line = re_color_string(opts.sub_patternc, line, FG.BOLD_RED)
518
 
                        s = path + (pfmt % (revno, line)) + eol_marker
519
 
                        res_append(s)
520
 
                        outf_write(s)
521
 
            else: # don't ignore case
522
 
                found_str = color_string(pattern, FG.BOLD_RED)
523
 
                for line in file_text.splitlines():
524
 
                    if pattern in line:
525
 
                        line = line.decode(_te, 'replace')
526
 
                        if opts.show_color == True:
527
 
                            line = line.replace(pattern, found_str)
528
 
                        s = path + (pfmt % (revno, line)) + eol_marker
529
 
                        res_append(s)
530
 
                        outf_write(s)
 
486
            found_str = color_string(pattern, FG.BOLD_RED)
 
487
            for line in file_text.splitlines():
 
488
                if pattern in line:
 
489
                    line = line.decode(_te, 'replace')
 
490
                    if opts.show_color == True:
 
491
                        line = line.replace(pattern, found_str)
 
492
                    s = path + (pfmt % (revno, line)) + eol_marker
 
493
                    res_append(s)
 
494
                    outf_write(s)
531
495
 
532
496
        else:
533
497
            for line in file_text.splitlines():
547
511
            pfmt = pfmt.encode(_te)
548
512
 
549
513
        if opts.fixed_string:
550
 
            if opts.ignore_case:
551
 
                for index, line in enumerate(file_text.splitlines()):
552
 
                    if pattern in line.lower():
553
 
                        line = line.decode(_te, 'replace')
554
 
                        if opts.show_color:
555
 
                            line = re_color_string(opts.sub_patternc, line, FG.BOLD_RED)
556
 
                        s = path + (pfmt % (index+1, line)) + eol_marker
557
 
                        res_append(s)
558
 
                        outf_write(s)
559
 
            else: # don't ignore case
560
 
                for index, line in enumerate(file_text.splitlines()):
561
 
                    found_str = color_string(pattern, FG.BOLD_RED)
562
 
                    if pattern in line:
563
 
                        line = line.decode(_te, 'replace')
564
 
                        if opts.show_color == True:
565
 
                            line = line.replace(pattern, found_str)
566
 
                        s = path + (pfmt % (index+1, line)) + eol_marker
567
 
                        res_append(s)
568
 
                        outf_write(s)
 
514
            for index, line in enumerate(file_text.splitlines()):
 
515
                found_str = color_string(pattern, FG.BOLD_RED)
 
516
                if pattern in line:
 
517
                    line = line.decode(_te, 'replace')
 
518
                    if opts.show_color == True:
 
519
                        line = line.replace(pattern, found_str)
 
520
                    s = path + (pfmt % (index+1, line)) + eol_marker
 
521
                    res_append(s)
 
522
                    outf_write(s)
569
523
        else:
570
524
            for index, line in enumerate(file_text.splitlines()):
571
525
                if patternc.search(line):
584
538
            pfmt = pfmt.encode(_te)
585
539
 
586
540
        if opts.fixed_string:
587
 
            if opts.ignore_case:
588
 
                for line in file_text.splitlines():
589
 
                    if pattern in line.lower():
590
 
                        line = line.decode(_te, 'replace')
591
 
                        if opts.show_color:
592
 
                            line = re_color_string(opts.sub_patternc, line, FG.BOLD_RED)
593
 
                        s = path + (pfmt % (line,)) + eol_marker
594
 
                        res_append(s)
595
 
                        outf_write(s)
596
 
            else: # don't ignore case
597
 
                found_str = color_string(pattern, FG.BOLD_RED)
598
 
                for line in file_text.splitlines():
599
 
                    if pattern in line:
600
 
                        line = line.decode(_te, 'replace')
601
 
                        if opts.show_color:
602
 
                            line = line.replace(pattern, found_str)
603
 
                        s = path + (pfmt % (line,)) + eol_marker
604
 
                        res_append(s)
605
 
                        outf_write(s)
 
541
            found_str = color_string(pattern, FG.BOLD_RED)
 
542
            for line in file_text.splitlines():
 
543
                if pattern in line:
 
544
                    line = line.decode(_te, 'replace')
 
545
                    if opts.show_color:
 
546
                        line = line.replace(pattern, found_str)
 
547
                    s = path + (pfmt % (line,)) + eol_marker
 
548
                    res_append(s)
 
549
                    outf_write(s)
606
550
        else:
607
551
            for line in file_text.splitlines():
608
552
                if patternc.search(line):