summaryrefslogtreecommitdiffstats
path: root/subcmds/cherry_pick.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/cherry_pick.py')
-rw-r--r--subcmds/cherry_pick.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py
index a541a040..7bd858bf 100644
--- a/subcmds/cherry_pick.py
+++ b/subcmds/cherry_pick.py
@@ -1,5 +1,3 @@
1# -*- coding:utf-8 -*-
2#
3# Copyright (C) 2010 The Android Open Source Project 1# Copyright (C) 2010 The Android Open Source Project
4# 2#
5# Licensed under the Apache License, Version 2.0 (the "License"); 3# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
14# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
15# limitations under the License. 13# limitations under the License.
16 14
17from __future__ import print_function
18import re 15import re
19import sys 16import sys
20from command import Command 17from command import Command
@@ -22,8 +19,9 @@ from git_command import GitCommand
22 19
23CHANGE_ID_RE = re.compile(r'^\s*Change-Id: I([0-9a-f]{40})\s*$') 20CHANGE_ID_RE = re.compile(r'^\s*Change-Id: I([0-9a-f]{40})\s*$')
24 21
22
25class CherryPick(Command): 23class CherryPick(Command):
26 common = True 24 COMMON = True
27 helpSummary = "Cherry-pick a change." 25 helpSummary = "Cherry-pick a change."
28 helpUsage = """ 26 helpUsage = """
29%prog <sha1> 27%prog <sha1>
@@ -34,9 +32,6 @@ The change id will be updated, and a reference to the old
34change id will be added. 32change id will be added.
35""" 33"""
36 34
37 def _Options(self, p):
38 pass
39
40 def ValidateOptions(self, opt, args): 35 def ValidateOptions(self, opt, args):
41 if len(args) != 1: 36 if len(args) != 1:
42 self.Usage() 37 self.Usage()
@@ -46,8 +41,8 @@ change id will be added.
46 41
47 p = GitCommand(None, 42 p = GitCommand(None,
48 ['rev-parse', '--verify', reference], 43 ['rev-parse', '--verify', reference],
49 capture_stdout = True, 44 capture_stdout=True,
50 capture_stderr = True) 45 capture_stderr=True)
51 if p.Wait() != 0: 46 if p.Wait() != 0:
52 print(p.stderr, file=sys.stderr) 47 print(p.stderr, file=sys.stderr)
53 sys.exit(1) 48 sys.exit(1)
@@ -61,8 +56,8 @@ change id will be added.
61 56
62 p = GitCommand(None, 57 p = GitCommand(None,
63 ['cherry-pick', sha1], 58 ['cherry-pick', sha1],
64 capture_stdout = True, 59 capture_stdout=True,
65 capture_stderr = True) 60 capture_stderr=True)
66 status = p.Wait() 61 status = p.Wait()
67 62
68 print(p.stdout, file=sys.stdout) 63 print(p.stdout, file=sys.stdout)
@@ -74,11 +69,9 @@ change id will be added.
74 new_msg = self._Reformat(old_msg, sha1) 69 new_msg = self._Reformat(old_msg, sha1)
75 70
76 p = GitCommand(None, ['commit', '--amend', '-F', '-'], 71 p = GitCommand(None, ['commit', '--amend', '-F', '-'],
77 provide_stdin = True, 72 input=new_msg,
78 capture_stdout = True, 73 capture_stdout=True,
79 capture_stderr = True) 74 capture_stderr=True)
80 p.stdin.write(new_msg)
81 p.stdin.close()
82 if p.Wait() != 0: 75 if p.Wait() != 0:
83 print("error: Failed to update commit message", file=sys.stderr) 76 print("error: Failed to update commit message", file=sys.stderr)
84 sys.exit(1) 77 sys.exit(1)
@@ -97,7 +90,7 @@ change id will be added.
97 90
98 def _StripHeader(self, commit_msg): 91 def _StripHeader(self, commit_msg):
99 lines = commit_msg.splitlines() 92 lines = commit_msg.splitlines()
100 return "\n".join(lines[lines.index("")+1:]) 93 return "\n".join(lines[lines.index("") + 1:])
101 94
102 def _Reformat(self, old_msg, sha1): 95 def _Reformat(self, old_msg, sha1):
103 new_msg = [] 96 new_msg = []