findmissing: Improve SHA matching using SQL queries

SHAs provided by the command line need to be matched against kernel_sha
and fixedby_upstream_sha in the two fixes tables. So far we used
get_fix_status_and_changeid_from_list() to first evaluate if a SHA is
an upstream SHA (fixedby_upstream_sha) or a ChromeOS/stable release SHA
(kernel_sha). In general it is either/or. This means we can use SQL
queries "kernel_sha IN (sha_list)" and "fixedby_upstream_sha in
(sha_list)" to find the SHAs in the database. Only question is if to use
ther AND or the OR operator when searching for entries with kernel_sha
and/or fixedby_upstream_sha. As it turns out, this is straightforward:

- For "abandon" and "restore" commands, we have one or two SHAs.
  - If the user provided one SHA, it can be a kernel_sha or a
    fixedby_upstream_sha, and we need to use the OR operator.
  - If the user provided two SHAs, expectation is that one is a kernel_sha
    and one is a fixedby_upstream_sha. Use the AND operator in this case.
- For the "status" command, we want to list SHAs found anywhere.
  Use the "OR" operator.

To implement this,
- Replace "kernel_sha" and "fixedby_upstream_sha" arguments to
  get_fix_status_and_changeid() with a list of SHAs.
- Replace query
  [kernel_sha = <kernel_sha>] [AND]
          [fixedby_upstream_sha = <fixedby_upstream_sha>]
  kernel_sha IN (sha_list) {AND,OR} fixedby_upstream_sha IN (sha_list)
- Pass "strict" argument to get_fix_status_and_changeid() to determine
  if the search needs to match both kernel_sha and fixedby_upstream_sha
  (AND) or if any match is sufficient (OR).

With this change, get_fix_status_and_changeid_from_list() and the query
of the linux_upstream table for each SHA is no longer needed. Also, we no
longer need to examine SHAs one by one in status_fix_cl() but can pass
the entire SHA list provided by the user to get_fix_status_and_changeid().

TEST=Run various findmissing commands

Change-Id: I959b80ec2e7eb7f428162aeab7c405ceecc6ce5f
Commit-Queue: Guenter Roeck <>
Tested-by: Guenter Roeck <>
Reviewed-by: Curtis Malainey <>
2 files changed