summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.py10
-rwxr-xr-xmain.py4
-rw-r--r--manifest.py37
-rw-r--r--manifest_loader.py27
-rw-r--r--manifest_xml.py57
-rw-r--r--subcmds/help.py1
-rw-r--r--subcmds/sync.py2
7 files changed, 99 insertions, 39 deletions
diff --git a/command.py b/command.py
index a941b95a..5ca43f20 100644
--- a/command.py
+++ b/command.py
@@ -17,6 +17,8 @@ import os
17import optparse 17import optparse
18import sys 18import sys
19 19
20import manifest_loader
21
20from error import NoSuchProjectError 22from error import NoSuchProjectError
21 23
22class Command(object): 24class Command(object):
@@ -24,7 +26,6 @@ class Command(object):
24 """ 26 """
25 27
26 common = False 28 common = False
27 manifest = None
28 _optparse = None 29 _optparse = None
29 30
30 def WantPager(self, opt): 31 def WantPager(self, opt):
@@ -57,6 +58,13 @@ class Command(object):
57 """ 58 """
58 raise NotImplementedError 59 raise NotImplementedError
59 60
61 @property
62 def manifest(self):
63 return self.GetManifest()
64
65 def GetManifest(self, reparse=False):
66 return manifest_loader.GetManifest(self.repodir, reparse)
67
60 def GetProjects(self, args, missing_ok=False): 68 def GetProjects(self, args, missing_ok=False):
61 """A list of projects that match the arguments. 69 """A list of projects that match the arguments.
62 """ 70 """
diff --git a/main.py b/main.py
index 70ddeffa..a60641d7 100755
--- a/main.py
+++ b/main.py
@@ -32,11 +32,9 @@ from git_config import close_ssh
32from command import InteractiveCommand 32from command import InteractiveCommand
33from command import MirrorSafeCommand 33from command import MirrorSafeCommand
34from command import PagedCommand 34from command import PagedCommand
35from editor import Editor
36from error import ManifestInvalidRevisionError 35from error import ManifestInvalidRevisionError
37from error import NoSuchProjectError 36from error import NoSuchProjectError
38from error import RepoChangedException 37from error import RepoChangedException
39from manifest_xml import XmlManifest
40from pager import RunPager 38from pager import RunPager
41 39
42from subcmds import all as all_commands 40from subcmds import all as all_commands
@@ -97,8 +95,6 @@ class _Repo(object):
97 sys.exit(1) 95 sys.exit(1)
98 96
99 cmd.repodir = self.repodir 97 cmd.repodir = self.repodir
100 cmd.manifest = XmlManifest(cmd.repodir)
101 Editor.globalConfig = cmd.manifest.globalConfig
102 98
103 if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: 99 if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
104 print >>sys.stderr, \ 100 print >>sys.stderr, \
diff --git a/manifest.py b/manifest.py
new file mode 100644
index 00000000..bf801dfa
--- /dev/null
+++ b/manifest.py
@@ -0,0 +1,37 @@
1#
2# Copyright (C) 2009 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17
18from editor import Editor
19from git_config import GitConfig
20from project import MetaProject
21
22class Manifest(object):
23 """any manifest format"""
24
25 def __init__(self, repodir):
26 self.repodir = os.path.abspath(repodir)
27 self.topdir = os.path.dirname(self.repodir)
28 self.globalConfig = GitConfig.ForUser()
29 Editor.globalConfig = self.globalConfig
30
31 self.repoProject = MetaProject(self, 'repo',
32 gitdir = os.path.join(repodir, 'repo/.git'),
33 worktree = os.path.join(repodir, 'repo'))
34
35 @property
36 def IsMirror(self):
37 return self.manifestProject.config.GetBoolean('repo.mirror')
diff --git a/manifest_loader.py b/manifest_loader.py
new file mode 100644
index 00000000..85ad3ea1
--- /dev/null
+++ b/manifest_loader.py
@@ -0,0 +1,27 @@
1#
2# Copyright (C) 2009 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from manifest_xml import XmlManifest
17
18def ParseManifest(repodir):
19 return XmlManifest(repodir)
20
21_manifest = None
22
23def GetManifest(repodir, reparse=False):
24 global _manifest
25 if _manifest is None or reparse:
26 _manifest = ParseManifest(repodir)
27 return _manifest
diff --git a/manifest_xml.py b/manifest_xml.py
index 7d02f9d6..971cf212 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -18,6 +18,7 @@ import sys
18import xml.dom.minidom 18import xml.dom.minidom
19 19
20from git_config import GitConfig, IsId 20from git_config import GitConfig, IsId
21from manifest import Manifest
21from project import RemoteSpec, Project, MetaProject, R_HEADS, HEAD 22from project import RemoteSpec, Project, MetaProject, R_HEADS, HEAD
22from error import ManifestParseError 23from error import ManifestParseError
23 24
@@ -46,19 +47,13 @@ class _XmlRemote(object):
46 url += '/%s.git' % projectName 47 url += '/%s.git' % projectName
47 return RemoteSpec(self.name, url, self.reviewUrl) 48 return RemoteSpec(self.name, url, self.reviewUrl)
48 49
49class XmlManifest(object): 50class XmlManifest(Manifest):
50 """manages the repo configuration file""" 51 """manages the repo configuration file"""
51 52
52 def __init__(self, repodir): 53 def __init__(self, repodir):
53 self.repodir = os.path.abspath(repodir) 54 Manifest.__init__(self, repodir)
54 self.topdir = os.path.dirname(self.repodir)
55 self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME)
56 self.globalConfig = GitConfig.ForUser()
57
58 self.repoProject = MetaProject(self, 'repo',
59 gitdir = os.path.join(repodir, 'repo/.git'),
60 worktree = os.path.join(repodir, 'repo'))
61 55
56 self._manifestFile = os.path.join(repodir, MANIFEST_FILE_NAME)
62 self.manifestProject = MetaProject(self, 'manifests', 57 self.manifestProject = MetaProject(self, 'manifests',
63 gitdir = os.path.join(repodir, 'manifests.git'), 58 gitdir = os.path.join(repodir, 'manifests.git'),
64 worktree = os.path.join(repodir, 'manifests')) 59 worktree = os.path.join(repodir, 'manifests'))
@@ -72,18 +67,18 @@ class XmlManifest(object):
72 if not os.path.isfile(path): 67 if not os.path.isfile(path):
73 raise ManifestParseError('manifest %s not found' % name) 68 raise ManifestParseError('manifest %s not found' % name)
74 69
75 old = self.manifestFile 70 old = self._manifestFile
76 try: 71 try:
77 self.manifestFile = path 72 self._manifestFile = path
78 self._Unload() 73 self._Unload()
79 self._Load() 74 self._Load()
80 finally: 75 finally:
81 self.manifestFile = old 76 self._manifestFile = old
82 77
83 try: 78 try:
84 if os.path.exists(self.manifestFile): 79 if os.path.exists(self._manifestFile):
85 os.remove(self.manifestFile) 80 os.remove(self._manifestFile)
86 os.symlink('manifests/%s' % name, self.manifestFile) 81 os.symlink('manifests/%s' % name, self._manifestFile)
87 except OSError, e: 82 except OSError, e:
88 raise ManifestParseError('cannot link manifest %s' % name) 83 raise ManifestParseError('cannot link manifest %s' % name)
89 84
@@ -168,10 +163,6 @@ class XmlManifest(object):
168 self._Load() 163 self._Load()
169 return self._default 164 return self._default
170 165
171 @property
172 def IsMirror(self):
173 return self.manifestProject.config.GetBoolean('repo.mirror')
174
175 def _Unload(self): 166 def _Unload(self):
176 self._loaded = False 167 self._loaded = False
177 self._projects = {} 168 self._projects = {}
@@ -192,11 +183,11 @@ class XmlManifest(object):
192 local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) 183 local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME)
193 if os.path.exists(local): 184 if os.path.exists(local):
194 try: 185 try:
195 real = self.manifestFile 186 real = self._manifestFile
196 self.manifestFile = local 187 self._manifestFile = local
197 self._ParseManifest(False) 188 self._ParseManifest(False)
198 finally: 189 finally:
199 self.manifestFile = real 190 self._manifestFile = real
200 191
201 if self.IsMirror: 192 if self.IsMirror:
202 self._AddMetaProjectMirror(self.repoProject) 193 self._AddMetaProjectMirror(self.repoProject)
@@ -205,17 +196,17 @@ class XmlManifest(object):
205 self._loaded = True 196 self._loaded = True
206 197
207 def _ParseManifest(self, is_root_file): 198 def _ParseManifest(self, is_root_file):
208 root = xml.dom.minidom.parse(self.manifestFile) 199 root = xml.dom.minidom.parse(self._manifestFile)
209 if not root or not root.childNodes: 200 if not root or not root.childNodes:
210 raise ManifestParseError, \ 201 raise ManifestParseError, \
211 "no root node in %s" % \ 202 "no root node in %s" % \
212 self.manifestFile 203 self._manifestFile
213 204
214 config = root.childNodes[0] 205 config = root.childNodes[0]
215 if config.nodeName != 'manifest': 206 if config.nodeName != 'manifest':
216 raise ManifestParseError, \ 207 raise ManifestParseError, \
217 "no <manifest> in %s" % \ 208 "no <manifest> in %s" % \
218 self.manifestFile 209 self._manifestFile
219 210
220 for node in config.childNodes: 211 for node in config.childNodes:
221 if node.nodeName == 'remove-project': 212 if node.nodeName == 'remove-project':
@@ -233,7 +224,7 @@ class XmlManifest(object):
233 if self._remotes.get(remote.name): 224 if self._remotes.get(remote.name):
234 raise ManifestParseError, \ 225 raise ManifestParseError, \
235 'duplicate remote %s in %s' % \ 226 'duplicate remote %s in %s' % \
236 (remote.name, self.manifestFile) 227 (remote.name, self._manifestFile)
237 self._remotes[remote.name] = remote 228 self._remotes[remote.name] = remote
238 229
239 for node in config.childNodes: 230 for node in config.childNodes:
@@ -241,7 +232,7 @@ class XmlManifest(object):
241 if self._default is not None: 232 if self._default is not None:
242 raise ManifestParseError, \ 233 raise ManifestParseError, \
243 'duplicate default in %s' % \ 234 'duplicate default in %s' % \
244 (self.manifestFile) 235 (self._manifestFile)
245 self._default = self._ParseDefault(node) 236 self._default = self._ParseDefault(node)
246 if self._default is None: 237 if self._default is None:
247 self._default = _Default() 238 self._default = _Default()
@@ -252,7 +243,7 @@ class XmlManifest(object):
252 if self._projects.get(project.name): 243 if self._projects.get(project.name):
253 raise ManifestParseError, \ 244 raise ManifestParseError, \
254 'duplicate project %s in %s' % \ 245 'duplicate project %s in %s' % \
255 (project.name, self.manifestFile) 246 (project.name, self._manifestFile)
256 self._projects[project.name] = project 247 self._projects[project.name] = project
257 248
258 def _AddMetaProjectMirror(self, m): 249 def _AddMetaProjectMirror(self, m):
@@ -324,7 +315,7 @@ class XmlManifest(object):
324 if remote is None: 315 if remote is None:
325 raise ManifestParseError, \ 316 raise ManifestParseError, \
326 "no remote for project %s within %s" % \ 317 "no remote for project %s within %s" % \
327 (name, self.manifestFile) 318 (name, self._manifestFile)
328 319
329 revisionExpr = node.getAttribute('revision') 320 revisionExpr = node.getAttribute('revision')
330 if not revisionExpr: 321 if not revisionExpr:
@@ -332,7 +323,7 @@ class XmlManifest(object):
332 if not revisionExpr: 323 if not revisionExpr:
333 raise ManifestParseError, \ 324 raise ManifestParseError, \
334 "no revision for project %s within %s" % \ 325 "no revision for project %s within %s" % \
335 (name, self.manifestFile) 326 (name, self._manifestFile)
336 327
337 path = node.getAttribute('path') 328 path = node.getAttribute('path')
338 if not path: 329 if not path:
@@ -340,7 +331,7 @@ class XmlManifest(object):
340 if path.startswith('/'): 331 if path.startswith('/'):
341 raise ManifestParseError, \ 332 raise ManifestParseError, \
342 "project %s path cannot be absolute in %s" % \ 333 "project %s path cannot be absolute in %s" % \
343 (name, self.manifestFile) 334 (name, self._manifestFile)
344 335
345 if self.IsMirror: 336 if self.IsMirror:
346 relpath = None 337 relpath = None
@@ -382,7 +373,7 @@ class XmlManifest(object):
382 if not v: 373 if not v:
383 raise ManifestParseError, \ 374 raise ManifestParseError, \
384 "remote %s not defined in %s" % \ 375 "remote %s not defined in %s" % \
385 (name, self.manifestFile) 376 (name, self._manifestFile)
386 return v 377 return v
387 378
388 def _reqatt(self, node, attname): 379 def _reqatt(self, node, attname):
@@ -393,5 +384,5 @@ class XmlManifest(object):
393 if not v: 384 if not v:
394 raise ManifestParseError, \ 385 raise ManifestParseError, \
395 "no %s in <%s> within %s" % \ 386 "no %s in <%s> within %s" % \
396 (attname, node.nodeName, self.manifestFile) 387 (attname, node.nodeName, self._manifestFile)
397 return v 388 return v
diff --git a/subcmds/help.py b/subcmds/help.py
index c5979fd6..01d5fa23 100644
--- a/subcmds/help.py
+++ b/subcmds/help.py
@@ -163,6 +163,7 @@ See 'repo help --all' for a complete list of recognized commands.
163 print >>sys.stderr, "repo: '%s' is not a repo command." % name 163 print >>sys.stderr, "repo: '%s' is not a repo command." % name
164 sys.exit(1) 164 sys.exit(1)
165 165
166 cmd.repodir = self.repodir
166 self._PrintCommandHelp(cmd) 167 self._PrintCommandHelp(cmd)
167 168
168 else: 169 else:
diff --git a/subcmds/sync.py b/subcmds/sync.py
index bd07dd9f..afd44dab 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -214,7 +214,7 @@ uncommitted changes are present' % project.relpath
214 if not syncbuf.Finish(): 214 if not syncbuf.Finish():
215 sys.exit(1) 215 sys.exit(1)
216 216
217 self.manifest._Unload() 217 self.GetManifest(reparse=True)
218 all = self.GetProjects(args, missing_ok=True) 218 all = self.GetProjects(args, missing_ok=True)
219 missing = [] 219 missing = []
220 for project in all: 220 for project in all: