From a04cae9f5891835d2c8a5d9a3b80370cb2a01403 Mon Sep 17 00:00:00 2001 From: "yyanagisawa@chromium.org" Date: Wed, 6 Apr 2016 01:30:56 +0000 Subject: [PATCH] Add --gerrit_no_reset for who need to use FETCH_HEAD revision. Avoid to call git reset --soft to preserve current revision to FETCH_HEAD. 'got_revision' property would also be that from FETCH_HEAD. BUG=596787 Review URL: https://codereview.chromium.org/1837453002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299721 0039d316-1c4b-4281-b951-d872f2087c98 --- recipe_modules/bot_update/api.py | 4 +- .../example.expected/gerrit_no_reset.json | 45 +++++++++++++++++++ recipe_modules/bot_update/example.py | 10 ++++- .../bot_update/resources/bot_update.py | 15 ++++--- 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 recipe_modules/bot_update/example.expected/gerrit_no_reset.json diff --git a/recipe_modules/bot_update/api.py b/recipe_modules/bot_update/api.py index 2b64807e5..31a27335c 100644 --- a/recipe_modules/bot_update/api.py +++ b/recipe_modules/bot_update/api.py @@ -60,7 +60,7 @@ class BotUpdateApi(recipe_api.RecipeApi): patch_project_roots=None, patch_oauth2=False, output_manifest=True, clobber=False, root_solution_revision=None, rietveld=None, issue=None, - patchset=None, **kwargs): + patchset=None, gerrit_no_reset=False, **kwargs): """ Args: gclient_config: The gclient configuration to use when running bot_update. @@ -200,6 +200,8 @@ class BotUpdateApi(recipe_api.RecipeApi): cmd.append('--output_manifest') if with_branch_heads or cfg.with_branch_heads: cmd.append('--with_branch_heads') + if gerrit_no_reset: + cmd.append('--gerrit_no_reset') # Inject Json output for testing. git_mode = self._mastername not in SVN_MASTERS diff --git a/recipe_modules/bot_update/example.expected/gerrit_no_reset.json b/recipe_modules/bot_update/example.expected/gerrit_no_reset.json new file mode 100644 index 000000000..734b43e5a --- /dev/null +++ b/recipe_modules/bot_update/example.expected/gerrit_no_reset.json @@ -0,0 +1,45 @@ +[ + { + "cmd": [ + "python", + "-u", + "RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py", + "--master", + "experimental", + "--builder", + "Experimental Builder", + "--slave", + "somehost", + "--spec", + "cache_dir = '[GIT_CACHE]'\nsolutions = [{'deps_file': '.DEPS.git', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]", + "--root", + "src", + "--revision_mapping_file", + "{\"src\": \"got_cr_revision\"}", + "--git-cache-dir", + "[GIT_CACHE]", + "--output_json", + "/path/to/tmp/json", + "--revision", + "src@HEAD", + "--gerrit_no_reset" + ], + "cwd": "[SLAVE_BUILD]", + "env": { + "PATH": "%(PATH)s:RECIPE_PACKAGE_REPO[depot_tools]" + }, + "name": "bot_update", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@{@@@", + "@@@STEP_LOG_LINE@json.output@ \"did_run\": false, @@@", + "@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false@@@", + "@@@STEP_LOG_LINE@json.output@}@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "name": "$result", + "recipe_result": null, + "status_code": 0 + } +] diff --git a/recipe_modules/bot_update/example.py b/recipe_modules/bot_update/example.py index 9e915331e..99362ffcf 100644 --- a/recipe_modules/bot_update/example.py +++ b/recipe_modules/bot_update/example.py @@ -30,6 +30,7 @@ def RunSteps(api): oauth2 = api.properties.get('oauth2', False) root_solution_revision = api.properties.get('root_solution_revision') suffix = api.properties.get('suffix') + gerrit_no_reset = True if api.properties.get('gerrit_no_reset') else False api.bot_update.ensure_checkout(force=force, no_shallow=no_shallow, patch=patch, @@ -38,7 +39,8 @@ def RunSteps(api): refs=refs, patch_oauth2=oauth2, clobber=clobber, root_solution_revision=root_solution_revision, - suffix=suffix) + suffix=suffix, + gerrit_no_reset=gerrit_no_reset) def GenTests(api): @@ -143,6 +145,12 @@ def GenTests(api): slavename='somehost', root_solution_revision='revision', ) + yield api.test('gerrit_no_reset') + api.properties( + mastername='experimental', + buildername='Experimental Builder', + slavename='somehost', + gerrit_no_reset=1 + ) yield api.test('tryjob_v8') + api.properties( mastername='tryserver.chromium.linux', buildername='linux_rel', diff --git a/recipe_modules/bot_update/resources/bot_update.py b/recipe_modules/bot_update/resources/bot_update.py index c1c81d348..df60837d5 100755 --- a/recipe_modules/bot_update/resources/bot_update.py +++ b/recipe_modules/bot_update/resources/bot_update.py @@ -1132,14 +1132,15 @@ def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, except SubprocessFailed as e: raise PatchFailed(e.message, e.code, e.output) -def apply_gerrit_ref(gerrit_repo, gerrit_ref, root): +def apply_gerrit_ref(gerrit_repo, gerrit_ref, root, gerrit_reset): gerrit_repo = gerrit_repo or 'origin' assert gerrit_ref try: base_rev = git('rev-parse', 'HEAD', cwd=root).strip() git('retry', 'fetch', gerrit_repo, gerrit_ref, cwd=root, tries=1) git('checkout', 'FETCH_HEAD', cwd=root) - git('reset', '--soft', base_rev, cwd=root) + if gerrit_reset: + git('reset', '--soft', base_rev, cwd=root) except SubprocessFailed as e: raise PatchFailed(e.message, e.code, e.output) @@ -1297,7 +1298,8 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, patch_root, issue, patchset, patch_url, rietveld_server, gerrit_repo, gerrit_ref, revision_mapping, apply_issue_email_file, apply_issue_key_file, buildspec, - gyp_env, shallow, runhooks, refs, git_cache_dir): + gyp_env, shallow, runhooks, refs, git_cache_dir, + gerrit_reset): # Get a checkout of each solution, without DEPS or hooks. # Calling git directly because there is no way to run Gclient without # invoking DEPS. @@ -1363,7 +1365,7 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, revision_mapping, git_ref, apply_issue_email_file, apply_issue_key_file, blacklist=already_patched) elif gerrit_ref: - apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root) + apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset) # Reset the deps_file point in the solutions so that hooks get run properly. for sln in solutions: @@ -1442,6 +1444,8 @@ def parse_args(): parse.add_option('--gerrit_repo', help='Gerrit repository to pull the ref from.') parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') + parse.add_option('--gerrit_no_reset', action='store_true', + help='Bypass calling reset after applying a gerrit ref.') parse.add_option('--specs', help='Gcilent spec.') parse.add_option('--master', help='Master name.') parse.add_option('-f', '--force', action='store_true', @@ -1611,7 +1615,8 @@ def checkout(options, git_slns, specs, buildspec, master, # Finally, extra configurations such as shallowness of the clone. shallow=options.shallow, refs=options.refs, - git_cache_dir=options.git_cache_dir) + git_cache_dir=options.git_cache_dir, + gerrit_reset=not options.gerrit_no_reset) gclient_output = ensure_checkout(**checkout_parameters) except GclientSyncFailed: print 'We failed gclient sync, lets delete the checkout and retry.'