[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 07:13:49 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 ddc622fc59f5409001b3842c793d3cf3dd521b5d
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 | 122 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)

diff --git a/util/gitconfig/cborg2cros.py b/util/gitconfig/cborg2cros.py
new file mode 100755
index 0000000..eb5e325
--- /dev/null
+++ b/util/gitconfig/cborg2cros.py
@@ -0,0 +1,122 @@
+#!/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
+import re
+import subprocess
+
+branch = ""
+new_commit_message = ""
+change_id = ""
+commit_id = ""
+bug_line_found = 0
+branch_line_found = 0
+test_line_found = 0
+
+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)
+
+if len(sys.argv) > 1:
+    branch = sys.argv[1]
+else:
+    branch = "cborg/master"
+
+# Get the last commit message, then loop through looking at each line
+commit_message = subprocess.check_output(["git", "log", "-n1"]).split("\n")
+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 we've reached the end of the real commit message text and we don't
+    # have the required TEST= BUG= and BRANCH= lines, add them.
+    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 we've found a TEST, BRANCH, or BUG line, mark it as found
+    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
+
+    # Add the current line to the updated commit message
+    new_commit_message += line + "\n"
+
+# Error out if no change ID was located
+if not change_id:
+    print "Error: No change ID found"
+    sys.exit(1)
+
+# Get the Commit ID based on the Change ID and the branch.
+# Error out if git returns an error
+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)
+
+# Error out if the Commit ID wasn't found.
+if not commit_id:
+    print "Error: Could not find ChangeID: " + change_id + " in branch " + branch + ".\n"
+    sys.exit(1)
+
+# Add the commit ID that this change came from to the patch.
+new_commit_message += "(cherry-picked from commit " + commit_id + ")\n"
+
+# Update the commit message
+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