Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: owners.py

Issue 11569018: Suggest owners for OWNERS files that only have per-file owners. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | testing_support/filesystem_mock.py » ('j') | testing_support/filesystem_mock.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """A database of OWNERS files. 5 """A database of OWNERS files.
6 6
7 OWNERS files indicate who is allowed to approve changes in a specific directory 7 OWNERS files indicate who is allowed to approve changes in a specific directory
8 (or who is allowed to make changes without needing approval of another OWNER). 8 (or who is allowed to make changes without needing approval of another OWNER).
9 Note that all changes must still be reviewed by someone familiar with the code, 9 Note that all changes must still be reviewed by someone familiar with the code,
10 so you may need approval from both an OWNER and a reviewer in many cases. 10 so you may need approval from both an OWNER and a reviewer in many cases.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if not self._is_obj_covered_by(o, covered_objs)] 150 if not self._is_obj_covered_by(o, covered_objs)]
151 151
152 return set(uncovered_objs) 152 return set(uncovered_objs)
153 153
154 objects_not_covered_by = directories_not_covered_by 154 objects_not_covered_by = directories_not_covered_by
155 155
156 def _check_paths(self, files): 156 def _check_paths(self, files):
157 def _is_under(f, pfx): 157 def _is_under(f, pfx):
158 return self.os_path.abspath(self.os_path.join(pfx, f)).startswith(pfx) 158 return self.os_path.abspath(self.os_path.join(pfx, f)).startswith(pfx)
159 _assert_is_collection(files) 159 _assert_is_collection(files)
160 assert all(_is_under(f, self.os_path.abspath(self.root)) for f in files) 160 assert all(not self.os_path.isabs(f) and
161 _is_under(f, self.os_path.abspath(self.root)) for f in files)
161 162
162 def _check_reviewers(self, reviewers): 163 def _check_reviewers(self, reviewers):
163 _assert_is_collection(reviewers) 164 _assert_is_collection(reviewers)
164 assert all(self.email_regexp.match(r) for r in reviewers) 165 assert all(self.email_regexp.match(r) for r in reviewers)
165 166
166 # TODO(dpranke): Rename to _objs_covered_by and update_callers 167 # TODO(dpranke): Rename to _objs_covered_by and update_callers
167 def _dirs_covered_by(self, reviewers): 168 def _dirs_covered_by(self, reviewers):
168 dirs = self.owned_by[EVERYONE] 169 dirs = self.owned_by[EVERYONE]
169 for r in reviewers: 170 for r in reviewers:
170 dirs = dirs | self.owned_by.get(r, set()) 171 dirs = dirs | self.owned_by.get(r, set())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 else: 250 else:
250 raise SyntaxErrorInOwnersFile(owners_path, lineno, 251 raise SyntaxErrorInOwnersFile(owners_path, lineno,
251 ('%s is not a "set" directive, "*", ' 252 ('%s is not a "set" directive, "*", '
252 'or an email address: "%s"' % (line_type, directive))) 253 'or an email address: "%s"' % (line_type, directive)))
253 254
254 255
255 def _covering_set_of_owners_for(self, files): 256 def _covering_set_of_owners_for(self, files):
256 # Get the set of directories from the files. 257 # Get the set of directories from the files.
257 dirs = set() 258 dirs = set()
258 for f in files: 259 for f in files:
259 dirs.add(self.os_path.dirname(f)) 260 dirs.add(self._enclosing_dir_with_owners(f))
261
260 262
261 owned_dirs = {} 263 owned_dirs = {}
262 dir_owners = {} 264 dir_owners = {}
263 265
264 for current_dir in dirs: 266 for current_dir in dirs:
265 # Get the list of owners for each directory. 267 # Get the list of owners for each directory.
266 current_owners = set() 268 current_owners = set()
267 dirname = current_dir 269 dirname = current_dir
268 while dirname in self.owners_for: 270 while dirname in self.owners_for:
269 current_owners |= self.owners_for[dirname] 271 current_owners |= self.owners_for[dirname]
(...skipping 30 matching lines...) Expand all
300 break 302 break
301 303
302 final_owners.add(max_owner) 304 final_owners.add(max_owner)
303 305
304 # Remove all directories owned by the current owner from the remaining 306 # Remove all directories owned by the current owner from the remaining
305 # list. 307 # list.
306 for dirname in owned_dirs[max_owner]: 308 for dirname in owned_dirs[max_owner]:
307 dirs.discard(dirname) 309 dirs.discard(dirname)
308 310
309 return final_owners 311 return final_owners
OLDNEW
« no previous file with comments | « no previous file | testing_support/filesystem_mock.py » ('j') | testing_support/filesystem_mock.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698