Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 the V8 project authors. All rights reserved. | 2 # Copyright 2013 the V8 project authors. All rights reserved. |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following | 10 # copyright notice, this list of conditions and the following |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 def ReadLine(self, default=None): | 313 def ReadLine(self, default=None): |
| 314 # Don't prompt in forced mode. | 314 # Don't prompt in forced mode. |
| 315 if self._options.force_readline_defaults and default is not None: | 315 if self._options.force_readline_defaults and default is not None: |
| 316 print "%s (forced)" % default | 316 print "%s (forced)" % default |
| 317 return default | 317 return default |
| 318 else: | 318 else: |
| 319 return self._side_effect_handler.ReadLine() | 319 return self._side_effect_handler.ReadLine() |
| 320 | 320 |
| 321 def Git(self, args="", prefix="", pipe=True, retry_on=None): | 321 def Git(self, args="", prefix="", pipe=True, retry_on=None): |
| 322 cmd = lambda: self._side_effect_handler.Command("git", args, prefix, pipe) | 322 cmd = lambda: self._side_effect_handler.Command("git", args, prefix, pipe) |
| 323 return self.Retry(cmd, retry_on, [5, 30]) | 323 result = self.Retry(cmd, retry_on, [5, 30]) |
| 324 if result is None: | |
| 325 self.Die("'git %s' failed." % args) | |
| 326 return result | |
| 324 | 327 |
| 325 def SVN(self, args="", prefix="", pipe=True, retry_on=None): | 328 def SVN(self, args="", prefix="", pipe=True, retry_on=None): |
| 326 cmd = lambda: self._side_effect_handler.Command("svn", args, prefix, pipe) | 329 cmd = lambda: self._side_effect_handler.Command("svn", args, prefix, pipe) |
| 327 return self.Retry(cmd, retry_on, [5, 30]) | 330 return self.Retry(cmd, retry_on, [5, 30]) |
| 328 | 331 |
| 329 def Editor(self, args): | 332 def Editor(self, args): |
| 330 if self._options.requires_editor: | 333 if self._options.requires_editor: |
| 331 return self._side_effect_handler.Command(os.environ["EDITOR"], args, | 334 return self._side_effect_handler.Command(os.environ["EDITOR"], args, |
| 332 pipe=False) | 335 pipe=False) |
| 333 | 336 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 354 print "%s [Y/n] " % msg, | 357 print "%s [Y/n] " % msg, |
| 355 answer = self.ReadLine(default="Y") | 358 answer = self.ReadLine(default="Y") |
| 356 return answer == "" or answer == "Y" or answer == "y" | 359 return answer == "" or answer == "Y" or answer == "y" |
| 357 | 360 |
| 358 def DeleteBranch(self, name): | 361 def DeleteBranch(self, name): |
| 359 git_result = self.Git("branch").strip() | 362 git_result = self.Git("branch").strip() |
| 360 for line in git_result.splitlines(): | 363 for line in git_result.splitlines(): |
| 361 if re.match(r".*\s+%s$" % name, line): | 364 if re.match(r".*\s+%s$" % name, line): |
| 362 msg = "Branch %s exists, do you want to delete it?" % name | 365 msg = "Branch %s exists, do you want to delete it?" % name |
| 363 if self.Confirm(msg): | 366 if self.Confirm(msg): |
| 364 if self.Git("branch -D %s" % name) is None: | 367 self.Git("branch -D %s" % name) |
| 365 self.Die("Deleting branch '%s' failed." % name) | |
| 366 print "Branch %s deleted." % name | 368 print "Branch %s deleted." % name |
| 367 else: | 369 else: |
| 368 msg = "Can't continue. Please delete branch %s and try again." % name | 370 msg = "Can't continue. Please delete branch %s and try again." % name |
| 369 self.Die(msg) | 371 self.Die(msg) |
| 370 | 372 |
| 371 def InitialEnvironmentChecks(self): | 373 def InitialEnvironmentChecks(self): |
| 372 # Cancel if this is not a git checkout. | 374 # Cancel if this is not a git checkout. |
| 373 if not os.path.exists(self._config[DOT_GIT_LOCATION]): | 375 if not os.path.exists(self._config[DOT_GIT_LOCATION]): |
| 374 self.Die("This is not a git checkout, this script won't work for you.") | 376 self.Die("This is not a git checkout, this script won't work for you.") |
| 375 | 377 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 386 # Persist current branch. | 388 # Persist current branch. |
| 387 self["current_branch"] = "" | 389 self["current_branch"] = "" |
| 388 git_result = self.Git("status -s -b -uno").strip() | 390 git_result = self.Git("status -s -b -uno").strip() |
| 389 for line in git_result.splitlines(): | 391 for line in git_result.splitlines(): |
| 390 match = re.match(r"^## (.+)", line) | 392 match = re.match(r"^## (.+)", line) |
| 391 if match: | 393 if match: |
| 392 self["current_branch"] = match.group(1) | 394 self["current_branch"] = match.group(1) |
| 393 break | 395 break |
| 394 | 396 |
| 395 # Fetch unfetched revisions. | 397 # Fetch unfetched revisions. |
| 396 if self.Git("svn fetch") is None: | 398 self.Git("svn fetch") |
| 397 self.Die("'git svn fetch' failed.") | |
| 398 | 399 |
| 399 def PrepareBranch(self): | 400 def PrepareBranch(self): |
| 400 # Get ahold of a safe temporary branch and check it out. | 401 # Get ahold of a safe temporary branch and check it out. |
| 401 if self["current_branch"] != self._config[TEMP_BRANCH]: | 402 if self["current_branch"] != self._config[TEMP_BRANCH]: |
| 402 self.DeleteBranch(self._config[TEMP_BRANCH]) | 403 self.DeleteBranch(self._config[TEMP_BRANCH]) |
| 403 self.Git("checkout -b %s" % self._config[TEMP_BRANCH]) | 404 self.Git("checkout -b %s" % self._config[TEMP_BRANCH]) |
| 404 | 405 |
| 405 # Delete the branch that will be created later if it exists already. | 406 # Delete the branch that will be created later if it exists already. |
| 406 self.DeleteBranch(self._config[BRANCHNAME]) | 407 self.DeleteBranch(self._config[BRANCHNAME]) |
| 407 | 408 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 if answer == "ABORT": | 451 if answer == "ABORT": |
| 451 self.Die("Applying the patch failed.") | 452 self.Die("Applying the patch failed.") |
| 452 if answer != "": | 453 if answer != "": |
| 453 print "That was not 'RESOLVED' or 'ABORT'." | 454 print "That was not 'RESOLVED' or 'ABORT'." |
| 454 print "> ", | 455 print "> ", |
| 455 answer = self.ReadLine() | 456 answer = self.ReadLine() |
| 456 | 457 |
| 457 # Takes a file containing the patch to apply as first argument. | 458 # Takes a file containing the patch to apply as first argument. |
| 458 def ApplyPatch(self, patch_file, reverse_patch=""): | 459 def ApplyPatch(self, patch_file, reverse_patch=""): |
| 459 args = "apply --index --reject %s \"%s\"" % (reverse_patch, patch_file) | 460 args = "apply --index --reject %s \"%s\"" % (reverse_patch, patch_file) |
| 460 if self.Git(args) is None: | 461 try: |
| 462 self.Git(args) | |
| 463 except: | |
|
ulan
2014/02/19 14:43:37
This will catch all exceptions. Is that intended?
Michael Achenbach
2014/02/19 14:56:06
Done.
| |
| 461 self.WaitForResolvingConflicts(patch_file) | 464 self.WaitForResolvingConflicts(patch_file) |
| 462 | 465 |
| 463 def FindLastTrunkPush(self): | 466 def FindLastTrunkPush(self): |
| 464 push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]* (based" | 467 push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]* (based" |
| 465 args = "log -1 --format=%%H --grep=\"%s\" svn/trunk" % push_pattern | 468 args = "log -1 --format=%%H --grep=\"%s\" svn/trunk" % push_pattern |
| 466 return self.Git(args).strip() | 469 return self.Git(args).strip() |
| 467 | 470 |
| 468 | 471 |
| 469 class UploadStep(Step): | 472 class UploadStep(Step): |
| 470 MESSAGE = "Upload for code review." | 473 MESSAGE = "Upload for code review." |
| 471 | 474 |
| 472 def RunStep(self): | 475 def RunStep(self): |
| 473 if self._options.reviewer: | 476 if self._options.reviewer: |
| 474 print "Using account %s for review." % self._options.reviewer | 477 print "Using account %s for review." % self._options.reviewer |
| 475 reviewer = self._options.reviewer | 478 reviewer = self._options.reviewer |
| 476 else: | 479 else: |
| 477 print "Please enter the email address of a V8 reviewer for your patch: ", | 480 print "Please enter the email address of a V8 reviewer for your patch: ", |
| 478 self.DieNoManualMode("A reviewer must be specified in forced mode.") | 481 self.DieNoManualMode("A reviewer must be specified in forced mode.") |
| 479 reviewer = self.ReadLine() | 482 reviewer = self.ReadLine() |
| 480 author_option = self._options.author | 483 author_option = self._options.author |
| 481 author = " --email \"%s\"" % author_option if author_option else "" | 484 author = " --email \"%s\"" % author_option if author_option else "" |
| 482 force_flag = " -f" if self._options.force_upload else "" | 485 force_flag = " -f" if self._options.force_upload else "" |
| 483 args = ("cl upload%s -r \"%s\" --send-mail%s" | 486 args = ("cl upload%s -r \"%s\" --send-mail%s" |
| 484 % (author, reviewer, force_flag)) | 487 % (author, reviewer, force_flag)) |
| 485 # TODO(machenbach): Check output in forced mode. Verify that all required | 488 # TODO(machenbach): Check output in forced mode. Verify that all required |
| 486 # base files were uploaded, if not retry. | 489 # base files were uploaded, if not retry. |
| 487 if self.Git(args, pipe=False) is None: | 490 self.Git(args, pipe=False) |
| 488 self.Die("'git cl upload' failed, please try again.") | |
| 489 | 491 |
| 490 | 492 |
| 491 def MakeStep(step_class=Step, number=0, state=None, config=None, | 493 def MakeStep(step_class=Step, number=0, state=None, config=None, |
| 492 options=None, side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): | 494 options=None, side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): |
| 493 # Allow to pass in empty dictionaries. | 495 # Allow to pass in empty dictionaries. |
| 494 state = state if state is not None else {} | 496 state = state if state is not None else {} |
| 495 config = config if config is not None else {} | 497 config = config if config is not None else {} |
| 496 | 498 |
| 497 try: | 499 try: |
| 498 message = step_class.MESSAGE | 500 message = step_class.MESSAGE |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 516 if options.s == 0 and os.path.exists(state_file): | 518 if options.s == 0 and os.path.exists(state_file): |
| 517 os.remove(state_file) | 519 os.remove(state_file) |
| 518 state = {} | 520 state = {} |
| 519 steps = [] | 521 steps = [] |
| 520 for (number, step_class) in enumerate(step_classes): | 522 for (number, step_class) in enumerate(step_classes): |
| 521 steps.append(MakeStep(step_class, number, state, config, | 523 steps.append(MakeStep(step_class, number, state, config, |
| 522 options, side_effect_handler)) | 524 options, side_effect_handler)) |
| 523 | 525 |
| 524 for step in steps[options.s:]: | 526 for step in steps[options.s:]: |
| 525 step.Run() | 527 step.Run() |
| OLD | NEW |