/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/patch.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import os
24
24
from subprocess import Popen, PIPE
25
25
import sys
26
 
import tempfile
27
26
 
28
27
from .errors import NoDiff3, BzrError
29
28
from .textfile import check_text_path
63
62
    stdout, stderr = process.communicate(input)
64
63
    status = process.wait()
65
64
    if status < 0:
66
 
        raise Exception("%s killed by signal %i" % (args[0], -status))
 
65
        raise Exception("%s killed by signal %i" (args[0], -status))
67
66
    return stdout, stderr, status
68
67
 
69
68
 
176
175
        raise PatchFailed()
177
176
 
178
177
    return result
179
 
 
180
 
 
181
 
def iter_patched_from_hunks(orig_lines, hunks):
182
 
    """Iterate through a series of lines with a patch applied.
183
 
    This handles a single file, and does exact, not fuzzy patching.
184
 
 
185
 
    :param orig_lines: The unpatched lines.
186
 
    :param hunks: An iterable of Hunk instances.
187
 
 
188
 
    This is different from breezy.patches in that it invokes the patch
189
 
    command.
190
 
    """
191
 
    with tempfile.NamedTemporaryFile() as f:
192
 
        f.writelines(orig_lines)
193
 
        f.flush()
194
 
        # TODO(jelmer): Stream patch contents to command, rather than
195
 
        # serializing the entire patch upfront.
196
 
        serialized = b''.join([hunk.as_bytes() for hunk in hunks])
197
 
        args = ["patch", "-f", "-s", "--posix", "--binary",
198
 
                "-o", "-", f.name, "-r", "-"]
199
 
        stdout, stderr, status = write_to_cmd(args, serialized)
200
 
    if status == 0:
201
 
        return [stdout]
202
 
    raise PatchFailed(stderr)