patchutils.py: Generate more compact autogenerated patches.

This commit is contained in:
Sebastian Lackner 2017-01-20 01:59:17 +01:00
parent 76177e1da2
commit efca1a6845
2 changed files with 96 additions and 300 deletions

File diff suppressed because it is too large Load Diff

View File

@ -506,7 +506,7 @@ def generate_ifdef_patch(original, patched, ifdef):
#
with tempfile.NamedTemporaryFile(mode='w+') as diff:
exitcode = subprocess.call(["diff", "-U", "1", original.name, patched.name],
exitcode = subprocess.call(["git", "diff", "--no-index", "--minimal", "-U1", original.name, patched.name],
stdout=diff, stderr=_devnull)
if exitcode == 0:
return None
@ -521,7 +521,11 @@ def generate_ifdef_patch(original, patched, ifdef):
fp = _PatchReader(diff.name, diff)
fp.seek(0)
# We expect this output format from 'diff', if this is not the case things might go wrong.
# We expect this output format from 'git diff', if this is not the case things might go wrong.
line = fp.read()
assert line.startswith("diff --git ")
line = fp.read()
assert line.startswith("index ")
line = fp.read()
assert line.startswith("--- ")
line = fp.read()
@ -645,7 +649,7 @@ def generate_ifdef_patch(original, patched, ifdef):
# Now we can finally compute the diff between the original file and our intermediate file
diff = tempfile.NamedTemporaryFile(mode='w+')
exitcode = subprocess.call(["git", "diff", "--no-index", original.name, intermediate.name],
exitcode = subprocess.call(["git", "diff", "--no-index", "--minimal", original.name, intermediate.name],
stdout=diff, stderr=_devnull)
if exitcode != 1: # exitcode 0 cannot (=shouldn't) happen in this situation
raise PatchDiffError("Failed to compute diff (exitcode %d)." % exitcode)