File: xx-p4-unmerge

package info (click to toggle)
xxdiff 1%3A4.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,716 kB
  • ctags: 2,245
  • sloc: cpp: 18,495; python: 6,134; sh: 1,543; ansic: 1,535; perl: 308; lex: 284; yacc: 279; lisp: 250; tcl: 213; makefile: 82
file content (64 lines) | stat: -rwxr-xr-x 1,775 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
A wrapper script that will split up a p4 file with merge conflicts to three
files and invoke xxdiff on it.
"""

# stdlib imports
import sys, os, shutil, re, StringIO, tempfile

# xxdiff imports
from xxdiff import invoke


def unmerge_file(filename):
    file_original = tempfile.NamedTemporaryFile()
    file_theirs = tempfile.NamedTemporaryFile()
    file_yours = tempfile.NamedTemporaryFile()
    files = file_original, file_theirs, file_yours
    file_current = None
    for line in open(filename):
        if line.startswith('>>>> ORIGINAL'):
            file_current = file_original
        elif line.startswith('==== THEIRS'):
            file_current = file_theirs
        elif line.startswith('==== YOURS'):
            file_current = file_yours
        elif line.startswith('<<<<'):
            file_current = None
        elif file_current is None:
            for file_ in files:
                file_.write(line)
        else:
            file_current.write(line)
    for file_ in files:
        file_.flush()
    return files


def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())
    invoke.options_graft(parser)
    opts, args = parser.parse_args()
    invoke.options_validate(opts, parser)

    if len(args) != 1:
        parser.error("You need to provide 1 file argumnet.")
    filename, = args

    file_original, file_theirs, file_yours = unmerge_file(filename)


    # Invoke xxdiff.
    decision, mergedf, __retcode = invoke.xxdiff_decision(
        opts,
        '--merged-filename=%s' % filename,
        '--title1=Current',
        '--title2=Ancestor',
        '--title3=Merging',
        file_yours.name, file_original.name, file_theirs.name)


if __name__ == '__main__':
    sys.exit(main())