How to use the breezy._patiencediff_py.PatienceSequenceMatcher_py function in breezy

To help you get started, we’ve selected a few breezy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pierstitus / klondiff / patiencediff.py View on Github external
if os.path.split(sys.argv[0])[1].startswith('klondi'):
        default_matcher = 'klondike'
    p = optparse.OptionParser(usage='%prog [options] file_a file_b'
                                    '\nFiles can be "-" to read from stdin')
    p.add_option('--patience', dest='matcher', action='store_const', const='patience',
                 default=default_matcher, help='Use the patience difference algorithm')
    p.add_option('--difflib', dest='matcher', action='store_const', const='difflib',
                 default=default_matcher, help='Use python\'s difflib algorithm')
    p.add_option('--klondike', dest='matcher', action='store_const', const='klondike',
                 default=default_matcher, help='Use the klondike diff algorithm')
    # TODO: implement more command line options
    #p.add_option('--unified', '-u', help='output NUM (default 3) lines of unified context')
    #p.add_option('--show-function-line', '-F', help='show the most recent line matching RE')
    #p.add_option('--color', '-c')

    algorithms = {'patience':PatienceSequenceMatcher, 'difflib':difflib.SequenceMatcher, 'klondike':KlondikeSequenceMatcher,}

    (opts, args) = p.parse_args(args)
    matcher = algorithms[opts.matcher]

    colordiff_writer = colordiff.DiffWriter(sys.stdout, color='always')
    def print_color(type, line):
        colordiff_writer.target.writelines(colordiff_writer.colorstring(type, line) + '\n')

    # check for git external diff syntax
    # TODO: check if git header is correct, old/new mode isn't handled
    displaynames = None
    if len(args) == 7:
        displaynames = ['a/' + args[0], 'b/' + args[0]]
        print_color('metaline', 'diff --git {0} {1}'.format(*displaynames))
        if '/dev/null' == args[1]:
            print_color('metaline', 'new file mode ' + args[6])

breezy

Friendly distributed version control system

GPL-2.0
Latest version published 19 days ago

Package Health Score

78 / 100
Full package analysis

Similar packages