~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patch.py

  • Committer: Martin Pool
  • Date: 2005-09-16 08:23:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050916082310-ecb5a25c40253839
- wrap wide strings when showing exceptions

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import errno
2
1
import os
3
2
from subprocess import Popen, PIPE
4
 
 
5
 
from bzrlib.errors import NoDiff3
6
 
from bzrlib.textfile import check_text_path
7
3
"""
8
4
Diff and patch functionality
9
5
"""
10
6
__docformat__ = "restructuredtext"
11
7
 
12
8
def write_to_cmd(args, input=""):
13
 
    if os.name != 'nt':
14
 
        process = Popen(args, bufsize=len(input), stdin=PIPE, stdout=PIPE,
15
 
                        stderr=PIPE, close_fds=True)
16
 
    else:
17
 
        process = Popen(args, bufsize=len(input), stdin=PIPE, stdout=PIPE,
18
 
                        stderr=PIPE)
19
 
 
 
9
    process = Popen(args, bufsize=len(input), stdin=PIPE, stdout=PIPE,
 
10
                    stderr=PIPE, close_fds=True)
20
11
    stdout, stderr = process.communicate(input)
21
12
    status = process.wait()
22
13
    if status < 0:
52
43
def diff3(out_file, mine_path, older_path, yours_path):
53
44
    def add_label(args, label):
54
45
        args.extend(("-L", label))
55
 
    check_text_path(mine_path)
56
 
    check_text_path(older_path)
57
 
    check_text_path(yours_path)
58
46
    args = ['diff3', "-E", "--merge"]
59
47
    add_label(args, "TREE")
60
48
    add_label(args, "ANCESTOR")
61
49
    add_label(args, "MERGE-SOURCE")
62
50
    args.extend((mine_path, older_path, yours_path))
63
 
    try:
64
 
        output, stderr, status = write_to_cmd(args)
65
 
    except OSError, e:
66
 
        if e.errno == errno.ENOENT:
67
 
            raise NoDiff3
68
 
        else:
69
 
            raise
 
51
    output, stderr, status = write_to_cmd(args)
70
52
    if status not in (0, 1):
71
53
        raise Exception(stderr)
72
54
    file(out_file, "wb").write(output)