Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mike Frysinger | 8b0fc37 | 2022-09-08 07:24:24 | [diff] [blame] | 2 | # Copyright 2021 The ChromiumOS Authors |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 5 | |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 6 | """Compare local cherry-picks with upstream SHA1s. |
| 7 | |
| 8 | This script compares local and UPSTREAM change by pulling |
| 9 | each into a patch file and compares the two patch files using meld. |
| 10 | |
| 11 | You may need to install meld to use this script: |
| 12 | chromeos: emerge dev-vcs/git |
| 13 | debian: sudo apt-get install meld |
| 14 | |
| 15 | 1) generate list of commit messages that need to be compared. e.g.: |
| 16 | git log remotes/cros/chromeos-3.18.. > /tmp/git.log |
| 17 | |
| 18 | 2) run: upstream_diff.py /tmp/git.log |
| 19 | |
| 20 | 3) Close the meld window once you are finished inspecting to see the next one |
| 21 | """ |
| 22 | |
| 23 | import re |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 24 | from subprocess import call |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 25 | import sys |
| 26 | |
| 27 | |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 28 | commit_start = 0 |
| 29 | patchid = 1 |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 30 | l_sha = "" |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 31 | |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 32 | f = open(sys.argv[1], "r") |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 33 | |
| 34 | for line in f.readlines(): |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 35 | if l_sha != "": |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 36 | # first line with leading white space is description |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 37 | if l_descr != "": |
| 38 | if re.match("^ .*$", line): |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 39 | l_descr = line.strip() |
| 40 | |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 41 | if l_descr[0:8] != "UPSTREAM:": |
| 42 | print("----------------------") |
| 43 | print("Skipping !UPSTREAM " + l_sha[0:9] + " " + l_descr) |
| 44 | l_sha = "" |
| 45 | l_descr = "" |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 46 | continue |
| 47 | |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 48 | if re.match( |
| 49 | r"^ \(cherry picked from commit ([0-9a-f]+)", line, remote_sha |
| 50 | ): |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 51 | remote_words = line.split() |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 52 | remote_sha = remote_words[4].split(")") |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 53 | r_sha = remote_sha[0] |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 54 | r_sha_file = "%3d" % patchid + "_" + r_sha + ".patch" |
| 55 | l_sha_file = "%3d" % patchid + "_" + l_sha + ".patch" |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 56 | patchid += 1 |
| 57 | |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 58 | print("----------------------") |
| 59 | print( |
| 60 | "Comparing " |
| 61 | + l_sha[0:9] |
| 62 | + " " |
| 63 | + l_descr |
| 64 | + " AND " |
| 65 | + r_sha[0:9] |
| 66 | ) |
| 67 | print("meld", r_sha_file, l_sha_file) |
| 68 | call( |
| 69 | "git format-patch -1 " + l_sha + " --stdout > " + l_sha_file, |
| 70 | shell=True, |
| 71 | ) |
| 72 | call( |
| 73 | "git format-patch -1 " + r_sha + " --stdout > " + r_sha_file, |
| 74 | shell=True, |
| 75 | ) |
| 76 | call("meld " + l_sha_file + " " + r_sha_file, shell=True) |
| 77 | l_sha = "" |
| 78 | l_descr = "" |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 79 | |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 80 | if re.match("^commit *", line): |
| 81 | if l_sha != "": |
| 82 | print("No cherry picked SHA1 in " + l_sha[0:9] + " " + l_descr) |
Grant Grundler | 73202f7 | 2021-10-08 23:25:00 | [diff] [blame] | 83 | words = line.split() |
| 84 | l_sha = words[1] |
Jack Rosenthal | 8de609d | 2023-02-09 20:20:35 | [diff] [blame] | 85 | l_descr = "" |