diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-11-07 12:47:12 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-11-07 12:47:12 +0100 |
commit | 8240fb9c736f91044cabbdde8c537b179fc4921e (patch) | |
tree | 49a4cc8dc683cf955d61b6618ad471860554ccb5 /third_party/aom/tools/intersect-diffs.py | |
parent | f9e04b54c2ccbc1f8e24b511003de09b4565193c (diff) | |
parent | 5c83a18cde404b5c0c9fba1d35f003d951ea32e2 (diff) | |
download | UXP-8240fb9c736f91044cabbdde8c537b179fc4921e.tar UXP-8240fb9c736f91044cabbdde8c537b179fc4921e.tar.gz UXP-8240fb9c736f91044cabbdde8c537b179fc4921e.tar.lz UXP-8240fb9c736f91044cabbdde8c537b179fc4921e.tar.xz UXP-8240fb9c736f91044cabbdde8c537b179fc4921e.zip |
Merge branch 'master' into Pale_Moon-release
# Conflicts:
# application/palemoon/config/version.txt
Diffstat (limited to 'third_party/aom/tools/intersect-diffs.py')
-rwxr-xr-x | third_party/aom/tools/intersect-diffs.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/third_party/aom/tools/intersect-diffs.py b/third_party/aom/tools/intersect-diffs.py new file mode 100755 index 000000000..df13c4ef7 --- /dev/null +++ b/third_party/aom/tools/intersect-diffs.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +## +## Copyright (c) 2016, Alliance for Open Media. All rights reserved +## +## This source code is subject to the terms of the BSD 2 Clause License and +## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License +## was not distributed with this source code in the LICENSE file, you can +## obtain it at www.aomedia.org/license/software. If the Alliance for Open +## Media Patent License 1.0 was not distributed with this source code in the +## PATENTS file, you can obtain it at www.aomedia.org/license/patent. +## +"""Calculates the "intersection" of two unified diffs. + +Given two diffs, A and B, it finds all hunks in B that had non-context lines +in A and prints them to stdout. This is useful to determine the hunks in B that +are relevant to A. The resulting file can be applied with patch(1) on top of A. +""" + +__author__ = "jkoleszar@google.com" + +import sys + +import diff + + +def FormatDiffHunks(hunks): + """Re-serialize a list of DiffHunks.""" + r = [] + last_header = None + for hunk in hunks: + this_header = hunk.header[0:2] + if last_header != this_header: + r.extend(hunk.header) + last_header = this_header + else: + r.extend(hunk.header[2]) + r.extend(hunk.lines) + r.append("\n") + return "".join(r) + + +def ZipHunks(rhs_hunks, lhs_hunks): + """Join two hunk lists on filename.""" + for rhs_hunk in rhs_hunks: + rhs_file = rhs_hunk.right.filename.split("/")[1:] + + for lhs_hunk in lhs_hunks: + lhs_file = lhs_hunk.left.filename.split("/")[1:] + if lhs_file != rhs_file: + continue + yield (rhs_hunk, lhs_hunk) + + +def main(): + old_hunks = [x for x in diff.ParseDiffHunks(open(sys.argv[1], "r"))] + new_hunks = [x for x in diff.ParseDiffHunks(open(sys.argv[2], "r"))] + out_hunks = [] + + # Join the right hand side of the older diff with the left hand side of the + # newer diff. + for old_hunk, new_hunk in ZipHunks(old_hunks, new_hunks): + if new_hunk in out_hunks: + continue + old_lines = old_hunk.right + new_lines = new_hunk.left + + # Determine if this hunk overlaps any non-context line from the other + for i in old_lines.delta_line_nums: + if i in new_lines: + out_hunks.append(new_hunk) + break + + if out_hunks: + print FormatDiffHunks(out_hunks) + sys.exit(1) + +if __name__ == "__main__": + main() |