diff options
author | Shawn O. Pearce <sop@google.com> | 2008-11-04 07:37:10 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2008-11-05 18:08:32 -0800 |
commit | e284ad1d1a2c6fa0e0ac800e87b2607f9bda339e (patch) | |
tree | fcf35ac784ec2e13c78ee3882ccb1fec0ad3d049 /manifest.py | |
parent | 3e5481999d5f853e19ee5caaaaa968fc4b5176ab (diff) | |
download | git-repo-e284ad1d1a2c6fa0e0ac800e87b2607f9bda339e.tar.gz |
Add 'repo init --mirror' to download a complete forrestv1.1
The mirror option downloads a complete forrest (as described by the
manifest) and creates a replica of the remote repositories rather
than a client working directory. This permits other clients to
sync off the mirror site.
A mirror can be positioned in a "DMZ", where the mirror executes
"repo sync" to obtain changes from the external upstream and
clients inside the protected zone operate off the mirror only,
and therefore do not require direct git:// access to the external
upstream repositories.
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'manifest.py')
-rw-r--r-- | manifest.py | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/manifest.py b/manifest.py index b928cdfe..ea68b682 100644 --- a/manifest.py +++ b/manifest.py | |||
@@ -88,6 +88,10 @@ class Manifest(object): | |||
88 | self._Load() | 88 | self._Load() |
89 | return self._default | 89 | return self._default |
90 | 90 | ||
91 | @property | ||
92 | def IsMirror(self): | ||
93 | return self.manifestProject.config.GetBoolean('repo.mirror') | ||
94 | |||
91 | def _Unload(self): | 95 | def _Unload(self): |
92 | self._loaded = False | 96 | self._loaded = False |
93 | self._projects = {} | 97 | self._projects = {} |
@@ -114,6 +118,10 @@ class Manifest(object): | |||
114 | finally: | 118 | finally: |
115 | self.manifestFile = real | 119 | self.manifestFile = real |
116 | 120 | ||
121 | if self.IsMirror: | ||
122 | self._AddMetaProjectMirror(self.repoProject) | ||
123 | self._AddMetaProjectMirror(self.manifestProject) | ||
124 | |||
117 | self._loaded = True | 125 | self._loaded = True |
118 | 126 | ||
119 | def _ParseManifest(self, is_root_file): | 127 | def _ParseManifest(self, is_root_file): |
@@ -157,6 +165,40 @@ class Manifest(object): | |||
157 | (project.name, self.manifestFile) | 165 | (project.name, self.manifestFile) |
158 | self._projects[project.name] = project | 166 | self._projects[project.name] = project |
159 | 167 | ||
168 | def _AddMetaProjectMirror(self, m): | ||
169 | name = None | ||
170 | m_url = m.GetRemote(m.remote.name).url | ||
171 | if m_url.endswith('/.git'): | ||
172 | raise ManifestParseError, 'refusing to mirror %s' % m_url | ||
173 | |||
174 | if self._default and self._default.remote: | ||
175 | url = self._default.remote.fetchUrl | ||
176 | if not url.endswith('/'): | ||
177 | url += '/' | ||
178 | if m_url.startswith(url): | ||
179 | remote = self._default.remote | ||
180 | name = m_url[len(url):] | ||
181 | |||
182 | if name is None: | ||
183 | s = m_url.rindex('/') + 1 | ||
184 | remote = Remote('origin', fetch = m_url[:s]) | ||
185 | name = m_url[s:] | ||
186 | |||
187 | if name.endswith('.git'): | ||
188 | name = name[:-4] | ||
189 | |||
190 | if name not in self._projects: | ||
191 | m.PreSync() | ||
192 | gitdir = os.path.join(self.topdir, '%s.git' % name) | ||
193 | project = Project(manifest = self, | ||
194 | name = name, | ||
195 | remote = remote, | ||
196 | gitdir = gitdir, | ||
197 | worktree = None, | ||
198 | relpath = None, | ||
199 | revision = m.revision) | ||
200 | self._projects[project.name] = project | ||
201 | |||
160 | def _ParseRemote(self, node): | 202 | def _ParseRemote(self, node): |
161 | """ | 203 | """ |
162 | reads a <remote> element from the manifest file | 204 | reads a <remote> element from the manifest file |
@@ -214,8 +256,13 @@ class Manifest(object): | |||
214 | "project %s path cannot be absolute in %s" % \ | 256 | "project %s path cannot be absolute in %s" % \ |
215 | (name, self.manifestFile) | 257 | (name, self.manifestFile) |
216 | 258 | ||
217 | worktree = os.path.join(self.topdir, path) | 259 | if self.IsMirror: |
218 | gitdir = os.path.join(self.repodir, 'projects/%s.git' % path) | 260 | relpath = None |
261 | worktree = None | ||
262 | gitdir = os.path.join(self.topdir, '%s.git' % name) | ||
263 | else: | ||
264 | worktree = os.path.join(self.topdir, path) | ||
265 | gitdir = os.path.join(self.repodir, 'projects/%s.git' % path) | ||
219 | 266 | ||
220 | project = Project(manifest = self, | 267 | project = Project(manifest = self, |
221 | name = name, | 268 | name = name, |
@@ -242,8 +289,10 @@ class Manifest(object): | |||
242 | def _ParseCopyFile(self, project, node): | 289 | def _ParseCopyFile(self, project, node): |
243 | src = self._reqatt(node, 'src') | 290 | src = self._reqatt(node, 'src') |
244 | dest = self._reqatt(node, 'dest') | 291 | dest = self._reqatt(node, 'dest') |
245 | # src is project relative, and dest is relative to the top of the tree | 292 | if not self.IsMirror: |
246 | project.AddCopyFile(src, os.path.join(self.topdir, dest)) | 293 | # src is project relative; |
294 | # dest is relative to the top of the tree | ||
295 | project.AddCopyFile(src, os.path.join(self.topdir, dest)) | ||
247 | 296 | ||
248 | def _get_remote(self, node): | 297 | def _get_remote(self, node): |
249 | name = node.getAttribute('remote') | 298 | name = node.getAttribute('remote') |