Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: tools/release/backport_node.py

Issue 2838843002: [tools] add script to simplify backporting patch to Node.js (Closed)
Patch Set: address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/release/test_backport_node.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 """
7 Use this script to cherry-pick a V8 commit to backport to a Node.js checkout.
8
9 Requirements:
10 - Node.js checkout to backport to.
11 - V8 checkout that contains the commit to cherry-pick.
12
13 Usage:
14 $ backport_node.py <path_to_v8> <path_to_node> <commit-hash>
15
16 This will apply the commit to <path_to_node>/deps/v8 and create a commit in
17 the Node.js checkout and copy over the original commit message.
18
19 Optional flags:
20 --no-review Run `gclient sync` on the V8 checkout before updating.
21 """
22
23 import argparse
24 import os
25 import subprocess
26 import sys
27
28 TARGET_SUBDIR = os.path.join("deps", "v8")
29
30 def CherryPick(options):
31 print ">> Apply patch."
32 patch = subprocess.Popen(["git", "diff-tree", "-p", options.commit],
33 stdout=subprocess.PIPE, cwd=options.v8_path)
34 patch.wait()
35 try:
36 subprocess.check_output(["git", "apply", "-3", "--directory=%s" % TARGET_SUB DIR],
37 stdin=patch.stdout, cwd=options.node_path)
38 except:
39 print ">> In another shell, please resolve patch conflicts"
40 print ">> and `git add` affected files."
41 print ">> Finally continue by entering RESOLVED."
42 while raw_input("[RESOLVED]") != "RESOLVED":
43 print ">> You need to type RESOLVED"
44
45 def CreateCommit(options):
46 print ">> Creating commit."
47 # Find short hash from source.
48 shorthash = subprocess.check_output(
49 ["git", "rev-parse", "--short", options.commit],
50 cwd=options.v8_path).strip()
51
52 # Commit message
53 title = "deps: backport %s from upstream V8" % shorthash
54 body = subprocess.check_output(
55 ["git", "log", options.commit, "-1", "--format=%B"],
56 cwd=options.v8_path).strip()
57 body = '\n'.join(" " + line for line in body.splitlines())
58
59 message = title + "\n\nOriginal commit message:\n\n" + body
60
61 # Create commit at target.
62 review_message = "" if options.no_review else "-e"
63 git_commands = [
64 ["git", "checkout", "-b", "backport_%s" % shorthash], # new branch
65 ["git", "add", TARGET_SUBDIR], # add files
66 ["git", "commit", "-m", message, review_message] # new commit
67 ]
68 for command in git_commands:
69 subprocess.check_call(command, cwd=options.node_path)
70
71 def ParseOptions(args):
72 parser = argparse.ArgumentParser(description="Backport V8 commit to Node.js")
73 parser.add_argument("v8_path", help="Path to V8 checkout")
74 parser.add_argument("node_path", help="Path to Node.js checkout")
75 parser.add_argument("commit", help="Commit to backport")
76 parser.add_argument("--no-review", action="store_true",
77 help="Skip editing commit message")
78 options = parser.parse_args(args)
79 options.v8_path = os.path.abspath(options.v8_path)
80 assert os.path.isdir(options.v8_path)
81 options.node_path = os.path.abspath(options.node_path)
82 assert os.path.isdir(options.node_path)
83 return options
84
85 def Main(args):
86 options = ParseOptions(args)
87 try:
88 CherryPick(options)
89 CreateCommit(options)
90 except:
91 print ">> Failed. Resetting."
92 subprocess.check_output(["git", "reset", "--hard"], cwd=options.node_path)
93 raise
94
95 if __name__ == "__main__":
96 Main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | tools/release/test_backport_node.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698