blob: e0c10c59638982d361a7170500a94b860e84b050 [file] [log] [blame]
Grant Grundler73202f72021-10-08 23:25:001#!/usr/bin/env python3
Mike Frysinger8b0fc372022-09-08 07:24:242# Copyright 2021 The ChromiumOS Authors
Grant Grundler73202f72021-10-08 23:25:003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
Jack Rosenthal8de609d2023-02-09 20:20:355
Grant Grundler73202f72021-10-08 23:25:006"""Compare local cherry-picks with upstream SHA1s.
7
8This script compares local and UPSTREAM change by pulling
9each into a patch file and compares the two patch files using meld.
10
11You may need to install meld to use this script:
12chromeos: emerge dev-vcs/git
13debian: sudo apt-get install meld
14
151) generate list of commit messages that need to be compared. e.g.:
16 git log remotes/cros/chromeos-3.18.. > /tmp/git.log
17
182) run: upstream_diff.py /tmp/git.log
19
203) Close the meld window once you are finished inspecting to see the next one
21"""
22
23import re
Grant Grundler73202f72021-10-08 23:25:0024from subprocess import call
Jack Rosenthal8de609d2023-02-09 20:20:3525import sys
26
27
Grant Grundler73202f72021-10-08 23:25:0028commit_start = 0
29patchid = 1
Jack Rosenthal8de609d2023-02-09 20:20:3530l_sha = ""
Grant Grundler73202f72021-10-08 23:25:0031
Jack Rosenthal8de609d2023-02-09 20:20:3532f = open(sys.argv[1], "r")
Grant Grundler73202f72021-10-08 23:25:0033
34for line in f.readlines():
Jack Rosenthal8de609d2023-02-09 20:20:3535 if l_sha != "":
Grant Grundler73202f72021-10-08 23:25:0036 # first line with leading white space is description
Jack Rosenthal8de609d2023-02-09 20:20:3537 if l_descr != "":
38 if re.match("^ .*$", line):
Grant Grundler73202f72021-10-08 23:25:0039 l_descr = line.strip()
40
Jack Rosenthal8de609d2023-02-09 20:20:3541 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 Grundler73202f72021-10-08 23:25:0046 continue
47
Jack Rosenthal8de609d2023-02-09 20:20:3548 if re.match(
49 r"^ \(cherry picked from commit ([0-9a-f]+)", line, remote_sha
50 ):
Grant Grundler73202f72021-10-08 23:25:0051 remote_words = line.split()
Jack Rosenthal8de609d2023-02-09 20:20:3552 remote_sha = remote_words[4].split(")")
Grant Grundler73202f72021-10-08 23:25:0053 r_sha = remote_sha[0]
Jack Rosenthal8de609d2023-02-09 20:20:3554 r_sha_file = "%3d" % patchid + "_" + r_sha + ".patch"
55 l_sha_file = "%3d" % patchid + "_" + l_sha + ".patch"
Grant Grundler73202f72021-10-08 23:25:0056 patchid += 1
57
Jack Rosenthal8de609d2023-02-09 20:20:3558 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 Grundler73202f72021-10-08 23:25:0079
Jack Rosenthal8de609d2023-02-09 20:20:3580 if re.match("^commit *", line):
81 if l_sha != "":
82 print("No cherry picked SHA1 in " + l_sha[0:9] + " " + l_descr)
Grant Grundler73202f72021-10-08 23:25:0083 words = line.split()
84 l_sha = words[1]
Jack Rosenthal8de609d2023-02-09 20:20:3585 l_descr = ""