mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Remove old DepotToolsOwners implementation
code-owners should have been enabled for most hosts that depot_tools supports by now. Remove our own implementation and rely on code-owners. Change-Id: Iaf0d3db65b2e5063b67d42b92188c4ec51d2cd9a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3783475 Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com> Reviewed-by: Joanna Wang <jojwang@chromium.org> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -2,15 +2,11 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import random
|
||||
import threading
|
||||
|
||||
import gerrit_util
|
||||
import git_common
|
||||
import owners as owners_db
|
||||
import scm
|
||||
|
||||
|
||||
class OwnersClient(object):
|
||||
@@ -117,47 +113,6 @@ class OwnersClient(object):
|
||||
|
||||
return selected
|
||||
|
||||
|
||||
class DepotToolsClient(OwnersClient):
|
||||
"""Implement OwnersClient using owners.py Database."""
|
||||
def __init__(self, root, branch, fopen=open, os_path=os.path):
|
||||
super(DepotToolsClient, self).__init__()
|
||||
|
||||
self._root = root
|
||||
self._branch = branch
|
||||
self._fopen = fopen
|
||||
self._os_path = os_path
|
||||
self._db = None
|
||||
self._db_lock = threading.Lock()
|
||||
|
||||
def _ensure_db(self):
|
||||
if self._db is not None:
|
||||
return
|
||||
self._db = owners_db.Database(self._root, self._fopen, self._os_path)
|
||||
self._db.override_files = self._GetOriginalOwnersFiles()
|
||||
|
||||
def _GetOriginalOwnersFiles(self):
|
||||
return {
|
||||
f: scm.GIT.GetOldContents(self._root, f, self._branch).splitlines()
|
||||
for _, f in scm.GIT.CaptureStatus(self._root, self._branch)
|
||||
if os.path.basename(f) == 'OWNERS'
|
||||
}
|
||||
|
||||
def ListOwners(self, path):
|
||||
# all_possible_owners is not thread safe.
|
||||
with self._db_lock:
|
||||
self._ensure_db()
|
||||
# all_possible_owners returns a dict {owner: [(path, distance)]}. We want
|
||||
# to return a list of owners sorted by increasing distance.
|
||||
distance_by_owner = self._db.all_possible_owners([path], None)
|
||||
# We add a small random number to the distance, so that owners at the
|
||||
# same distance are returned in random order to avoid overloading those
|
||||
# who would appear first.
|
||||
return sorted(
|
||||
distance_by_owner,
|
||||
key=lambda o: distance_by_owner[o][0][1] + random.random())
|
||||
|
||||
|
||||
class GerritClient(OwnersClient):
|
||||
"""Implement OwnersClient using OWNERS REST API."""
|
||||
def __init__(self, host, project, branch):
|
||||
@@ -196,11 +151,14 @@ class GerritClient(OwnersClient):
|
||||
return self._owners_cache[path]
|
||||
|
||||
|
||||
def GetCodeOwnersClient(root, upstream, host, project, branch):
|
||||
def GetCodeOwnersClient(host, project, branch):
|
||||
"""Get a new OwnersClient.
|
||||
|
||||
Defaults to GerritClient, and falls back to DepotToolsClient if code-owners
|
||||
plugin is not available."""
|
||||
Uses GerritClient and raises an exception if code-owners plugin is not
|
||||
available."""
|
||||
if gerrit_util.IsCodeOwnersEnabledOnHost(host):
|
||||
return GerritClient(host, project, branch)
|
||||
return DepotToolsClient(root, upstream)
|
||||
raise Exception(
|
||||
'code-owners plugin is not enabled. Ask your host admin to enable it '
|
||||
'on %s. Read more about code-owners at '
|
||||
'https://gerrit.googlesource.com/plugins/code-owners.' % host)
|
||||
|
||||
Reference in New Issue
Block a user