OLD | NEW |
---|---|
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 if fnmatch.fnmatch(objname, owned_pattern): | 174 if fnmatch.fnmatch(objname, owned_pattern): |
175 return True | 175 return True |
176 if self._should_stop_looking(objname): | 176 if self._should_stop_looking(objname): |
177 break | 177 break |
178 objname = self.os_path.dirname(objname) | 178 objname = self.os_path.dirname(objname) |
179 return False | 179 return False |
180 | 180 |
181 def _enclosing_dir_with_owners(self, objname): | 181 def _enclosing_dir_with_owners(self, objname): |
182 """Returns the innermost enclosing directory that has an OWNERS file.""" | 182 """Returns the innermost enclosing directory that has an OWNERS file.""" |
183 dirpath = objname | 183 dirpath = objname |
184 while not self._owners_for(dirpath): | 184 while not self._owners_for(dirpath): |
ncarter (slow)
2016/08/30 22:51:27
I wonder if this check needs something like what h
| |
185 if self._should_stop_looking(dirpath): | 185 if self._should_stop_looking(dirpath): |
186 break | 186 break |
187 dirpath = self.os_path.dirname(dirpath) | 187 dirpath = self.os_path.dirname(dirpath) |
188 return dirpath | 188 return dirpath |
189 | 189 |
190 def load_data_needed_for(self, files): | 190 def load_data_needed_for(self, files): |
191 for f in files: | 191 for f in files: |
192 loaded_dirs = set() | |
192 dirpath = self.os_path.dirname(f) | 193 dirpath = self.os_path.dirname(f) |
193 while not self._owners_for(dirpath): | 194 while dirpath not in loaded_dirs: |
dtu
2016/08/31 02:35:46
Is loaded_dirs supposed to be at the top-level? I
| |
194 self._read_owners(self.os_path.join(dirpath, 'OWNERS')) | 195 self._read_owners(self.os_path.join(dirpath, 'OWNERS')) |
196 loaded_dirs.add(dirpath) | |
195 if self._should_stop_looking(dirpath): | 197 if self._should_stop_looking(dirpath): |
196 break | 198 break |
197 dirpath = self.os_path.dirname(dirpath) | 199 dirpath = self.os_path.dirname(dirpath) |
198 | 200 |
199 def _should_stop_looking(self, objname): | 201 def _should_stop_looking(self, objname): |
200 return any(fnmatch.fnmatch(objname, stop_looking) | 202 return any(fnmatch.fnmatch(objname, stop_looking) |
201 for stop_looking in self._stop_looking) | 203 for stop_looking in self._stop_looking) |
202 | 204 |
203 def _owners_for(self, objname): | 205 def _owners_for(self, objname): |
204 obj_owners = set() | 206 obj_owners = set() |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 @staticmethod | 364 @staticmethod |
363 def lowest_cost_owner(all_possible_owners, dirs): | 365 def lowest_cost_owner(all_possible_owners, dirs): |
364 total_costs_by_owner = Database.total_costs_by_owner(all_possible_owners, | 366 total_costs_by_owner = Database.total_costs_by_owner(all_possible_owners, |
365 dirs) | 367 dirs) |
366 # Return the lowest cost owner. In the case of a tie, pick one randomly. | 368 # Return the lowest cost owner. In the case of a tie, pick one randomly. |
367 lowest_cost = min(total_costs_by_owner.itervalues()) | 369 lowest_cost = min(total_costs_by_owner.itervalues()) |
368 lowest_cost_owners = filter( | 370 lowest_cost_owners = filter( |
369 lambda owner: total_costs_by_owner[owner] == lowest_cost, | 371 lambda owner: total_costs_by_owner[owner] == lowest_cost, |
370 total_costs_by_owner) | 372 total_costs_by_owner) |
371 return random.Random().choice(lowest_cost_owners) | 373 return random.Random().choice(lowest_cost_owners) |
OLD | NEW |