Improve code readability in roll_deps
after https://webrtc-review.googlesource.com/36320 No-Try: True Bug: webrtc:8688 Change-Id: I7a16a813f86dfb24924beacdcc65a4a2a43532f5 Reviewed-on: https://webrtc-review.googlesource.com/36960 Commit-Queue: Oleh Prypin <oprypin@webrtc.org> Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21470}
This commit is contained in:
@ -403,7 +403,7 @@ def _LocalCommit(commit_msg, dry_run):
|
||||
_RunCommand(['git', 'commit', '-m', commit_msg])
|
||||
|
||||
|
||||
def ShouldUseCQ(skip_cq, cq_over, current_commit_pos, new_commit_pos):
|
||||
def ChooseCQMode(skip_cq, cq_over, current_commit_pos, new_commit_pos):
|
||||
if skip_cq:
|
||||
return 0
|
||||
if (new_commit_pos - current_commit_pos) < cq_over:
|
||||
@ -411,24 +411,22 @@ def ShouldUseCQ(skip_cq, cq_over, current_commit_pos, new_commit_pos):
|
||||
return 2
|
||||
|
||||
|
||||
def _UploadCL(dry_run, commit_queue=2):
|
||||
def _UploadCL(commit_queue_mode):
|
||||
"""Upload the committed changes as a changelist to Gerrit.
|
||||
|
||||
commit_queue:
|
||||
commit_queue_mode:
|
||||
- 2: Submit to commit queue.
|
||||
- 1: Commit queue dry run.
|
||||
- 1: Run trybots but do not submit to CQ.
|
||||
- 0: Skip CQ, upload only.
|
||||
"""
|
||||
logging.info('Uploading CL...')
|
||||
if not dry_run:
|
||||
cmd = ['git', 'cl', 'upload', '-f', '--gerrit']
|
||||
if commit_queue >= 2:
|
||||
logging.info('Sending the CL to the CQ...')
|
||||
cmd.extend(['--use-commit-queue', '--send-mail'])
|
||||
elif commit_queue >= 1:
|
||||
logging.info('Starting CQ dry run...')
|
||||
cmd.extend(['--cq-dry-run'])
|
||||
_RunCommand(cmd, extra_env={'EDITOR': 'true', 'SKIP_GCE_AUTH_FOR_GIT': '1'})
|
||||
cmd = ['git', 'cl', 'upload', '-f', '--gerrit']
|
||||
if commit_queue_mode >= 2:
|
||||
logging.info('Sending the CL to the CQ...')
|
||||
cmd.extend(['--use-commit-queue', '--send-mail'])
|
||||
elif commit_queue_mode >= 1:
|
||||
logging.info('Starting CQ dry run...')
|
||||
cmd.extend(['--cq-dry-run'])
|
||||
_RunCommand(cmd, extra_env={'EDITOR': 'true', 'SKIP_GCE_AUTH_FOR_GIT': '1'})
|
||||
|
||||
|
||||
def main():
|
||||
@ -503,9 +501,11 @@ def main():
|
||||
logging.info("No DEPS changes detected, skipping CL creation.")
|
||||
else:
|
||||
_LocalCommit(commit_msg, opts.dry_run)
|
||||
commit_queue = ShouldUseCQ(opts.skip_cq, opts.cq_over,
|
||||
current_commit_pos, new_commit_pos)
|
||||
_UploadCL(opts.dry_run, commit_queue)
|
||||
commit_queue_mode = ChooseCQMode(opts.skip_cq, opts.cq_over,
|
||||
current_commit_pos, new_commit_pos)
|
||||
logging.info('Uploading CL...')
|
||||
if not opts.dry_run:
|
||||
_UploadCL(commit_queue_mode)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@ -19,8 +19,8 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir)
|
||||
sys.path.append(PARENT_DIR)
|
||||
import roll_deps
|
||||
from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, \
|
||||
ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile, ShouldUseCQ
|
||||
from roll_deps import CalculateChangedDeps, ChooseCQMode, \
|
||||
GetMatchingDepsEntries, ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile
|
||||
|
||||
|
||||
TEST_DATA_VARS = {
|
||||
@ -140,15 +140,15 @@ class TestRollChromiumRevision(unittest.TestCase):
|
||||
self.assertEquals(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV)
|
||||
|
||||
|
||||
class TestShouldUseCQ(unittest.TestCase):
|
||||
class TestChooseCQMode(unittest.TestCase):
|
||||
def testSkip(self):
|
||||
self.assertEquals(ShouldUseCQ(True, 99, 500000, 500100), 0)
|
||||
self.assertEquals(ChooseCQMode(True, 99, 500000, 500100), 0)
|
||||
|
||||
def testDryRun(self):
|
||||
self.assertEquals(ShouldUseCQ(False, 101, 500000, 500100), 1)
|
||||
self.assertEquals(ChooseCQMode(False, 101, 500000, 500100), 1)
|
||||
|
||||
def testSubmit(self):
|
||||
self.assertEquals(ShouldUseCQ(False, 100, 500000, 500100), 2)
|
||||
self.assertEquals(ChooseCQMode(False, 100, 500000, 500100), 2)
|
||||
|
||||
|
||||
def _SetupGitLsRemoteCall(cmd_fake, url, revision):
|
||||
|
||||
Reference in New Issue
Block a user