findmissing: getopen: Identify and report subsequent fixes

Subsequent fixes are fixes of patches which have been identified
as missing. Report those as well.

BUG=None
TEST=Run getopen tool

Change-Id: I416313bc0e6f2fd246bc1cd6707d68321a56f8f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2216803
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Tested-by: Guenter Roeck <groeck@chromium.org>
Commit-Queue: Curtis Malainey <cujomalainey@chromium.org>
diff --git a/contrib/findmissing/getopen.py b/contrib/findmissing/getopen.py
index 1a52536..74cbea3 100755
--- a/contrib/findmissing/getopen.py
+++ b/contrib/findmissing/getopen.py
@@ -29,8 +29,10 @@
 import argparse
 import re
 import MySQLdb
+
 import common
 import git_interface
+import missing
 import synchronize
 import util
 
@@ -189,6 +191,24 @@
                 branch_name = branch_name_pattern % affected_branch
                 report_integration_status_sha(metadata.path, merge_base, branch_name, fixedby_sha)
 
+        # Check if this commit has been fixed as well and, if so, report it
+        subsequent_fixes = missing.get_subsequent_fixes(db, fixedby_sha)
+        # remove initial fix
+        subsequent_fixes.pop(0)
+        if subsequent_fixes:
+            subsequent_fixes = ["\'" + sha + "\'" for sha in subsequent_fixes]
+            parsed_fixes = ', '.join(subsequent_fixes)
+            # format query here since we are inserting n values
+            q = """SELECT sha, description
+                   FROM linux_upstream
+                   WHERE sha in ({})
+                   ORDER BY FIELD(sha, {})""".format(parsed_fixes, parsed_fixes)
+            c.execute(q)
+            fixes = c.fetchall()
+            print('    Fixed by:')
+            for fix in fixes:
+                print('      %s ("%s")' % fix)
+
 
 @util.cloud_sql_proxy_decorator
 @util.preliminary_check_decorator(False)