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 import collections | 7 import collections |
8 import re | 8 import re |
9 | 9 |
10 | 10 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 dirs.add(self.os_path.dirname(f)) | 171 dirs.add(self.os_path.dirname(f)) |
172 | 172 |
173 owned_dirs = {} | 173 owned_dirs = {} |
174 dir_owners = {} | 174 dir_owners = {} |
175 | 175 |
176 for current_dir in dirs: | 176 for current_dir in dirs: |
177 # Get the list of owners for each directory. | 177 # Get the list of owners for each directory. |
178 current_owners = set() | 178 current_owners = set() |
179 dirname = current_dir | 179 dirname = current_dir |
180 while dirname in self.owners_for: | 180 while dirname in self.owners_for: |
181 for owner in self.owners_for[dirname]: | 181 current_owners |= self.owners_for[dirname] |
182 current_owners.add(owner) | 182 if self._stop_looking(dirname) or dirname == '/': |
Dirk Pranke
2012/05/10 18:26:11
I'm a bit troubled by the "dirname == '/'" additio
| |
183 if self._stop_looking(dirname): | |
184 break | 183 break |
185 dirname = self.os_path.dirname(dirname) | 184 dirname = self.os_path.dirname(dirname) |
186 | 185 |
187 # Map each directory to a list of its owners. | 186 # Map each directory to a list of its owners. |
188 dir_owners[current_dir] = current_owners | 187 dir_owners[current_dir] = current_owners |
189 | 188 |
190 # Add the directory to the list of each owner. | 189 # Add the directory to the list of each owner. |
191 for owner in current_owners: | 190 for owner in current_owners: |
192 if not owner in owned_dirs: | 191 owned_dirs.setdefault(owner, set()).add(current_dir) |
193 owned_dirs[owner] = set() | |
194 owned_dirs[owner].add(current_dir) | |
195 | 192 |
196 final_owners = set() | 193 final_owners = set() |
197 while dirs: | 194 while dirs: |
198 # Find the owner that has the most directories. | 195 # Find the owner that has the most directories. |
199 max_count = 0 | 196 max_count = 0 |
200 max_owner = None | 197 max_owner = None |
201 owner_count = {} | 198 owner_count = {} |
202 for dirname in dirs: | 199 for dirname in dirs: |
203 for owner in dir_owners[dirname]: | 200 for owner in dir_owners[dirname]: |
204 count = owner_count.get(owner, 0) + 1 | 201 count = owner_count.get(owner, 0) + 1 |
205 owner_count[owner] = count | 202 owner_count[owner] = count |
206 if count >= max_count: | 203 if count >= max_count: |
207 max_owner = owner | 204 max_owner = owner |
205 max_count = count | |
208 | 206 |
209 # If no more directories have OWNERS, we're done. | 207 # If no more directories have OWNERS, we're done. |
210 if not max_owner: | 208 if not max_owner: |
211 break | 209 break |
212 | 210 |
213 final_owners.add(max_owner) | 211 final_owners.add(max_owner) |
214 | 212 |
215 # Remove all directories owned by the current owner from the remaining | 213 # Remove all directories owned by the current owner from the remaining |
216 # list. | 214 # list. |
217 for dirname in owned_dirs[max_owner]: | 215 for dirname in owned_dirs[max_owner]: |
218 if dirname in dirs: | 216 dirs.discard(dirname) |
219 dirs.remove(dirname) | |
220 | 217 |
221 return final_owners | 218 return final_owners |
OLD | NEW |