Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2017 the V8 project authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import argparse | |
| 7 import os | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 TARGET_SUBDIR = os.path.join("deps", "v8") | |
| 12 | |
| 13 def CherryPick(options): | |
| 14 print ">> Apply patch." | |
| 15 print subprocess.check_call(["git", "diff-tree", "-p", options.commit], cwd=op tions.v8_path) | |
|
Michael Achenbach
2017/04/25 12:33:45
Why do we output the whole patch? Isn't this somet
Yang
2017/04/25 18:22:05
Debugging remnant. Removing.
| |
| 16 patch = subprocess.Popen(["git", "diff-tree", "-p", options.commit], | |
| 17 stdout=subprocess.PIPE, cwd=options.v8_path) | |
| 18 patch.wait() | |
|
Michael Achenbach
2017/04/25 12:33:45
Probably many roads to Rome. I used to use a diffe
Yang
2017/04/25 18:22:05
Mine was a piece of stackoverflow wisdom as well :
| |
| 19 try: | |
| 20 subprocess.check_output(["git", "apply", "-3", "--directory=%s" % TARGET_SUB DIR], | |
| 21 stdin=patch.stdout, cwd=options.node_path) | |
| 22 except: | |
| 23 print ">> In another shell, please resolve patch conflicts" | |
| 24 print ">> and `git add` affected files." | |
| 25 print ">> Finally continue by entering RESOLVED." | |
| 26 while raw_input("[RESOLVED]") != "RESOLVED": | |
| 27 print ">> You need to type RESOLVED" | |
| 28 | |
| 29 def CreateCommit(options): | |
| 30 print ">> Creating commit." | |
| 31 # Find short hash from source. | |
| 32 shorthash = subprocess.check_output( | |
| 33 ["git", "rev-parse", "--short", options.commit], | |
| 34 cwd=options.v8_path).strip() | |
| 35 | |
| 36 # Commit message | |
| 37 title = "deps: backport %s from upstream V8" % shorthash | |
| 38 body = subprocess.check_output( | |
| 39 ["git", "log", options.commit, "-1", "--format=%B"], | |
| 40 cwd=options.v8_path).strip() | |
| 41 body = '\n'.join(" " + line for line in body.splitlines()) | |
| 42 | |
| 43 message = title + "\n\nOriginal commit message:\n\n" + body | |
| 44 | |
| 45 # Create commit at target. | |
| 46 review_message = "" if options.no_review else "-e" | |
| 47 git_commands = [ | |
| 48 ["git", "checkout", "-b", "backport_%s" % shorthash], # new branch | |
| 49 ["git", "add", TARGET_SUBDIR], # add files | |
| 50 ["git", "commit", "-m", message, review_message] # new commit | |
| 51 ] | |
| 52 for command in git_commands: | |
| 53 subprocess.check_call(command, cwd=options.node_path) | |
| 54 | |
| 55 def ParseOptions(args): | |
| 56 parser = argparse.ArgumentParser(description="Backport V8 commit to Node.js") | |
|
Franzi
2017/04/25 12:39:50
Can you add some docu? I.e., what is this for, how
Yang
2017/04/25 18:22:05
Done. Also added documentation for update_node.py
| |
| 57 parser.add_argument("v8_path", help="Path to V8 checkout") | |
| 58 parser.add_argument("node_path", help="Path to Node.js checkout") | |
| 59 parser.add_argument("commit", help="Commit to backport") | |
| 60 parser.add_argument("--no-review", action="store_true", | |
| 61 help="Skip editing commit message") | |
| 62 options = parser.parse_args(args) | |
| 63 options.v8_path = os.path.abspath(options.v8_path) | |
| 64 assert os.path.isdir(options.v8_path) | |
| 65 options.node_path = os.path.abspath(options.node_path) | |
| 66 assert os.path.isdir(options.node_path) | |
| 67 return options | |
| 68 | |
| 69 def Main(args): | |
| 70 options = ParseOptions(args) | |
| 71 try: | |
| 72 CherryPick(options) | |
| 73 CreateCommit(options) | |
| 74 except: | |
| 75 print ">> Failed. Resetting." | |
| 76 subprocess.check_output(["git", "reset", "--hard"], cwd=options.node_path) | |
| 77 raise | |
| 78 | |
| 79 if __name__ == "__main__": | |
| 80 Main(sys.argv[1:]) | |
| OLD | NEW |