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

Side by Side Diff: tools/safely-roll-deps.py

Issue 271733007: Make safely-roll-deps work with git commit hashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generate a CL to roll a DEPS entry to the specified revision number and post 6 """Generate a CL to roll a DEPS entry to the specified revision number and post
7 it to Rietveld so that the CL will land automatically if it passes the 7 it to Rietveld so that the CL will land automatically if it passes the
8 commit-queue's checks. 8 commit-queue's checks.
9 """ 9 """
10 10
(...skipping 15 matching lines...) Expand all
26 26
27 def process_deps(path, project, new_rev, is_dry_run): 27 def process_deps(path, project, new_rev, is_dry_run):
28 """Update project_revision to |new_issue|. 28 """Update project_revision to |new_issue|.
29 29
30 A bit hacky, could it be made better? 30 A bit hacky, could it be made better?
31 """ 31 """
32 content = open(path).read() 32 content = open(path).read()
33 # Hack for Blink to get the AutoRollBot running again. 33 # Hack for Blink to get the AutoRollBot running again.
34 if project == "blink": 34 if project == "blink":
35 project = "webkit" 35 project = "webkit"
36 old_line = r'(\s+)"%s_revision": "(\d+)",' % project 36 old_line = r'(\s+)"%s_revision": "(.+)",' % project
M-A Ruel 2014/05/08 16:44:34 [0-9a-f]{2,40}
borenet 2014/05/08 17:10:58 Done.
37 new_line = r'\1"%s_revision": "%d",' % (project, new_rev) 37 new_line = r'\1"%s_revision": "%s",' % (project, new_rev)
38 new_content = re.sub(old_line, new_line, content, 1) 38 new_content = re.sub(old_line, new_line, content, 1)
39 old_rev = re.search(old_line, content).group(2) 39 old_rev = re.search(old_line, content).group(2)
40 if not old_rev or new_content == content: 40 if not old_rev or new_content == content:
41 die_with_error('Failed to update the DEPS file') 41 die_with_error('Failed to update the DEPS file')
42 42
43 if not is_dry_run: 43 if not is_dry_run:
44 open(path, 'w').write(new_content) 44 open(path, 'w').write(new_content)
45 return old_rev 45 return old_rev
46 46
47 47
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 [logging.WARNING, logging.INFO, logging.DEBUG][ 86 [logging.WARNING, logging.INFO, logging.DEBUG][
87 min(2, options.verbose)]) 87 min(2, options.verbose)])
88 if len(args) != 2: 88 if len(args) != 2:
89 parser.print_help() 89 parser.print_help()
90 exit(0) 90 exit(0)
91 91
92 root_dir = os.path.dirname(tool_dir) 92 root_dir = os.path.dirname(tool_dir)
93 os.chdir(root_dir) 93 os.chdir(root_dir)
94 94
95 project = args[0] 95 project = args[0]
96 new_rev = int(args[1]) 96 new_rev = args[1]
97 97
98 # Silence the editor. 98 # Silence the editor.
99 os.environ['EDITOR'] = 'true' 99 os.environ['EDITOR'] = 'true'
100 100
101 if options.force and not options.dry_run: 101 if options.force and not options.dry_run:
102 prnt_subprocess.check_call(['git', 'clean', '-d', '-f']) 102 prnt_subprocess.check_call(['git', 'clean', '-d', '-f'])
103 prnt_subprocess.call(['git', 'rebase', '--abort']) 103 prnt_subprocess.call(['git', 'rebase', '--abort'])
104 104
105 old_branch = scm.GIT.GetBranch(root_dir) 105 old_branch = scm.GIT.GetBranch(root_dir)
106 new_branch = '%s_roll' % project 106 new_branch = '%s_roll' % project
(...skipping 12 matching lines...) Expand all
119 119
120 if not options.dry_run: 120 if not options.dry_run:
121 prnt_subprocess.check_call(['git', 'fetch', 'origin']) 121 prnt_subprocess.check_call(['git', 'fetch', 'origin'])
122 prnt_subprocess.call(['git', 'svn', 'fetch']) 122 prnt_subprocess.call(['git', 'svn', 'fetch'])
123 branch_cmd = ['git', 'checkout', '-b', new_branch, options.upstream] 123 branch_cmd = ['git', 'checkout', '-b', new_branch, options.upstream]
124 if options.force: 124 if options.force:
125 branch_cmd.append('-f') 125 branch_cmd.append('-f')
126 prnt_subprocess.check_output(branch_cmd) 126 prnt_subprocess.check_output(branch_cmd)
127 127
128 try: 128 try:
129 old_rev = int(process_deps(os.path.join(root_dir, 'DEPS'), project, new_rev, 129 old_rev = process_deps(os.path.join(root_dir, 'DEPS'), project, new_rev,
130 options.dry_run)) 130 options.dry_run)
131 print '%s roll %s:%s' % (project.title(), old_rev, new_rev) 131 print '%s roll %s:%s' % (project.title(), old_rev, new_rev)
132 132
133 review_field = 'TBR' if options.commit else 'R' 133 review_field = 'TBR' if options.commit else 'R'
134 commit_msg = options.message or '%s roll %s:%s\n' % (project.title(), 134 commit_msg = options.message or '%s roll %s:%s\n' % (project.title(),
135 old_rev, new_rev) 135 old_rev, new_rev)
136 commit_msg += '\n%s=%s\n' % (review_field, options.reviewers) 136 commit_msg += '\n%s=%s\n' % (review_field, options.reviewers)
137 137
138 if options.dry_run: 138 if options.dry_run:
139 print 'Commit message: ' + commit_msg 139 print 'Commit message: ' + commit_msg
140 return 0 140 return 0
(...skipping 11 matching lines...) Expand all
152 prnt_subprocess.check_call(upload_cmd) 152 prnt_subprocess.check_call(upload_cmd)
153 finally: 153 finally:
154 if not options.dry_run: 154 if not options.dry_run:
155 prnt_subprocess.check_output(['git', 'checkout', old_branch]) 155 prnt_subprocess.check_output(['git', 'checkout', old_branch])
156 prnt_subprocess.check_output(['git', 'branch', '-D', new_branch]) 156 prnt_subprocess.check_output(['git', 'branch', '-D', new_branch])
157 return 0 157 return 0
158 158
159 159
160 if __name__ == '__main__': 160 if __name__ == '__main__':
161 sys.exit(main()) 161 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698