[coreboot-gerrit] Patch set updated for coreboot: util/gitconfig: add cborg2cros.py script

Martin Roth (martinroth@google.com) gerrit at coreboot.org
Thu Aug 4 06:52:08 CEST 2016


Martin Roth (martinroth at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15323

-gerrit

commit 1a7229591317cad7a20753381dfffbaf965bcdfa
Author: Martin Roth <martinroth at google.com>
Date:   Wed Aug 3 22:50:46 2016 -0600

    util/gitconfig: add cborg2cros.py script
    
    This is a python script that does basically the same thing as the
    rebase.sh script, but in the other direction.  rebase.sh takes files
    from the chromium tree (cros) and pulls them to the coreboot.org tree.
    cborg2cros, as the name implies, updates patches to go into the cros
    tree from coreboot.
    
    It adds the 'UPSTREAM: ' identifier to the start of the commit message,
    and uses the text '(cherry-picked from commit #####)' instead of
    'Original-Commit-Id: #####'
    
    It also adds the 'TEST=', 'BRANCH=', and 'BUG=' lines if they aren't
    there.
    
    Change-Id: Ibad9a5f0d0d2c713cf08e103c463e2e82768c436
    Signed-off-by: Martin Roth <martinroth at google.com>
---
 util/gitconfig/cborg2cros.py | 113 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/util/gitconfig/cborg2cros.py b/util/gitconfig/cborg2cros.py
new file mode 100755
index 0000000..8b3e392
--- /dev/null
+++ b/util/gitconfig/cborg2cros.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+
+# This file is part of the coreboot project.
+#
+# Copyright (C) 2016 Google, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+import sys
+
+branch = ""
+if len(sys.argv) > 1:
+    branch = sys.argv[1]
+else:
+    branch = "cborg/master"
+
+import subprocess
+commit_message = subprocess.check_output(["git", "log", "-n1"]).split("\n")
+
+new_commit_message = ""
+change_id = ""
+commit_id = ""
+bug_line_found = 0
+branch_line_found = 0
+test_line_found = 0
+
+import re
+pat_change_id = re.compile('^Change-Id: (.*)$')
+pat_orig_lines = re.compile('^(Signed-off-by|Reviewed-on|Reviewed-by)')
+pat_uninteresting = re.compile('^Tested-by')
+pat_quotes = re.compile('"')
+pat_leading_space = re.compile('^ ')
+pat_bug_line = re.compile('^bug\s*=', re.IGNORECASE)
+pat_branch_line = re.compile('branch\s*=', re.IGNORECASE)
+pat_test_line = re.compile('test\s*=', re.IGNORECASE)
+
+for line in commit_message:
+
+    # Skip the initial few lines of the commit message
+    m = pat_leading_space.match(line)
+    if not m:
+        continue
+
+    # Remove initial whitespace
+    line = line.lstrip(' ')
+
+    # Add the 'UPSTREAM' comment to the subject line
+    if len(new_commit_message) == 0:
+        new_commit_message += "UPSTREAM: " + line + "\n"
+        continue
+
+    # Grab the Change ID
+    chid = pat_change_id.match(line)
+    if chid:
+        change_id = chid.group(1)
+
+    # Add 'Original-' to all of the coreboot.org gerrit messages
+    grrt = pat_orig_lines.match(line)
+    if grrt:
+        line = "Original-" + line
+
+    if chid or grrt:
+        if not test_line_found:
+            new_commit_message += "TEST=Build tested at coreboot.org\n"
+            test_line_found = 1
+        if not bug_line_found:
+            new_commit_message += "BUG=None\n\n"
+            bug_line_found = 1
+        if not branch_line_found:
+            new_commit_message += "BRANCH=None\n\n"
+            branch_line_found = 1
+
+    # Remove uninteresting gerrit messages
+    if pat_uninteresting.match(line):
+        continue
+
+    if pat_test_line.match(line):
+        test_line_found = 1
+    if pat_bug_line.match(line):
+        bug_line_found = 1
+    if pat_branch_line.match(line):
+        branch_line_found = 1
+
+    new_commit_message += line + "\n"
+
+if not change_id:
+    print "Error: No change ID found"
+    sys.exit(1)
+
+try:
+    commit_id = subprocess.check_output(["git", "log", "-n1", "--grep", change_id, '--pretty=%H', branch, "--"]).rstrip('\n')
+except:
+    print "Error: invalid branch - " + branch + ".\n"
+    sys.exit(1)
+
+if not commit_id:
+    print "Error: Could not find ChangeID: " + change_id + " in branch " + branch + ".\n"
+    sys.exit(1)
+
+
+new_commit_message += "(cherry-picked from commit " + commit_id + ")\n"
+
+amend_output = subprocess.check_output(["git", "commit", "-s", "--amend", "-m", new_commit_message ])
+
+print "----------\n"
+print amend_output



More information about the coreboot-gerrit mailing list