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

Side by Side Diff: owners.py

Issue 10384099: Readd missing unittests for owners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix parent dir search Created 8 years, 7 months 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 | tests/owners_unittest.py » ('j') | no next file with comments »
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 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
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)
183 if self._stop_looking(dirname): 182 if self._stop_looking(dirname):
184 break 183 break
184 prev_parent = dirname
185 dirname = self.os_path.dirname(dirname) 185 dirname = self.os_path.dirname(dirname)
186 if prev_parent == dirname:
187 break
186 188
187 # Map each directory to a list of its owners. 189 # Map each directory to a list of its owners.
188 dir_owners[current_dir] = current_owners 190 dir_owners[current_dir] = current_owners
189 191
190 # Add the directory to the list of each owner. 192 # Add the directory to the list of each owner.
191 for owner in current_owners: 193 for owner in current_owners:
192 if not owner in owned_dirs: 194 owned_dirs.setdefault(owner, set()).add(current_dir)
193 owned_dirs[owner] = set()
194 owned_dirs[owner].add(current_dir)
195 195
196 final_owners = set() 196 final_owners = set()
197 while dirs: 197 while dirs:
198 # Find the owner that has the most directories. 198 # Find the owner that has the most directories.
199 max_count = 0 199 max_count = 0
200 max_owner = None 200 max_owner = None
201 owner_count = {} 201 owner_count = {}
202 for dirname in dirs: 202 for dirname in dirs:
203 for owner in dir_owners[dirname]: 203 for owner in dir_owners[dirname]:
204 count = owner_count.get(owner, 0) + 1 204 count = owner_count.get(owner, 0) + 1
205 owner_count[owner] = count 205 owner_count[owner] = count
206 if count >= max_count: 206 if count >= max_count:
207 max_owner = owner 207 max_owner = owner
208 max_count = count
208 209
209 # If no more directories have OWNERS, we're done. 210 # If no more directories have OWNERS, we're done.
210 if not max_owner: 211 if not max_owner:
211 break 212 break
212 213
213 final_owners.add(max_owner) 214 final_owners.add(max_owner)
214 215
215 # Remove all directories owned by the current owner from the remaining 216 # Remove all directories owned by the current owner from the remaining
216 # list. 217 # list.
217 for dirname in owned_dirs[max_owner]: 218 for dirname in owned_dirs[max_owner]:
218 if dirname in dirs: 219 dirs.discard(dirname)
219 dirs.remove(dirname)
220 220
221 return final_owners 221 return final_owners
OLDNEW
« no previous file with comments | « no previous file | tests/owners_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698