findmissing: initdb_upstream: Record merges as handled

While we don't want to do anything with merges, we should still record
them as handled to avoid unnecessary non-linearities and thus duplicates
when traversing the list of commits again later on.

While at it, add space between error number and error text after
database errors to improve readability.

BUG=None
TEST=Run on GCE

Change-Id: I2a431e96c9a457a022f764d858da16eb3d554f1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2207397
Reviewed-by: Curtis Malainey <cujomalainey@chromium.org>
Commit-Queue: Guenter Roeck <groeck@chromium.org>
Tested-by: Guenter Roeck <groeck@chromium.org>
diff --git a/contrib/findmissing/initdb_upstream.py b/contrib/findmissing/initdb_upstream.py
index d86c5a7..47b15a6 100755
--- a/contrib/findmissing/initdb_upstream.py
+++ b/contrib/findmissing/initdb_upstream.py
@@ -45,8 +45,7 @@
     subprocess.check_output(['git', 'pull'])
 
     logging.info('Loading all linux-upstream commit logs from %s', start)
-    cmd = ['git', 'log', '--abbrev=12', '--oneline',
-            '--no-merges', '--reverse', start + '..HEAD']
+    cmd = ['git', 'log', '--abbrev=12', '--oneline', '--reverse', start + '..HEAD']
     commits = subprocess.check_output(cmd, encoding='utf-8', errors='ignore')
 
     fixes = []
@@ -59,6 +58,12 @@
             sha = elem[0]
             last = sha
 
+            # Nothing else to do if the commit is a merge
+            l = subprocess.check_output(['git', 'rev-list', '--parents', '-n', '1', sha],
+                                        encoding='utf-8', errors='ignore')
+            if len(l.split(' ')) > 2:
+                continue
+
             description = elem[1].rstrip('\n')
 
             # Calculate patch ID
@@ -78,7 +83,7 @@
                 # due to git idiosyncrasies (non-linearity).
                 if e.args[0] != MySQLdb.constants.ER.DUP_ENTRY:
                     logging.error(
-                        'Issue inserting sha "%s", description "%s", patch_id "%s": error %d(%s)',
+                        'Issue inserting sha "%s", description "%s", patch_id "%s": error %d (%s)',
                         sha, description, patch_id, e.args[0], e.args[1])
                 continue
             except UnicodeEncodeError as e:
@@ -133,7 +138,7 @@
             cursor.execute(q, [fix.upstream_sha, fix.fixedby_upstream_sha])
         except MySQLdb.IntegrityError as e: # pylint: disable=no-member
             # TODO(hirthanan): Email mailing list that one of usha or fix_usha is missing
-            logging.error('CANNOT FIND commit %s fixed by %s: error %d(%s)',
+            logging.error('CANNOT FIND commit %s fixed by %s: error %d (%s)',
                     fix.upstream_sha, fix.fixedby_upstream_sha, e.args[0], e.args[1])
 
     # Update previous fetch database