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.
|
|
|
|
|
2021-03-01 05:56:38 +00:00
|
|
|
import multiprocessing
|
2008-10-21 14:00:00 +00:00
|
|
|
import os
|
|
|
|
import optparse
|
2012-04-16 18:02:21 +00:00
|
|
|
import platform
|
2012-03-29 03:15:45 +00:00
|
|
|
import re
|
2008-10-21 14:00:00 +00:00
|
|
|
import sys
|
|
|
|
|
2017-04-05 07:02:59 +00:00
|
|
|
from event_log import EventLog
|
2008-10-21 14:00:00 +00:00
|
|
|
from error import NoSuchProjectError
|
2012-03-29 03:15:45 +00:00
|
|
|
from error import InvalidProjectGroupsError
|
2021-03-01 05:56:38 +00:00
|
|
|
import progress
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-11-16 00:33:39 +00:00
|
|
|
|
2021-02-16 06:45:39 +00:00
|
|
|
# Number of projects to submit to a single worker process at a time.
|
|
|
|
# This number represents a tradeoff between the overhead of IPC and finer
|
|
|
|
# grained opportunity for parallelism. This particular value was chosen by
|
|
|
|
# iterating through powers of two until the overall performance no longer
|
|
|
|
# improved. The performance of this batch size is not a function of the
|
|
|
|
# number of cores on the system.
|
|
|
|
WORKER_BATCH_SIZE = 32
|
|
|
|
|
|
|
|
|
2021-02-16 06:43:31 +00:00
|
|
|
# How many jobs to run in parallel by default? This assumes the jobs are
|
|
|
|
# largely I/O bound and do not hit the network.
|
|
|
|
DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8)
|
|
|
|
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class Command(object):
|
|
|
|
"""Base class for any command line action in repo.
|
|
|
|
"""
|
|
|
|
|
2017-04-05 07:02:59 +00:00
|
|
|
event_log = EventLog()
|
2008-10-21 14:00:00 +00:00
|
|
|
manifest = None
|
|
|
|
_optparse = None
|
|
|
|
|
2021-06-14 20:05:19 +00:00
|
|
|
# Whether this command is a "common" one, i.e. whether the user would commonly
|
|
|
|
# use it or it's a more uncommon command. This is used by the help command to
|
|
|
|
# show short-vs-full summaries.
|
|
|
|
COMMON = False
|
|
|
|
|
2021-02-16 06:43:31 +00:00
|
|
|
# Whether this command supports running in parallel. If greater than 0,
|
|
|
|
# it is the number of parallel jobs to default to.
|
|
|
|
PARALLEL_JOBS = None
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
def WantPager(self, _opt):
|
2009-04-18 20:49:13 +00:00
|
|
|
return False
|
|
|
|
|
2012-11-16 00:33:39 +00:00
|
|
|
def ReadEnvironmentOptions(self, opts):
|
|
|
|
""" Set options from environment variables. """
|
|
|
|
|
|
|
|
env_options = self._RegisteredEnvironmentOptions()
|
|
|
|
|
|
|
|
for env_key, opt_key in env_options.items():
|
|
|
|
# Get the user-set option value if any
|
|
|
|
opt_value = getattr(opts, opt_key)
|
|
|
|
|
|
|
|
# If the value is set, it means the user has passed it as a command
|
|
|
|
# line option, and we should use that. Otherwise we can try to set it
|
|
|
|
# with the value from the corresponding environment variable.
|
|
|
|
if opt_value is not None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
env_value = os.environ.get(env_key)
|
|
|
|
if env_value is not None:
|
|
|
|
setattr(opts, opt_key, env_value)
|
|
|
|
|
|
|
|
return opts
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
@property
|
|
|
|
def OptionParser(self):
|
|
|
|
if self._optparse is None:
|
|
|
|
try:
|
|
|
|
me = 'repo %s' % self.NAME
|
|
|
|
usage = self.helpUsage.strip().replace('%prog', me)
|
|
|
|
except AttributeError:
|
|
|
|
usage = 'repo %s' % self.NAME
|
2020-02-19 06:20:18 +00:00
|
|
|
epilog = 'Run `repo help %s` to view the detailed manual.' % self.NAME
|
|
|
|
self._optparse = optparse.OptionParser(usage=usage, epilog=epilog)
|
2021-04-13 18:57:40 +00:00
|
|
|
self._CommonOptions(self._optparse)
|
2008-10-21 14:00:00 +00:00
|
|
|
self._Options(self._optparse)
|
|
|
|
return self._optparse
|
|
|
|
|
2021-04-13 18:57:40 +00:00
|
|
|
def _CommonOptions(self, p, opt_v=True):
|
|
|
|
"""Initialize the option parser with common options.
|
|
|
|
|
|
|
|
These will show up for *all* subcommands, so use sparingly.
|
|
|
|
NB: Keep in sync with repo:InitParser().
|
2008-10-21 14:00:00 +00:00
|
|
|
"""
|
2021-04-13 18:57:40 +00:00
|
|
|
g = p.add_option_group('Logging options')
|
|
|
|
opts = ['-v'] if opt_v else []
|
|
|
|
g.add_option(*opts, '--verbose',
|
|
|
|
dest='output_mode', action='store_true',
|
|
|
|
help='show all output')
|
|
|
|
g.add_option('-q', '--quiet',
|
|
|
|
dest='output_mode', action='store_false',
|
|
|
|
help='only show errors')
|
|
|
|
|
2021-02-16 06:43:31 +00:00
|
|
|
if self.PARALLEL_JOBS is not None:
|
|
|
|
p.add_option(
|
|
|
|
'-j', '--jobs',
|
|
|
|
type=int, default=self.PARALLEL_JOBS,
|
|
|
|
help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2021-04-13 18:57:40 +00:00
|
|
|
def _Options(self, p):
|
|
|
|
"""Initialize the option parser with subcommand-specific options."""
|
|
|
|
|
2012-11-16 00:33:39 +00:00
|
|
|
def _RegisteredEnvironmentOptions(self):
|
|
|
|
"""Get options that can be set from environment variables.
|
|
|
|
|
|
|
|
Return a dictionary mapping environment variable name
|
|
|
|
to option key name that it can override.
|
|
|
|
|
|
|
|
Example: {'REPO_MY_OPTION': 'my_option'}
|
|
|
|
|
|
|
|
Will allow the option with key value 'my_option' to be set
|
|
|
|
from the value in the environment variable named 'REPO_MY_OPTION'.
|
|
|
|
|
|
|
|
Note: This does not work properly for options that are explicitly
|
|
|
|
set to None by the user, or options that are defined with a
|
|
|
|
default value other than None.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return {}
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def Usage(self):
|
|
|
|
"""Display usage and terminate.
|
|
|
|
"""
|
|
|
|
self.OptionParser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-04-13 18:57:40 +00:00
|
|
|
def CommonValidateOptions(self, opt, args):
|
|
|
|
"""Validate common options."""
|
|
|
|
opt.quiet = opt.output_mode is False
|
|
|
|
opt.verbose = opt.output_mode is True
|
|
|
|
|
2019-08-27 05:10:59 +00:00
|
|
|
def ValidateOptions(self, opt, args):
|
|
|
|
"""Validate the user options & arguments before executing.
|
|
|
|
|
|
|
|
This is meant to help break the code up into logical steps. Some tips:
|
|
|
|
* Use self.OptionParser.error to display CLI related errors.
|
|
|
|
* Adjust opt member defaults as makes sense.
|
|
|
|
* Adjust the args list, but do so inplace so the caller sees updates.
|
|
|
|
* Try to avoid updating self state. Leave that to Execute.
|
|
|
|
"""
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def Execute(self, opt, args):
|
|
|
|
"""Perform the action, after option parsing is complete.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
2012-04-16 17:36:08 +00:00
|
|
|
|
2021-03-01 05:56:38 +00:00
|
|
|
@staticmethod
|
|
|
|
def ExecuteInParallel(jobs, func, inputs, callback, output=None, ordered=False):
|
|
|
|
"""Helper for managing parallel execution boiler plate.
|
|
|
|
|
|
|
|
For subcommands that can easily split their work up.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
jobs: How many parallel processes to use.
|
|
|
|
func: The function to apply to each of the |inputs|. Usually a
|
|
|
|
functools.partial for wrapping additional arguments. It will be run
|
|
|
|
in a separate process, so it must be pickalable, so nested functions
|
|
|
|
won't work. Methods on the subcommand Command class should work.
|
|
|
|
inputs: The list of items to process. Must be a list.
|
|
|
|
callback: The function to pass the results to for processing. It will be
|
|
|
|
executed in the main thread and process the results of |func| as they
|
|
|
|
become available. Thus it may be a local nested function. Its return
|
|
|
|
value is passed back directly. It takes three arguments:
|
|
|
|
- The processing pool (or None with one job).
|
|
|
|
- The |output| argument.
|
|
|
|
- An iterator for the results.
|
|
|
|
output: An output manager. May be progress.Progess or color.Coloring.
|
|
|
|
ordered: Whether the jobs should be processed in order.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The |callback| function's results are returned.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
|
|
|
if len(inputs) == 1 or jobs == 1:
|
|
|
|
return callback(None, output, (func(x) for x in inputs))
|
|
|
|
else:
|
|
|
|
with multiprocessing.Pool(jobs) as pool:
|
|
|
|
submit = pool.imap if ordered else pool.imap_unordered
|
|
|
|
return callback(pool, output, submit(func, inputs, chunksize=WORKER_BATCH_SIZE))
|
|
|
|
finally:
|
|
|
|
if isinstance(output, progress.Progress):
|
|
|
|
output.end()
|
|
|
|
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
def _ResetPathToProjectMap(self, projects):
|
|
|
|
self._by_path = dict((p.worktree, p) for p in projects)
|
|
|
|
|
|
|
|
def _UpdatePathToProjectMap(self, project):
|
|
|
|
self._by_path[project.worktree] = project
|
|
|
|
|
2015-08-20 19:19:28 +00:00
|
|
|
def _GetProjectByPath(self, manifest, path):
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
project = None
|
|
|
|
if os.path.exists(path):
|
|
|
|
oldpath = None
|
2020-02-12 05:55:01 +00:00
|
|
|
while (path and
|
|
|
|
path != oldpath and
|
|
|
|
path != manifest.topdir):
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
try:
|
|
|
|
project = self._by_path[path]
|
|
|
|
break
|
|
|
|
except KeyError:
|
|
|
|
oldpath = path
|
|
|
|
path = os.path.dirname(path)
|
repo: Repo does not always handle '.' parameter correctly
The repo script allows a manifest to specify a '.' as the path the
top-level directory, which co-locates the .git and .repo directories,
and places files from the git repository at the top-level:
<project name="proj_name" path="." />
<project name="sierra.other.git" path="other" />
Most commands work correctly with this setup. Some commands, however,
fail to find the project. For instance, 'repo sync' works, and 'repo sync .'
works in a sub-project ('other' in this case) but 'repo sync .' in the
top-level directory fails with the error:
error: project . not found
There are two reasons for this:
1. The self.worktree attribute of the Project object is not normalized,
so with a '.' for path its value would be '/my/project/root/.'. This is
fine when used as a path, since it's the same path as '/my/project/root',
but when used in a string comparison it fails. This commit applies
os.path.normpath() to that value before storing it.
2. The _GetProjectByPath method in command.py was not checking the path
against manifest.topdir, so even once it was normalized the project was
not found. This commit adds a check against manifest.topdir if the
loop drops out without finding a project.
Change-Id: Ic84d053f1bbb5a357cad566805d5a326ae8246d2
2016-02-24 01:10:42 +00:00
|
|
|
if not project and path == manifest.topdir:
|
|
|
|
try:
|
|
|
|
project = self._by_path[path]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
project = self._by_path[path]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
return project
|
|
|
|
|
2015-08-20 19:19:28 +00:00
|
|
|
def GetProjects(self, args, manifest=None, groups='', missing_ok=False,
|
|
|
|
submodules_ok=False):
|
2008-10-21 14:00:00 +00:00
|
|
|
"""A list of projects that match the arguments.
|
|
|
|
"""
|
2015-08-20 19:19:28 +00:00
|
|
|
if not manifest:
|
|
|
|
manifest = self.manifest
|
|
|
|
all_projects_list = manifest.projects
|
2008-10-21 14:00:00 +00:00
|
|
|
result = []
|
|
|
|
|
2015-08-20 19:19:28 +00:00
|
|
|
mp = manifest.manifestProject
|
2012-03-29 03:15:45 +00:00
|
|
|
|
2015-07-29 22:02:54 +00:00
|
|
|
if not groups:
|
2021-03-09 23:19:06 +00:00
|
|
|
groups = manifest.GetGroupsStr()
|
2012-10-25 03:23:11 +00:00
|
|
|
groups = [x for x in re.split(r'[,\s]+', groups) if x]
|
2012-03-29 03:15:45 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
if not args:
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
derived_projects = {}
|
|
|
|
for project in all_projects_list:
|
|
|
|
if submodules_ok or project.sync_s:
|
|
|
|
derived_projects.update((p.name, p)
|
|
|
|
for p in project.GetDerivedSubprojects())
|
|
|
|
all_projects_list.extend(derived_projects.values())
|
|
|
|
for project in all_projects_list:
|
2016-02-10 17:44:30 +00:00
|
|
|
if (missing_ok or project.Exists) and project.MatchesGroups(groups):
|
2008-10-21 14:00:00 +00:00
|
|
|
result.append(project)
|
|
|
|
else:
|
2013-10-12 00:03:19 +00:00
|
|
|
self._ResetPathToProjectMap(all_projects_list)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
for arg in args:
|
2019-10-04 18:21:41 +00:00
|
|
|
# We have to filter by manifest groups in case the requested project is
|
|
|
|
# checked out multiple times or differently based on them.
|
|
|
|
projects = [project for project in manifest.GetProjectsWithName(arg)
|
|
|
|
if project.MatchesGroups(groups)]
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
if not projects:
|
2011-01-10 01:31:57 +00:00
|
|
|
path = os.path.abspath(arg).replace('\\', '/')
|
2015-08-20 19:19:28 +00:00
|
|
|
project = self._GetProjectByPath(manifest, path)
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
|
|
|
|
# If it's not a derived project, update path->project mapping and
|
|
|
|
# search again, as arg might actually point to a derived subproject.
|
2016-02-10 17:44:30 +00:00
|
|
|
if (project and not project.Derived and (submodules_ok or
|
|
|
|
project.sync_s)):
|
Represent git-submodule as nested projects, take 2
(Previous submission of this change broke Android buildbot due to
incorrect regular expression for parsing git-config output. During
investigation, we also found that Android, which pulls Chromium, has a
workaround for Chromium's submodules; its manifest includes Chromium's
submodules. This new change, in addition to fixing the regex, also
take this type of workarounds into consideration; it adds a new
attribute that makes repo not fetch submodules unless submodules have a
project element defined in the manifest, or this attribute is
overridden by a parent project element or by the default element.)
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: I4b8344c1b9ccad2f58ad304573133e5d52e1faef
2012-01-11 03:28:42 +00:00
|
|
|
search_again = False
|
|
|
|
for subproject in project.GetDerivedSubprojects():
|
|
|
|
self._UpdatePathToProjectMap(subproject)
|
|
|
|
search_again = True
|
|
|
|
if search_again:
|
2015-08-20 19:19:28 +00:00
|
|
|
project = self._GetProjectByPath(manifest, path) or project
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
if project:
|
|
|
|
projects = [project]
|
|
|
|
|
|
|
|
if not projects:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise NoSuchProjectError(arg)
|
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
for project in projects:
|
|
|
|
if not missing_ok and not project.Exists:
|
2019-10-04 18:21:41 +00:00
|
|
|
raise NoSuchProjectError('%s (%s)' % (arg, project.relpath))
|
2013-10-12 00:03:19 +00:00
|
|
|
if not project.MatchesGroups(groups):
|
|
|
|
raise InvalidProjectGroupsError(arg)
|
|
|
|
|
|
|
|
result.extend(projects)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _getpath(x):
|
|
|
|
return x.relpath
|
|
|
|
result.sort(key=_getpath)
|
|
|
|
return result
|
|
|
|
|
2016-01-26 05:11:35 +00:00
|
|
|
def FindProjects(self, args, inverse=False):
|
2013-03-15 02:32:10 +00:00
|
|
|
result = []
|
2013-04-30 01:57:37 +00:00
|
|
|
patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args]
|
2013-03-15 02:32:10 +00:00
|
|
|
for project in self.GetProjects(''):
|
2013-04-30 01:57:37 +00:00
|
|
|
for pattern in patterns:
|
2016-01-26 05:11:35 +00:00
|
|
|
match = pattern.search(project.name) or pattern.search(project.relpath)
|
|
|
|
if not inverse and match:
|
2013-03-15 02:32:10 +00:00
|
|
|
result.append(project)
|
|
|
|
break
|
2016-01-26 05:11:35 +00:00
|
|
|
if inverse and match:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
if inverse:
|
|
|
|
result.append(project)
|
2013-03-15 02:32:10 +00:00
|
|
|
result.sort(key=lambda project: project.relpath)
|
|
|
|
return result
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class InteractiveCommand(Command):
|
|
|
|
"""Command which requires user interaction on the tty and
|
|
|
|
must not run within a pager, even if the user asks to.
|
|
|
|
"""
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
def WantPager(self, _opt):
|
2009-04-18 20:49:13 +00:00
|
|
|
return False
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class PagedCommand(Command):
|
|
|
|
"""Command which defaults to output in a pager, as its
|
|
|
|
display tends to be larger than one screen full.
|
|
|
|
"""
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
def WantPager(self, _opt):
|
2009-04-18 20:49:13 +00:00
|
|
|
return True
|
2009-03-04 01:47:06 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2009-03-04 01:47:06 +00:00
|
|
|
class MirrorSafeCommand(object):
|
|
|
|
"""Command permits itself to run within a mirror,
|
|
|
|
and does not require a working directory.
|
|
|
|
"""
|
2015-08-31 22:45:06 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2015-08-31 22:45:06 +00:00
|
|
|
class GitcAvailableCommand(object):
|
2015-08-31 22:45:06 +00:00
|
|
|
"""Command that requires GITC to be available, but does
|
|
|
|
not require the local client to be a GITC client.
|
|
|
|
"""
|
2015-08-31 22:45:06 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2015-08-31 22:45:06 +00:00
|
|
|
class GitcClientCommand(object):
|
|
|
|
"""Command that requires the local client to be a GITC
|
|
|
|
client.
|
|
|
|
"""
|