2008-10-21 14:00:00 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2008 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
import itertools
|
2008-10-21 14:00:00 +00:00
|
|
|
import os
|
2011-09-26 23:34:01 +00:00
|
|
|
import re
|
2008-10-21 14:00:00 +00:00
|
|
|
import sys
|
2011-09-26 23:34:01 +00:00
|
|
|
import urlparse
|
2008-10-21 14:00:00 +00:00
|
|
|
import xml.dom.minidom
|
|
|
|
|
2012-08-22 01:46:11 +00:00
|
|
|
from git_config import GitConfig
|
2012-09-11 05:33:51 +00:00
|
|
|
from git_refs import R_HEADS, HEAD
|
|
|
|
from project import RemoteSpec, Project, MetaProject
|
2008-10-21 14:00:00 +00:00
|
|
|
from error import ManifestParseError
|
|
|
|
|
|
|
|
MANIFEST_FILE_NAME = 'manifest.xml'
|
2008-10-23 23:19:27 +00:00
|
|
|
LOCAL_MANIFEST_NAME = 'local_manifest.xml'
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2011-09-26 23:34:01 +00:00
|
|
|
urlparse.uses_relative.extend(['ssh', 'git'])
|
|
|
|
urlparse.uses_netloc.extend(['ssh', 'git'])
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class _Default(object):
|
|
|
|
"""Project defaults within the manifest."""
|
|
|
|
|
2009-05-30 01:38:17 +00:00
|
|
|
revisionExpr = None
|
2008-10-21 14:00:00 +00:00
|
|
|
remote = None
|
2011-09-23 00:44:31 +00:00
|
|
|
sync_j = 1
|
2012-04-20 21:41:59 +00:00
|
|
|
sync_c = False
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-05-19 21:58:02 +00:00
|
|
|
class _XmlRemote(object):
|
|
|
|
def __init__(self,
|
|
|
|
name,
|
2012-07-02 14:32:50 +00:00
|
|
|
alias=None,
|
2009-05-19 21:58:02 +00:00
|
|
|
fetch=None,
|
2011-09-26 23:34:01 +00:00
|
|
|
manifestUrl=None,
|
2009-05-19 21:58:02 +00:00
|
|
|
review=None):
|
|
|
|
self.name = name
|
|
|
|
self.fetchUrl = fetch
|
2011-09-26 23:34:01 +00:00
|
|
|
self.manifestUrl = manifestUrl
|
2012-07-02 14:32:50 +00:00
|
|
|
self.remoteAlias = alias
|
2009-05-19 21:58:02 +00:00
|
|
|
self.reviewUrl = review
|
2011-10-20 17:45:47 +00:00
|
|
|
self.resolvedFetchUrl = self._resolveFetchUrl()
|
2009-05-19 21:58:02 +00:00
|
|
|
|
2011-10-20 17:45:47 +00:00
|
|
|
def _resolveFetchUrl(self):
|
|
|
|
url = self.fetchUrl.rstrip('/')
|
2011-09-26 23:34:01 +00:00
|
|
|
manifestUrl = self.manifestUrl.rstrip('/')
|
|
|
|
# urljoin will get confused if there is no scheme in the base url
|
|
|
|
# ie, if manifestUrl is of the form <hostname:port>
|
|
|
|
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
|
|
|
|
manifestUrl = 'gopher://' + manifestUrl
|
|
|
|
url = urlparse.urljoin(manifestUrl, url)
|
2011-10-20 17:45:47 +00:00
|
|
|
return re.sub(r'^gopher://', '', url)
|
|
|
|
|
|
|
|
def ToRemoteSpec(self, projectName):
|
2011-10-20 21:36:35 +00:00
|
|
|
url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName
|
2012-07-02 14:32:50 +00:00
|
|
|
remoteName = self.name
|
|
|
|
if self.remoteAlias:
|
|
|
|
remoteName = self.remoteAlias
|
|
|
|
return RemoteSpec(remoteName, url, self.reviewUrl)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-05-18 20:19:57 +00:00
|
|
|
class XmlManifest(object):
|
2008-10-21 14:00:00 +00:00
|
|
|
"""manages the repo configuration file"""
|
|
|
|
|
|
|
|
def __init__(self, repodir):
|
|
|
|
self.repodir = os.path.abspath(repodir)
|
|
|
|
self.topdir = os.path.dirname(self.repodir)
|
|
|
|
self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME)
|
|
|
|
self.globalConfig = GitConfig.ForUser()
|
|
|
|
|
|
|
|
self.repoProject = MetaProject(self, 'repo',
|
|
|
|
gitdir = os.path.join(repodir, 'repo/.git'),
|
|
|
|
worktree = os.path.join(repodir, 'repo'))
|
|
|
|
|
|
|
|
self.manifestProject = MetaProject(self, 'manifests',
|
2008-11-04 16:11:53 +00:00
|
|
|
gitdir = os.path.join(repodir, 'manifests.git'),
|
|
|
|
worktree = os.path.join(repodir, 'manifests'))
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
self._Unload()
|
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
def Override(self, name):
|
|
|
|
"""Use a different manifest, just for the current instantiation.
|
2008-10-21 14:00:00 +00:00
|
|
|
"""
|
|
|
|
path = os.path.join(self.manifestProject.worktree, name)
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
raise ManifestParseError('manifest %s not found' % name)
|
|
|
|
|
|
|
|
old = self.manifestFile
|
|
|
|
try:
|
|
|
|
self.manifestFile = path
|
|
|
|
self._Unload()
|
|
|
|
self._Load()
|
|
|
|
finally:
|
|
|
|
self.manifestFile = old
|
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
def Link(self, name):
|
|
|
|
"""Update the repo metadata to use a different manifest.
|
|
|
|
"""
|
|
|
|
self.Override(name)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
try:
|
|
|
|
if os.path.exists(self.manifestFile):
|
|
|
|
os.remove(self.manifestFile)
|
|
|
|
os.symlink('manifests/%s' % name, self.manifestFile)
|
2012-09-24 03:15:13 +00:00
|
|
|
except OSError:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise ManifestParseError('cannot link manifest %s' % name)
|
|
|
|
|
2009-03-05 18:32:38 +00:00
|
|
|
def _RemoteToXml(self, r, doc, root):
|
|
|
|
e = doc.createElement('remote')
|
|
|
|
root.appendChild(e)
|
|
|
|
e.setAttribute('name', r.name)
|
|
|
|
e.setAttribute('fetch', r.fetchUrl)
|
|
|
|
if r.reviewUrl is not None:
|
|
|
|
e.setAttribute('review', r.reviewUrl)
|
|
|
|
|
2012-09-29 03:21:57 +00:00
|
|
|
def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
|
2009-03-05 18:32:38 +00:00
|
|
|
"""Write the current manifest out to the given file descriptor.
|
|
|
|
"""
|
2012-03-29 03:15:45 +00:00
|
|
|
mp = self.manifestProject
|
|
|
|
|
|
|
|
groups = mp.config.GetString('manifest.groups')
|
2012-04-23 20:41:58 +00:00
|
|
|
if not groups:
|
2012-08-13 20:11:18 +00:00
|
|
|
groups = 'all'
|
2012-04-16 17:36:08 +00:00
|
|
|
groups = [x for x in re.split(r'[,\s]+', groups) if x]
|
2012-03-29 03:15:45 +00:00
|
|
|
|
2009-03-05 18:32:38 +00:00
|
|
|
doc = xml.dom.minidom.Document()
|
|
|
|
root = doc.createElement('manifest')
|
|
|
|
doc.appendChild(root)
|
|
|
|
|
2010-11-01 22:08:06 +00:00
|
|
|
# Save out the notice. There's a little bit of work here to give it the
|
|
|
|
# right whitespace, which assumes that the notice is automatically indented
|
|
|
|
# by 4 by minidom.
|
|
|
|
if self.notice:
|
|
|
|
notice_element = root.appendChild(doc.createElement('notice'))
|
|
|
|
notice_lines = self.notice.splitlines()
|
|
|
|
indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:]
|
|
|
|
notice_element.appendChild(doc.createTextNode(indented_notice))
|
|
|
|
|
2009-03-05 18:32:38 +00:00
|
|
|
d = self.default
|
|
|
|
sort_remotes = list(self.remotes.keys())
|
|
|
|
sort_remotes.sort()
|
|
|
|
|
|
|
|
for r in sort_remotes:
|
|
|
|
self._RemoteToXml(self.remotes[r], doc, root)
|
|
|
|
if self.remotes:
|
|
|
|
root.appendChild(doc.createTextNode(''))
|
|
|
|
|
|
|
|
have_default = False
|
|
|
|
e = doc.createElement('default')
|
|
|
|
if d.remote:
|
|
|
|
have_default = True
|
|
|
|
e.setAttribute('remote', d.remote.name)
|
2009-05-30 01:38:17 +00:00
|
|
|
if d.revisionExpr:
|
2009-03-05 18:32:38 +00:00
|
|
|
have_default = True
|
2009-05-30 01:38:17 +00:00
|
|
|
e.setAttribute('revision', d.revisionExpr)
|
2011-09-23 00:44:31 +00:00
|
|
|
if d.sync_j > 1:
|
|
|
|
have_default = True
|
|
|
|
e.setAttribute('sync-j', '%d' % d.sync_j)
|
2012-04-20 21:41:59 +00:00
|
|
|
if d.sync_c:
|
|
|
|
have_default = True
|
|
|
|
e.setAttribute('sync-c', 'true')
|
2009-03-05 18:32:38 +00:00
|
|
|
if have_default:
|
|
|
|
root.appendChild(e)
|
|
|
|
root.appendChild(doc.createTextNode(''))
|
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
if self._manifest_server:
|
|
|
|
e = doc.createElement('manifest-server')
|
|
|
|
e.setAttribute('url', self._manifest_server)
|
|
|
|
root.appendChild(e)
|
|
|
|
root.appendChild(doc.createTextNode(''))
|
|
|
|
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
def output_projects(parent, parent_node, projects):
|
|
|
|
for p in projects:
|
|
|
|
output_project(parent, parent_node, self.projects[p])
|
2012-03-29 03:15:45 +00:00
|
|
|
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
def output_project(parent, parent_node, p):
|
2012-03-29 03:15:45 +00:00
|
|
|
if not p.MatchesGroups(groups):
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
name = p.name
|
|
|
|
relpath = p.relpath
|
|
|
|
if parent:
|
|
|
|
name = self._UnjoinName(parent.name, name)
|
|
|
|
relpath = self._UnjoinRelpath(parent.relpath, relpath)
|
2012-03-29 03:15:45 +00:00
|
|
|
|
2009-03-05 18:32:38 +00:00
|
|
|
e = doc.createElement('project')
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
parent_node.appendChild(e)
|
|
|
|
e.setAttribute('name', name)
|
|
|
|
if relpath != name:
|
|
|
|
e.setAttribute('path', relpath)
|
2009-03-05 18:32:38 +00:00
|
|
|
if not d.remote or p.remote.name != d.remote.name:
|
|
|
|
e.setAttribute('remote', p.remote.name)
|
|
|
|
if peg_rev:
|
|
|
|
if self.IsMirror:
|
2012-09-29 03:21:57 +00:00
|
|
|
value = p.bare_git.rev_parse(p.revisionExpr + '^0')
|
2009-03-05 18:32:38 +00:00
|
|
|
else:
|
2012-09-29 03:21:57 +00:00
|
|
|
value = p.work_git.rev_parse(HEAD + '^0')
|
|
|
|
e.setAttribute('revision', value)
|
|
|
|
if peg_rev_upstream and value != p.revisionExpr:
|
|
|
|
# Only save the origin if the origin is not a sha1, and the default
|
|
|
|
# isn't our value, and the if the default doesn't already have that
|
|
|
|
# covered.
|
|
|
|
e.setAttribute('upstream', p.revisionExpr)
|
2009-05-30 01:38:17 +00:00
|
|
|
elif not d.revisionExpr or p.revisionExpr != d.revisionExpr:
|
|
|
|
e.setAttribute('revision', p.revisionExpr)
|
2009-03-05 18:32:38 +00:00
|
|
|
|
|
|
|
for c in p.copyfiles:
|
|
|
|
ce = doc.createElement('copyfile')
|
|
|
|
ce.setAttribute('src', c.src)
|
|
|
|
ce.setAttribute('dest', c.dest)
|
|
|
|
e.appendChild(ce)
|
|
|
|
|
2012-08-13 20:11:18 +00:00
|
|
|
default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
|
2012-08-06 21:52:29 +00:00
|
|
|
egroups = [g for g in p.groups if g not in default_groups]
|
2012-04-16 17:36:08 +00:00
|
|
|
if egroups:
|
|
|
|
e.setAttribute('groups', ','.join(egroups))
|
2012-03-29 03:15:45 +00:00
|
|
|
|
2012-04-12 20:04:13 +00:00
|
|
|
for a in p.annotations:
|
|
|
|
if a.keep == "true":
|
|
|
|
ae = doc.createElement('annotation')
|
|
|
|
ae.setAttribute('name', a.name)
|
|
|
|
ae.setAttribute('value', a.value)
|
|
|
|
e.appendChild(ae)
|
|
|
|
|
2012-04-20 21:41:59 +00:00
|
|
|
if p.sync_c:
|
|
|
|
e.setAttribute('sync-c', 'true')
|
|
|
|
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
if p.subprojects:
|
|
|
|
sort_projects = [subp.name for subp in p.subprojects]
|
|
|
|
sort_projects.sort()
|
|
|
|
output_projects(p, e, sort_projects)
|
|
|
|
|
|
|
|
sort_projects = [key for key in self.projects.keys()
|
|
|
|
if not self.projects[key].parent]
|
|
|
|
sort_projects.sort()
|
|
|
|
output_projects(None, root, sort_projects)
|
|
|
|
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
if self._repo_hooks_project:
|
|
|
|
root.appendChild(doc.createTextNode(''))
|
|
|
|
e = doc.createElement('repo-hooks')
|
|
|
|
e.setAttribute('in-project', self._repo_hooks_project.name)
|
|
|
|
e.setAttribute('enabled-list',
|
|
|
|
' '.join(self._repo_hooks_project.enabled_repo_hooks))
|
|
|
|
root.appendChild(e)
|
|
|
|
|
2009-03-05 18:32:38 +00:00
|
|
|
doc.writexml(fd, '', ' ', '\n', 'UTF-8')
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
@property
|
|
|
|
def projects(self):
|
|
|
|
self._Load()
|
|
|
|
return self._projects
|
|
|
|
|
|
|
|
@property
|
|
|
|
def remotes(self):
|
|
|
|
self._Load()
|
|
|
|
return self._remotes
|
|
|
|
|
|
|
|
@property
|
|
|
|
def default(self):
|
|
|
|
self._Load()
|
|
|
|
return self._default
|
|
|
|
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
@property
|
|
|
|
def repo_hooks_project(self):
|
|
|
|
self._Load()
|
|
|
|
return self._repo_hooks_project
|
|
|
|
|
2010-11-01 22:08:06 +00:00
|
|
|
@property
|
|
|
|
def notice(self):
|
|
|
|
self._Load()
|
|
|
|
return self._notice
|
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
@property
|
|
|
|
def manifest_server(self):
|
|
|
|
self._Load()
|
2011-11-30 21:41:02 +00:00
|
|
|
return self._manifest_server
|
2010-04-06 17:40:01 +00:00
|
|
|
|
2008-11-04 15:37:10 +00:00
|
|
|
@property
|
|
|
|
def IsMirror(self):
|
|
|
|
return self.manifestProject.config.GetBoolean('repo.mirror')
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _Unload(self):
|
|
|
|
self._loaded = False
|
|
|
|
self._projects = {}
|
|
|
|
self._remotes = {}
|
|
|
|
self._default = None
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
self._repo_hooks_project = None
|
2010-11-01 22:08:06 +00:00
|
|
|
self._notice = None
|
2008-10-21 14:00:00 +00:00
|
|
|
self.branch = None
|
2010-04-06 17:40:01 +00:00
|
|
|
self._manifest_server = None
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _Load(self):
|
|
|
|
if not self._loaded:
|
2008-11-04 16:22:07 +00:00
|
|
|
m = self.manifestProject
|
|
|
|
b = m.GetBranch(m.CurrentBranch).merge
|
2009-06-25 23:47:30 +00:00
|
|
|
if b is not None and b.startswith(R_HEADS):
|
2008-11-04 16:22:07 +00:00
|
|
|
b = b[len(R_HEADS):]
|
|
|
|
self.branch = b
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
nodes = []
|
2012-06-08 03:05:35 +00:00
|
|
|
nodes.append(self._ParseManifestXml(self.manifestFile,
|
|
|
|
self.manifestProject.worktree))
|
2008-10-23 23:19:27 +00:00
|
|
|
|
|
|
|
local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME)
|
|
|
|
if os.path.exists(local):
|
2012-06-08 03:05:35 +00:00
|
|
|
nodes.append(self._ParseManifestXml(local, self.repodir))
|
2012-04-21 07:33:54 +00:00
|
|
|
|
|
|
|
self._ParseManifest(nodes)
|
2008-10-23 23:19:27 +00:00
|
|
|
|
2008-11-04 15:37:10 +00:00
|
|
|
if self.IsMirror:
|
|
|
|
self._AddMetaProjectMirror(self.repoProject)
|
|
|
|
self._AddMetaProjectMirror(self.manifestProject)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
self._loaded = True
|
|
|
|
|
2012-06-08 03:05:35 +00:00
|
|
|
def _ParseManifestXml(self, path, include_root):
|
2011-04-28 12:04:41 +00:00
|
|
|
root = xml.dom.minidom.parse(path)
|
2008-10-21 14:00:00 +00:00
|
|
|
if not root or not root.childNodes:
|
2011-04-28 12:04:41 +00:00
|
|
|
raise ManifestParseError("no root node in %s" % (path,))
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-08-26 17:25:59 +00:00
|
|
|
for manifest in root.childNodes:
|
|
|
|
if manifest.nodeName == 'manifest':
|
|
|
|
break
|
|
|
|
else:
|
2011-04-28 12:04:41 +00:00
|
|
|
raise ManifestParseError("no <manifest> in %s" % (path,))
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
nodes = []
|
2012-10-22 03:50:15 +00:00
|
|
|
for node in manifest.childNodes: # pylint:disable=W0631
|
2012-10-11 07:44:48 +00:00
|
|
|
# We only get here if manifest is initialised
|
2011-04-28 12:04:41 +00:00
|
|
|
if node.nodeName == 'include':
|
|
|
|
name = self._reqatt(node, 'name')
|
2012-06-08 03:05:35 +00:00
|
|
|
fp = os.path.join(include_root, name)
|
2011-04-28 12:04:41 +00:00
|
|
|
if not os.path.isfile(fp):
|
|
|
|
raise ManifestParseError, \
|
|
|
|
"include %s doesn't exist or isn't a file" % \
|
|
|
|
(name,)
|
|
|
|
try:
|
2012-06-08 03:05:35 +00:00
|
|
|
nodes.extend(self._ParseManifestXml(fp, include_root))
|
2011-04-28 12:04:41 +00:00
|
|
|
# should isolate this to the exact exception, but that's
|
|
|
|
# tricky. actual parsing implementation may vary.
|
|
|
|
except (KeyboardInterrupt, RuntimeError, SystemExit):
|
|
|
|
raise
|
|
|
|
except Exception, e:
|
|
|
|
raise ManifestParseError(
|
|
|
|
"failed parsing included manifest %s: %s", (name, e))
|
2012-04-21 07:33:54 +00:00
|
|
|
else:
|
|
|
|
nodes.append(node)
|
|
|
|
return nodes
|
2011-04-28 12:04:41 +00:00
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
def _ParseManifest(self, node_list):
|
|
|
|
for node in itertools.chain(*node_list):
|
2008-10-21 14:00:00 +00:00
|
|
|
if node.nodeName == 'remote':
|
|
|
|
remote = self._ParseRemote(node)
|
|
|
|
if self._remotes.get(remote.name):
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
raise ManifestParseError(
|
|
|
|
'duplicate remote %s in %s' %
|
|
|
|
(remote.name, self.manifestFile))
|
2008-10-21 14:00:00 +00:00
|
|
|
self._remotes[remote.name] = remote
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
for node in itertools.chain(*node_list):
|
2008-10-21 14:00:00 +00:00
|
|
|
if node.nodeName == 'default':
|
|
|
|
if self._default is not None:
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
raise ManifestParseError(
|
|
|
|
'duplicate default in %s' %
|
|
|
|
(self.manifestFile))
|
2008-10-21 14:00:00 +00:00
|
|
|
self._default = self._ParseDefault(node)
|
|
|
|
if self._default is None:
|
|
|
|
self._default = _Default()
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
for node in itertools.chain(*node_list):
|
2010-11-01 22:08:06 +00:00
|
|
|
if node.nodeName == 'notice':
|
|
|
|
if self._notice is not None:
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
raise ManifestParseError(
|
|
|
|
'duplicate notice in %s' %
|
|
|
|
(self.manifestFile))
|
2010-11-01 22:08:06 +00:00
|
|
|
self._notice = self._ParseNotice(node)
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
for node in itertools.chain(*node_list):
|
2010-04-06 17:40:01 +00:00
|
|
|
if node.nodeName == 'manifest-server':
|
|
|
|
url = self._reqatt(node, 'url')
|
|
|
|
if self._manifest_server is not None:
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
raise ManifestParseError(
|
|
|
|
'duplicate manifest-server in %s' %
|
|
|
|
(self.manifestFile))
|
2010-04-06 17:40:01 +00:00
|
|
|
self._manifest_server = url
|
|
|
|
|
2012-04-21 07:33:54 +00:00
|
|
|
for node in itertools.chain(*node_list):
|
2008-10-21 14:00:00 +00:00
|
|
|
if node.nodeName == 'project':
|
|
|
|
project = self._ParseProject(node)
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
def recursively_add_projects(project):
|
|
|
|
if self._projects.get(project.name):
|
|
|
|
raise ManifestParseError(
|
|
|
|
'duplicate project %s in %s' %
|
|
|
|
(project.name, self.manifestFile))
|
|
|
|
self._projects[project.name] = project
|
|
|
|
for subproject in project.subprojects:
|
|
|
|
recursively_add_projects(subproject)
|
|
|
|
recursively_add_projects(project)
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
if node.nodeName == 'repo-hooks':
|
|
|
|
# Get the name of the project and the (space-separated) list of enabled.
|
|
|
|
repo_hooks_project = self._reqatt(node, 'in-project')
|
|
|
|
enabled_repo_hooks = self._reqatt(node, 'enabled-list').split()
|
|
|
|
|
|
|
|
# Only one project can be the hooks project
|
|
|
|
if self._repo_hooks_project is not None:
|
|
|
|
raise ManifestParseError(
|
|
|
|
'duplicate repo-hooks in %s' %
|
|
|
|
(self.manifestFile))
|
|
|
|
|
|
|
|
# Store a reference to the Project.
|
|
|
|
try:
|
|
|
|
self._repo_hooks_project = self._projects[repo_hooks_project]
|
|
|
|
except KeyError:
|
|
|
|
raise ManifestParseError(
|
|
|
|
'project %s not found for repo-hooks' %
|
|
|
|
(repo_hooks_project))
|
|
|
|
|
|
|
|
# Store the enabled hooks in the Project object.
|
|
|
|
self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
|
2012-04-21 07:33:54 +00:00
|
|
|
if node.nodeName == 'remove-project':
|
|
|
|
name = self._reqatt(node, 'name')
|
|
|
|
try:
|
|
|
|
del self._projects[name]
|
|
|
|
except KeyError:
|
|
|
|
raise ManifestParseError(
|
|
|
|
'project %s not found' %
|
|
|
|
(name))
|
|
|
|
|
|
|
|
# If the manifest removes the hooks project, treat it as if it deleted
|
|
|
|
# the repo-hooks element too.
|
|
|
|
if self._repo_hooks_project and (self._repo_hooks_project.name == name):
|
|
|
|
self._repo_hooks_project = None
|
|
|
|
|
Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project. The name of the hooks project is provided
in the manifest.xml. The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).
Before running any hook, we will prompt the user to make sure that it
is OK. A user can deny running the hook, allow once, or allow
"forever" (until hooks change). This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down. Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).
When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run. This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future. During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.
The upload command has two options that control hook behavior:
- no-verify=False, verify=False (DEFAULT):
If stdout is a tty, can prompt about running upload hooks if needed.
If user denies running hooks, the upload is cancelled. If stdout is
not a tty and we would need to prompt about upload hooks, upload is
cancelled.
- no-verify=False, verify=True:
Always run upload hooks with no prompt.
- no-verify=True, verify=False:
Never run upload hooks, but upload anyway (AKA bypass hooks).
- no-verify=True, verify=True:
Invalid
Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
<repo-hooks in-project="hooks" enabled-list="pre-upload" />
Sample main() function in pre-upload.py in hooks directory:
def main(project_list, **kwargs):
print ('These projects will be uploaded: %s' %
', '.join(project_list))
print ('I am being a good boy and ignoring anything in kwargs\n'
'that I don\'t understand.')
print 'I fail 50% of the time. How flaky.'
if random.random() <= .5:
raise Exception('Pre-upload hook failed. Have a nice day.')
Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-04 19:54:18 +00:00
|
|
|
|
2008-11-04 15:37:10 +00:00
|
|
|
def _AddMetaProjectMirror(self, m):
|
|
|
|
name = None
|
|
|
|
m_url = m.GetRemote(m.remote.name).url
|
|
|
|
if m_url.endswith('/.git'):
|
|
|
|
raise ManifestParseError, 'refusing to mirror %s' % m_url
|
|
|
|
|
|
|
|
if self._default and self._default.remote:
|
2011-10-20 17:45:47 +00:00
|
|
|
url = self._default.remote.resolvedFetchUrl
|
2008-11-04 15:37:10 +00:00
|
|
|
if not url.endswith('/'):
|
|
|
|
url += '/'
|
|
|
|
if m_url.startswith(url):
|
|
|
|
remote = self._default.remote
|
|
|
|
name = m_url[len(url):]
|
|
|
|
|
|
|
|
if name is None:
|
|
|
|
s = m_url.rindex('/') + 1
|
2011-09-26 23:34:01 +00:00
|
|
|
manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
|
2012-08-02 18:46:22 +00:00
|
|
|
remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl)
|
2008-11-04 15:37:10 +00:00
|
|
|
name = m_url[s:]
|
|
|
|
|
|
|
|
if name.endswith('.git'):
|
|
|
|
name = name[:-4]
|
|
|
|
|
|
|
|
if name not in self._projects:
|
|
|
|
m.PreSync()
|
|
|
|
gitdir = os.path.join(self.topdir, '%s.git' % name)
|
|
|
|
project = Project(manifest = self,
|
|
|
|
name = name,
|
2009-05-19 21:58:02 +00:00
|
|
|
remote = remote.ToRemoteSpec(name),
|
2008-11-04 15:37:10 +00:00
|
|
|
gitdir = gitdir,
|
|
|
|
worktree = None,
|
|
|
|
relpath = None,
|
2009-05-30 01:38:17 +00:00
|
|
|
revisionExpr = m.revisionExpr,
|
|
|
|
revisionId = None)
|
2008-11-04 15:37:10 +00:00
|
|
|
self._projects[project.name] = project
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _ParseRemote(self, node):
|
|
|
|
"""
|
|
|
|
reads a <remote> element from the manifest file
|
|
|
|
"""
|
|
|
|
name = self._reqatt(node, 'name')
|
2012-07-02 14:32:50 +00:00
|
|
|
alias = node.getAttribute('alias')
|
|
|
|
if alias == '':
|
|
|
|
alias = None
|
2008-10-21 14:00:00 +00:00
|
|
|
fetch = self._reqatt(node, 'fetch')
|
|
|
|
review = node.getAttribute('review')
|
2008-11-06 18:25:35 +00:00
|
|
|
if review == '':
|
|
|
|
review = None
|
2011-09-26 23:34:01 +00:00
|
|
|
manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
|
2012-07-02 14:32:50 +00:00
|
|
|
return _XmlRemote(name, alias, fetch, manifestUrl, review)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _ParseDefault(self, node):
|
|
|
|
"""
|
|
|
|
reads a <default> element from the manifest file
|
|
|
|
"""
|
|
|
|
d = _Default()
|
|
|
|
d.remote = self._get_remote(node)
|
2009-05-30 01:38:17 +00:00
|
|
|
d.revisionExpr = node.getAttribute('revision')
|
|
|
|
if d.revisionExpr == '':
|
|
|
|
d.revisionExpr = None
|
2012-04-20 21:41:59 +00:00
|
|
|
|
2011-09-23 00:44:31 +00:00
|
|
|
sync_j = node.getAttribute('sync-j')
|
|
|
|
if sync_j == '' or sync_j is None:
|
|
|
|
d.sync_j = 1
|
|
|
|
else:
|
|
|
|
d.sync_j = int(sync_j)
|
2012-04-20 21:41:59 +00:00
|
|
|
|
|
|
|
sync_c = node.getAttribute('sync-c')
|
|
|
|
if not sync_c:
|
|
|
|
d.sync_c = False
|
|
|
|
else:
|
|
|
|
d.sync_c = sync_c.lower() in ("yes", "true", "1")
|
2008-10-21 14:00:00 +00:00
|
|
|
return d
|
|
|
|
|
2010-11-01 22:08:06 +00:00
|
|
|
def _ParseNotice(self, node):
|
|
|
|
"""
|
|
|
|
reads a <notice> element from the manifest file
|
|
|
|
|
|
|
|
The <notice> element is distinct from other tags in the XML in that the
|
|
|
|
data is conveyed between the start and end tag (it's not an empty-element
|
|
|
|
tag).
|
|
|
|
|
|
|
|
The white space (carriage returns, indentation) for the notice element is
|
|
|
|
relevant and is parsed in a way that is based on how python docstrings work.
|
|
|
|
In fact, the code is remarkably similar to here:
|
|
|
|
http://www.python.org/dev/peps/pep-0257/
|
|
|
|
"""
|
|
|
|
# Get the data out of the node...
|
|
|
|
notice = node.childNodes[0].data
|
|
|
|
|
|
|
|
# Figure out minimum indentation, skipping the first line (the same line
|
|
|
|
# as the <notice> tag)...
|
|
|
|
minIndent = sys.maxint
|
|
|
|
lines = notice.splitlines()
|
|
|
|
for line in lines[1:]:
|
|
|
|
lstrippedLine = line.lstrip()
|
|
|
|
if lstrippedLine:
|
|
|
|
indent = len(line) - len(lstrippedLine)
|
|
|
|
minIndent = min(indent, minIndent)
|
|
|
|
|
|
|
|
# Strip leading / trailing blank lines and also indentation.
|
|
|
|
cleanLines = [lines[0].strip()]
|
|
|
|
for line in lines[1:]:
|
|
|
|
cleanLines.append(line[minIndent:].rstrip())
|
|
|
|
|
|
|
|
# Clear completely blank lines from front and back...
|
|
|
|
while cleanLines and not cleanLines[0]:
|
|
|
|
del cleanLines[0]
|
|
|
|
while cleanLines and not cleanLines[-1]:
|
|
|
|
del cleanLines[-1]
|
|
|
|
|
|
|
|
return '\n'.join(cleanLines)
|
|
|
|
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
def _JoinName(self, parent_name, name):
|
|
|
|
return os.path.join(parent_name, name)
|
|
|
|
|
|
|
|
def _UnjoinName(self, parent_name, name):
|
|
|
|
return os.path.relpath(name, parent_name)
|
|
|
|
|
|
|
|
def _ParseProject(self, node, parent = None):
|
2008-10-21 14:00:00 +00:00
|
|
|
"""
|
|
|
|
reads a <project> element from the manifest file
|
2010-04-06 17:40:01 +00:00
|
|
|
"""
|
2008-10-21 14:00:00 +00:00
|
|
|
name = self._reqatt(node, 'name')
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
if parent:
|
|
|
|
name = self._JoinName(parent.name, name)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
remote = self._get_remote(node)
|
|
|
|
if remote is None:
|
|
|
|
remote = self._default.remote
|
|
|
|
if remote is None:
|
|
|
|
raise ManifestParseError, \
|
|
|
|
"no remote for project %s within %s" % \
|
|
|
|
(name, self.manifestFile)
|
|
|
|
|
2009-05-30 01:38:17 +00:00
|
|
|
revisionExpr = node.getAttribute('revision')
|
|
|
|
if not revisionExpr:
|
|
|
|
revisionExpr = self._default.revisionExpr
|
|
|
|
if not revisionExpr:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise ManifestParseError, \
|
|
|
|
"no revision for project %s within %s" % \
|
|
|
|
(name, self.manifestFile)
|
|
|
|
|
|
|
|
path = node.getAttribute('path')
|
|
|
|
if not path:
|
|
|
|
path = name
|
|
|
|
if path.startswith('/'):
|
|
|
|
raise ManifestParseError, \
|
|
|
|
"project %s path cannot be absolute in %s" % \
|
|
|
|
(name, self.manifestFile)
|
|
|
|
|
2012-02-28 19:53:24 +00:00
|
|
|
rebase = node.getAttribute('rebase')
|
|
|
|
if not rebase:
|
|
|
|
rebase = True
|
|
|
|
else:
|
|
|
|
rebase = rebase.lower() in ("yes", "true", "1")
|
|
|
|
|
2012-04-20 21:41:59 +00:00
|
|
|
sync_c = node.getAttribute('sync-c')
|
|
|
|
if not sync_c:
|
|
|
|
sync_c = False
|
|
|
|
else:
|
|
|
|
sync_c = sync_c.lower() in ("yes", "true", "1")
|
|
|
|
|
2012-09-29 03:21:57 +00:00
|
|
|
upstream = node.getAttribute('upstream')
|
|
|
|
|
2012-04-16 17:36:08 +00:00
|
|
|
groups = ''
|
|
|
|
if node.hasAttribute('groups'):
|
|
|
|
groups = node.getAttribute('groups')
|
|
|
|
groups = [x for x in re.split('[,\s]+', groups) if x]
|
2012-06-15 09:24:20 +00:00
|
|
|
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
if parent is None:
|
|
|
|
relpath, worktree, gitdir = self.GetProjectPaths(name, path)
|
2008-11-04 15:37:10 +00:00
|
|
|
else:
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
relpath, worktree, gitdir = self.GetSubprojectPaths(parent, path)
|
|
|
|
|
|
|
|
default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath]
|
|
|
|
groups.extend(set(default_groups).difference(groups))
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
project = Project(manifest = self,
|
|
|
|
name = name,
|
2009-05-19 21:58:02 +00:00
|
|
|
remote = remote.ToRemoteSpec(name),
|
2008-10-21 14:00:00 +00:00
|
|
|
gitdir = gitdir,
|
|
|
|
worktree = worktree,
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
relpath = relpath,
|
2009-05-30 01:38:17 +00:00
|
|
|
revisionExpr = revisionExpr,
|
2012-02-28 19:53:24 +00:00
|
|
|
revisionId = None,
|
2012-03-29 03:15:45 +00:00
|
|
|
rebase = rebase,
|
2012-04-20 21:41:59 +00:00
|
|
|
groups = groups,
|
2012-09-29 03:21:57 +00:00
|
|
|
sync_c = sync_c,
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
upstream = upstream,
|
|
|
|
parent = parent)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
for n in node.childNodes:
|
2009-05-19 20:00:29 +00:00
|
|
|
if n.nodeName == 'copyfile':
|
2008-10-21 14:00:00 +00:00
|
|
|
self._ParseCopyFile(project, n)
|
2012-04-12 20:04:13 +00:00
|
|
|
if n.nodeName == 'annotation':
|
|
|
|
self._ParseAnnotation(project, n)
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
if n.nodeName == 'project':
|
|
|
|
project.subprojects.append(self._ParseProject(n, parent = project))
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
return project
|
|
|
|
|
Represent git-submodule as nested projects
We need a representation of git-submodule in repo; otherwise repo will
not sync submodules, and leave workspace in a broken state. Of course
this will not be a problem if all projects are owned by the owner of the
manifest file, who may simply choose not to use git-submodule in all
projects. However, this is not possible in practice because manifest
file owner is unlikely to own all upstream projects.
As git submodules are simply git repositories, it is natural to treat
them as plain repo projects that live inside a repo project. That is,
we could use recursively declared projects to denote the is-submodule
relation of git repositories.
The behavior of repo remains the same to projects that do not have a
sub-project within. As for parent projects, repo fetches them and their
sub-projects as normal projects, and then checks out subprojects at the
commit specified in parent's commit object. The sub-project is fetched
at a path relative to parent project's working directory; so the path
specified in manifest file should match that of .gitmodules file.
If a submodule is not registered in repo manifest, repo will derive its
properties from itself and its parent project, which might not always be
correct. In such cases, the subproject is called a derived subproject.
To a user, a sub-project is merely a git-submodule; so all tips of
working with a git-submodule apply here, too. For example, you should
not run `repo sync` in a parent repository if its submodule is dirty.
Change-Id: I541e9e2ac1a70304272dbe09724572aa1004eb5c
2012-01-11 03:28:42 +00:00
|
|
|
def GetProjectPaths(self, name, path):
|
|
|
|
relpath = path
|
|
|
|
if self.IsMirror:
|
|
|
|
worktree = None
|
|
|
|
gitdir = os.path.join(self.topdir, '%s.git' % name)
|
|
|
|
else:
|
|
|
|
worktree = os.path.join(self.topdir, path).replace('\\', '/')
|
|
|
|
gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path)
|
|
|
|
return relpath, worktree, gitdir
|
|
|
|
|
|
|
|
def GetSubprojectName(self, parent, submodule_path):
|
|
|
|
return os.path.join(parent.name, submodule_path)
|
|
|
|
|
|
|
|
def _JoinRelpath(self, parent_relpath, relpath):
|
|
|
|
return os.path.join(parent_relpath, relpath)
|
|
|
|
|
|
|
|
def _UnjoinRelpath(self, parent_relpath, relpath):
|
|
|
|
return os.path.relpath(relpath, parent_relpath)
|
|
|
|
|
|
|
|
def GetSubprojectPaths(self, parent, path):
|
|
|
|
relpath = self._JoinRelpath(parent.relpath, path)
|
|
|
|
gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path)
|
|
|
|
if self.IsMirror:
|
|
|
|
worktree = None
|
|
|
|
else:
|
|
|
|
worktree = os.path.join(parent.worktree, path).replace('\\', '/')
|
|
|
|
return relpath, worktree, gitdir
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _ParseCopyFile(self, project, node):
|
|
|
|
src = self._reqatt(node, 'src')
|
|
|
|
dest = self._reqatt(node, 'dest')
|
2008-11-04 15:37:10 +00:00
|
|
|
if not self.IsMirror:
|
|
|
|
# src is project relative;
|
|
|
|
# dest is relative to the top of the tree
|
2009-03-05 18:32:38 +00:00
|
|
|
project.AddCopyFile(src, dest, os.path.join(self.topdir, dest))
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-04-12 20:04:13 +00:00
|
|
|
def _ParseAnnotation(self, project, node):
|
|
|
|
name = self._reqatt(node, 'name')
|
|
|
|
value = self._reqatt(node, 'value')
|
|
|
|
try:
|
|
|
|
keep = self._reqatt(node, 'keep').lower()
|
|
|
|
except ManifestParseError:
|
|
|
|
keep = "true"
|
|
|
|
if keep != "true" and keep != "false":
|
|
|
|
raise ManifestParseError, "optional \"keep\" attribute must be \"true\" or \"false\""
|
|
|
|
project.AddAnnotation(name, value, keep)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _get_remote(self, node):
|
|
|
|
name = node.getAttribute('remote')
|
|
|
|
if not name:
|
|
|
|
return None
|
|
|
|
|
|
|
|
v = self._remotes.get(name)
|
|
|
|
if not v:
|
|
|
|
raise ManifestParseError, \
|
|
|
|
"remote %s not defined in %s" % \
|
|
|
|
(name, self.manifestFile)
|
|
|
|
return v
|
|
|
|
|
|
|
|
def _reqatt(self, node, attname):
|
|
|
|
"""
|
|
|
|
reads a required attribute from the node.
|
|
|
|
"""
|
|
|
|
v = node.getAttribute(attname)
|
|
|
|
if not v:
|
|
|
|
raise ManifestParseError, \
|
|
|
|
"no %s in <%s> within %s" % \
|
|
|
|
(attname, node.nodeName, self.manifestFile)
|
|
|
|
return v
|