~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

Allow external diff to write to a file without a fileno.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
def external_diff(old_filename, oldlines, new_filename, newlines, to_file,
87
87
                  diff_opts):
88
88
    """Display a diff by calling out to the external diff program."""
89
 
    if not hasattr(to_file, 'fileno'):
90
 
        raise NotImplementedError("sorry, can't send external diff other "
91
 
                                  "than to a file descriptor", to_file)
 
89
    if hasattr(to_file, 'fileno'):
 
90
        out_file = to_file
 
91
        have_fileno = True
 
92
    else:
 
93
        out_file = subprocess.PIPE
 
94
        have_fileno = False
92
95
    
93
96
    # make sure our own output is properly ordered before the diff
94
97
    to_file.flush()
149
152
        try:
150
153
            pipe = subprocess.Popen(diffcmd,
151
154
                                    stdin=subprocess.PIPE,
152
 
                                    stdout=to_file)
 
155
                                    stdout=out_file)
153
156
        except OSError, e:
154
157
            if e.errno == errno.ENOENT:
155
158
                raise errors.NoDiff(str(e))
156
159
            raise
157
160
        pipe.stdin.close()
 
161
 
 
162
        if not have_fileno:
 
163
            to_file.write(pipe.stdout.read())
158
164
        rc = pipe.wait()
159
165
        
160
166
        if rc != 0 and rc != 1: