summaryrefslogtreecommitdiffstats
path: root/command.py
diff options
context:
space:
mode:
Diffstat (limited to 'command.py')
-rw-r--r--command.py72
1 files changed, 24 insertions, 48 deletions
diff --git a/command.py b/command.py
index d543e3a8..0c3b360c 100644
--- a/command.py
+++ b/command.py
@@ -60,32 +60,6 @@ class Command(object):
60 """ 60 """
61 raise NotImplementedError 61 raise NotImplementedError
62 62
63 def _ResetPathToProjectMap(self, projects):
64 self._by_path = dict((p.worktree, p) for p in projects)
65
66 def _UpdatePathToProjectMap(self, project):
67 self._by_path[project.worktree] = project
68
69 def _GetProjectByPath(self, path):
70 project = None
71 if os.path.exists(path):
72 oldpath = None
73 while path \
74 and path != oldpath \
75 and path != self.manifest.topdir:
76 try:
77 project = self._by_path[path]
78 break
79 except KeyError:
80 oldpath = path
81 path = os.path.dirname(path)
82 else:
83 try:
84 project = self._by_path[path]
85 except KeyError:
86 pass
87 return project
88
89 def GetProjects(self, args, missing_ok=False): 63 def GetProjects(self, args, missing_ok=False):
90 """A list of projects that match the arguments. 64 """A list of projects that match the arguments.
91 """ 65 """
@@ -100,38 +74,40 @@ class Command(object):
100 groups = [x for x in re.split('[,\s]+', groups) if x] 74 groups = [x for x in re.split('[,\s]+', groups) if x]
101 75
102 if not args: 76 if not args:
103 all_projects_list = all_projects.values() 77 for project in all_projects.values():
104 derived_projects = []
105 for project in all_projects_list:
106 if project.Registered:
107 # Do not search registered subproject for derived projects
108 # since its parent has been searched already
109 continue
110 derived_projects.extend(project.GetDerivedSubprojects())
111 all_projects_list.extend(derived_projects)
112 for project in all_projects_list:
113 if ((missing_ok or project.Exists) and 78 if ((missing_ok or project.Exists) and
114 project.MatchesGroups(groups)): 79 project.MatchesGroups(groups)):
115 result.append(project) 80 result.append(project)
116 else: 81 else:
117 self._ResetPathToProjectMap(all_projects.values()) 82 by_path = None
118 83
119 for arg in args: 84 for arg in args:
120 project = all_projects.get(arg) 85 project = all_projects.get(arg)
121 86
122 if not project: 87 if not project:
123 path = os.path.abspath(arg).replace('\\', '/') 88 path = os.path.abspath(arg).replace('\\', '/')
124 project = self._GetProjectByPath(path) 89
125 90 if not by_path:
126 # If it's not a derived project, update path->project mapping and 91 by_path = dict()
127 # search again, as arg might actually point to a derived subproject. 92 for p in all_projects.values():
128 if project and not project.Derived: 93 by_path[p.worktree] = p
129 search_again = False 94
130 for subproject in project.GetDerivedSubprojects(): 95 if os.path.exists(path):
131 self._UpdatePathToProjectMap(subproject) 96 oldpath = None
132 search_again = True 97 while path \
133 if search_again: 98 and path != oldpath \
134 project = self._GetProjectByPath(path) or project 99 and path != self.manifest.topdir:
100 try:
101 project = by_path[path]
102 break
103 except KeyError:
104 oldpath = path
105 path = os.path.dirname(path)
106 else:
107 try:
108 project = by_path[path]
109 except KeyError:
110 pass
135 111
136 if not project: 112 if not project:
137 raise NoSuchProjectError(arg) 113 raise NoSuchProjectError(arg)