Revert "Reland "gclient: Require a target ref when applying patches.""
This reverts commit 822dbc51a298688c61e4dd8c40fbc714e1460663.
Reason for revert:
Skia autoroller is complaining
https://skia-review.googlesource.com/c/buildbot/+/219338
Original change's description:
> Reland "gclient: Require a target ref when applying patches."
>
> This is a reland of 1d6478a5ffed7d272a7910d678e0a35d2f9fd69b
>
> Original change's description:
> > gclient: Require a target ref when applying patches.
> >
> > Bug: 956807
> > Change-Id: Icfffe965f9f4651f22e8ba32c60133a5620bb350
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1616804
> > Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
> > Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
>
> Bug: 956807
> Change-Id: I3de8475a091ce6a2a14ff7dcfb92507a205ef78c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1623594
> Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
TBR=borenet@chromium.org,tandrii@chromium.org,ehmaldonado@chromium.org
Change-Id: I14a70206a34f7024abc21039806f23dc7cf56bb6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 956807
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1648321
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/gclient_scm.py b/gclient_scm.py
index 72a5dd5..ef7dbae 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -351,6 +351,28 @@
self.Print('FAILED to break lock: %s: %s' % (to_break, ex))
raise
+ # TODO(ehmaldonado): Remove after bot_update is modified to pass the patch's
+ # branch.
+ def _GetTargetBranchForCommit(self, commit):
+ """Get the remote branch a commit is part of."""
+ _WELL_KNOWN_BRANCHES = [
+ 'refs/remotes/origin/master',
+ 'refs/remotes/origin/infra/config',
+ 'refs/remotes/origin/lkgr',
+ ]
+ for branch in _WELL_KNOWN_BRANCHES:
+ if scm.GIT.IsAncestor(self.checkout_path, commit, branch):
+ return branch
+ remote_refs = self._Capture(
+ ['for-each-ref', 'refs/remotes/%s' % self.remote,
+ '--format=%(refname)']).splitlines()
+ for ref in sorted(remote_refs, reverse=True):
+ if scm.GIT.IsAncestor(self.checkout_path, commit, ref):
+ return ref
+ self.Print('Failed to find a remote ref that contains %s. '
+ 'Candidate refs were %s.' % (commit, remote_refs))
+ return None
+
def apply_patch_ref(self, patch_repo, patch_rev, target_rev, options,
file_list):
"""Apply a patch on top of the revision we're synced at.
@@ -397,7 +419,8 @@
base_rev = self._Capture(['rev-parse', 'HEAD'])
if not target_rev:
- raise gclient_utils.Error('A target revision for the patch must be given')
+ # TODO(ehmaldonado): Raise an error once |target_rev| is mandatory.
+ target_rev = self._GetTargetBranchForCommit(base_rev) or base_rev
elif target_rev.startswith('refs/heads/'):
# If |target_rev| is in refs/heads/**, try first to find the corresponding
# remote ref for it, since |target_rev| might point to a local ref which