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

Side by Side Diff: cros_mark_as_stable.py

Issue 6339018: Revert "Have the ability for the PFQ to both rev Chrome and ..." (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Put the right revert patch Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « bin/cros_mark_chrome_as_stable.py ('k') | cros_mark_as_stable_unittest.py » ('j') | 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/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """This module uprevs a given package's ebuild to the next revision.""" 7 """This module uprevs a given package's ebuild to the next revision."""
8 8
9 9
10 import fileinput 10 import fileinput
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 # Add stable ebuilds to overlays[overlay]. 159 # Add stable ebuilds to overlays[overlay].
160 paths = [os.path.join(package_dir, path) for path in files] 160 paths = [os.path.join(package_dir, path) for path in files]
161 ebuild = _FindUprevCandidates(paths) 161 ebuild = _FindUprevCandidates(paths)
162 162
163 # If the --all option isn't used, we only want to update packages that 163 # If the --all option isn't used, we only want to update packages that
164 # are in packages. 164 # are in packages.
165 if ebuild and (all or ebuild.package in packages): 165 if ebuild and (all or ebuild.package in packages):
166 overlays[overlay].append(ebuild) 166 overlays[overlay].append(ebuild)
167 167
168 168
169 def _DoWeHaveLocalCommits(stable_branch, tracking_branch): 169 def _CheckOnStabilizingBranch(stable_branch):
170 """Returns true if there are local commits.""" 170 """Returns true if the git branch is on the stabilizing branch."""
171 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1] 171 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1]
172 if current_branch == stable_branch: 172 return current_branch == stable_branch
173 current_commit_id = _SimpleRunCommand('git rev-parse HEAD')
174 tracking_commit_id = _SimpleRunCommand('git rev-parse %s' % tracking_branch)
175 return current_commit_id != tracking_commit_id
176 else:
177 return False
178 173
179 174
180 def _CheckSaneArguments(package_list, command): 175 def _CheckSaneArguments(package_list, command):
181 """Checks to make sure the flags are sane. Dies if arguments are not sane.""" 176 """Checks to make sure the flags are sane. Dies if arguments are not sane."""
182 if not command in COMMAND_DICTIONARY.keys(): 177 if not command in COMMAND_DICTIONARY.keys():
183 _PrintUsageAndDie('%s is not a valid command' % command) 178 _PrintUsageAndDie('%s is not a valid command' % command)
184 if not gflags.FLAGS.packages and command == 'commit' and not gflags.FLAGS.all: 179 if not gflags.FLAGS.packages and command == 'commit' and not gflags.FLAGS.all:
185 _PrintUsageAndDie('Please specify at least one package') 180 _PrintUsageAndDie('Please specify at least one package')
186 if not gflags.FLAGS.board and command == 'commit': 181 if not gflags.FLAGS.board and command == 'commit':
187 _PrintUsageAndDie('Please specify a board') 182 _PrintUsageAndDie('Please specify a board')
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 # ======================= End Global Helper Functions ======================== 216 # ======================= End Global Helper Functions ========================
222 217
223 218
224 def Clean(tracking_branch): 219 def Clean(tracking_branch):
225 """Cleans up uncommitted changes. 220 """Cleans up uncommitted changes.
226 221
227 Args: 222 Args:
228 tracking_branch: The tracking branch we want to return to after the call. 223 tracking_branch: The tracking branch we want to return to after the call.
229 """ 224 """
230 _SimpleRunCommand('git reset HEAD --hard') 225 _SimpleRunCommand('git reset HEAD --hard')
231 branch = GitBranch(STABLE_BRANCH_NAME, tracking_branch) 226 _SimpleRunCommand('git checkout %s' % tracking_branch)
232 if branch.Exists():
233 GitBranch.Checkout(branch)
234 branch.Delete()
235 227
236 228
237 def PushChange(stable_branch, tracking_branch): 229 def PushChange(stable_branch, tracking_branch):
238 """Pushes commits in the stable_branch to the remote git repository. 230 """Pushes commits in the stable_branch to the remote git repository.
239 231
240 Pushes locals commits from calls to CommitChange to the remote git 232 Pushes locals commits from calls to CommitChange to the remote git
241 repository specified by current working directory. 233 repository specified by current working directory.
242 234
243 Args: 235 Args:
244 stable_branch: The local branch with commits we want to push. 236 stable_branch: The local branch with commits we want to push.
245 tracking_branch: The tracking branch of the local branch. 237 tracking_branch: The tracking branch of the local branch.
246 Raises: 238 Raises:
247 OSError: Error occurred while pushing. 239 OSError: Error occurred while pushing.
248 """ 240 """
249 num_retries = 5 241 num_retries = 5
250 242
251 # Sanity check to make sure we're on a stabilizing branch before pushing. 243 # Sanity check to make sure we're on a stabilizing branch before pushing.
252 if not _DoWeHaveLocalCommits(stable_branch, tracking_branch): 244 if not _CheckOnStabilizingBranch(stable_branch):
253 Info('Not work found to push. Exiting') 245 Info('Not on branch %s so no work found to push. Exiting' % stable_branch)
254 return 246 return
255 247
256 description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' + 248 description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' +
257 tracking_branch + '..') 249 tracking_branch + '..')
258 description = 'Marking set of ebuilds as stable\n\n%s' % description 250 description = 'Marking set of ebuilds as stable\n\n%s' % description
259 Info('Using description %s' % description) 251 Info('Using description %s' % description)
260 merge_branch_name = 'merge_branch' 252 merge_branch_name = 'merge_branch'
261 for push_try in range(num_retries + 1): 253 for push_try in range(num_retries + 1):
262 try: 254 try:
263 _SimpleRunCommand('repo sync .') 255 _SimpleRunCommand('repo sync .')
(...skipping 11 matching lines...) Expand all
275 267
276 break 268 break
277 except: 269 except:
278 if push_try < num_retries: 270 if push_try < num_retries:
279 Warning('Failed to push change, performing retry (%s/%s)' % ( 271 Warning('Failed to push change, performing retry (%s/%s)' % (
280 push_try + 1, num_retries)) 272 push_try + 1, num_retries))
281 else: 273 else:
282 raise 274 raise
283 275
284 276
285
286 class GitBranch(object): 277 class GitBranch(object):
287 """Wrapper class for a git branch.""" 278 """Wrapper class for a git branch."""
288 279
289 def __init__(self, branch_name, tracking_branch): 280 def __init__(self, branch_name, tracking_branch):
290 """Sets up variables but does not create the branch.""" 281 """Sets up variables but does not create the branch."""
291 self.branch_name = branch_name 282 self.branch_name = branch_name
292 self.tracking_branch = tracking_branch 283 self.tracking_branch = tracking_branch
293 284
294 def CreateBranch(self): 285 def CreateBranch(self):
295 GitBranch.Checkout(self) 286 """Creates a new git branch or replaces an existing one."""
287 if self.Exists():
288 self.Delete()
289 self._Checkout(self.branch_name)
296 290
297 @classmethod 291 def _Checkout(self, target, create=True):
298 def Checkout(cls, target): 292 """Function used internally to create and move between branches."""
299 """Function used to check out to another GitBranch.""" 293 if create:
300 if target.branch_name == target.tracking_branch or target.Exists(): 294 git_cmd = 'git checkout -b %s %s' % (target, self.tracking_branch)
301 git_cmd = 'git checkout %s' % target.branch_name
302 else: 295 else:
303 git_cmd = 'git checkout -b %s %s' % (target.branch_name, 296 git_cmd = 'git checkout %s' % target
304 target.tracking_branch)
305 _SimpleRunCommand(git_cmd) 297 _SimpleRunCommand(git_cmd)
306 298
307 def Exists(self): 299 def Exists(self):
308 """Returns True if the branch exists.""" 300 """Returns True if the branch exists."""
309 branch_cmd = 'git branch' 301 branch_cmd = 'git branch'
310 branches = _SimpleRunCommand(branch_cmd) 302 branches = _SimpleRunCommand(branch_cmd)
311 return self.branch_name in branches.split() 303 return self.branch_name in branches.split()
312 304
313 def Delete(self): 305 def Delete(self):
314 """Deletes the branch and returns the user to the master branch. 306 """Deletes the branch and returns the user to the master branch.
315 307
316 Returns True on success. 308 Returns True on success.
317 """ 309 """
318 tracking_branch = GitBranch(self.tracking_branch, self.tracking_branch) 310 self._Checkout(self.tracking_branch, create=False)
319 GitBranch.Checkout(tracking_branch)
320 delete_cmd = 'git branch -D %s' % self.branch_name 311 delete_cmd = 'git branch -D %s' % self.branch_name
321 _SimpleRunCommand(delete_cmd) 312 _SimpleRunCommand(delete_cmd)
322 313
323 314
324 class EBuild(object): 315 class EBuild(object):
325 """Wrapper class for information about an ebuild.""" 316 """Wrapper class for information about an ebuild."""
326 317
327 def __init__(self, path): 318 def __init__(self, path):
328 """Sets up data about an ebuild from its path.""" 319 """Sets up data about an ebuild from its path."""
329 from portage.versions import pkgsplit 320 from portage.versions import pkgsplit
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) 563 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id)
573 worker.CommitChange(message) 564 worker.CommitChange(message)
574 revved_packages.append(ebuild.package) 565 revved_packages.append(ebuild.package)
575 new_package_atoms.append('=%s' % new_package) 566 new_package_atoms.append('=%s' % new_package)
576 except (OSError, IOError): 567 except (OSError, IOError):
577 Warning('Cannot rev %s\n' % ebuild.package, 568 Warning('Cannot rev %s\n' % ebuild.package,
578 'Note you will have to go into %s ' 569 'Note you will have to go into %s '
579 'and reset the git repo yourself.' % overlay) 570 'and reset the git repo yourself.' % overlay)
580 raise 571 raise
581 572
582 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms) 573 if revved_packages:
583 if gflags.FLAGS.drop_file: 574 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms)
584 fh = open(gflags.FLAGS.drop_file, 'w') 575 if gflags.FLAGS.drop_file:
585 fh.write(' '.join(revved_packages)) 576 fh = open(gflags.FLAGS.drop_file, 'w')
586 fh.close() 577 fh.write(' '.join(revved_packages))
578 fh.close()
579 else:
580 work_branch.Delete()
587 581
588 582
589 if __name__ == '__main__': 583 if __name__ == '__main__':
590 main(sys.argv) 584 main(sys.argv)
OLDNEW
« no previous file with comments | « bin/cros_mark_chrome_as_stable.py ('k') | cros_mark_as_stable_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698