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-04-25 12:02:02 +00:00
|
|
|
import errno
|
2021-02-24 01:48:04 +00:00
|
|
|
import functools
|
2019-06-13 06:24:21 +00:00
|
|
|
import http.cookiejar as cookielib
|
2021-02-23 23:38:39 +00:00
|
|
|
import io
|
2014-05-06 14:57:48 +00:00
|
|
|
import json
|
2021-02-24 01:48:04 +00:00
|
|
|
import multiprocessing
|
2012-08-24 01:21:02 +00:00
|
|
|
import netrc
|
2009-04-10 23:51:53 +00:00
|
|
|
from optparse import SUPPRESS_HELP
|
2008-10-21 14:00:00 +00:00
|
|
|
import os
|
2010-04-06 17:40:01 +00:00
|
|
|
import socket
|
2008-10-21 14:00:00 +00:00
|
|
|
import sys
|
2015-08-17 20:41:45 +00:00
|
|
|
import tempfile
|
2009-04-18 17:49:00 +00:00
|
|
|
import time
|
2019-06-13 06:24:21 +00:00
|
|
|
import urllib.error
|
|
|
|
import urllib.parse
|
|
|
|
import urllib.request
|
|
|
|
import xmlrpc.client
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2010-05-08 20:32:08 +00:00
|
|
|
try:
|
|
|
|
import threading as _threading
|
|
|
|
except ImportError:
|
|
|
|
import dummy_threading as _threading
|
|
|
|
|
2011-09-23 00:23:41 +00:00
|
|
|
try:
|
|
|
|
import resource
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2011-09-23 00:23:41 +00:00
|
|
|
def _rlimit_nofile():
|
|
|
|
return resource.getrlimit(resource.RLIMIT_NOFILE)
|
|
|
|
except ImportError:
|
|
|
|
def _rlimit_nofile():
|
|
|
|
return (256, 256)
|
|
|
|
|
2017-04-05 07:02:59 +00:00
|
|
|
import event_log
|
2021-03-15 18:58:52 +00:00
|
|
|
from git_command import git_require
|
2015-08-20 07:55:42 +00:00
|
|
|
from git_config import GetUrlCookieFile
|
2012-09-07 00:52:04 +00:00
|
|
|
from git_refs import R_HEADS, HEAD
|
2021-01-15 03:17:50 +00:00
|
|
|
import git_superproject
|
2015-08-10 20:23:23 +00:00
|
|
|
import gitc_utils
|
2009-06-02 04:10:33 +00:00
|
|
|
from project import Project
|
|
|
|
from project import RemoteSpec
|
2021-04-21 03:21:29 +00:00
|
|
|
from command import Command, MirrorSafeCommand, WORKER_BATCH_SIZE
|
2021-02-04 22:39:38 +00:00
|
|
|
from error import RepoChangedException, GitError, ManifestParseError
|
2016-11-03 17:37:53 +00:00
|
|
|
import platform_utils
|
Change repo sync to be more friendly when updating the tree
We now try to sync all projects that can be done safely first, before
we start rebasing user commits over the upstream. This has the nice
effect of making the local tree as close to the upstream as possible
before the user has to start resolving merge conflicts, as that extra
information in other projects may aid in the conflict resolution.
Informational output is buffered and delayed until calculation for
all projects has been done, so that the user gets one concise list
of notice messages, rather than it interrupting the progress meter.
Fast-forward output is now prefixed with the project header, so the
user can see which project that update is taking place in, and make
some relation of the diffstat back to the project name.
Rebase output is now prefixed with the project header, so that if
the rebase fails, the user can see which project we were operating
on and can try to address the failure themselves.
Since rebase sits on a detached HEAD, we now look for an in-progress
rebase during sync, so we can alert the user that the given project
is in a state we cannot handle.
Signed-off-by: Shawn O. Pearce <sop@google.com>
2009-04-16 18:21:18 +00:00
|
|
|
from project import SyncBuffer
|
2009-04-10 23:48:52 +00:00
|
|
|
from progress import Progress
|
2021-05-05 23:44:35 +00:00
|
|
|
import ssh
|
2014-01-30 23:09:59 +00:00
|
|
|
from wrapper import Wrapper
|
2015-09-08 20:27:20 +00:00
|
|
|
from manifest_xml import GitcManifest
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-10-23 22:00:54 +00:00
|
|
|
_ONE_DAY_S = 24 * 60 * 60
|
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2009-03-04 01:47:06 +00:00
|
|
|
class Sync(Command, MirrorSafeCommand):
|
2010-05-08 20:32:08 +00:00
|
|
|
jobs = 1
|
2021-06-14 20:05:19 +00:00
|
|
|
COMMON = True
|
2008-10-21 14:00:00 +00:00
|
|
|
helpSummary = "Update working tree to the latest revision"
|
|
|
|
helpUsage = """
|
|
|
|
%prog [<project>...]
|
|
|
|
"""
|
|
|
|
helpDescription = """
|
|
|
|
The '%prog' command synchronizes local project directories
|
|
|
|
with the remote repositories specified in the manifest. If a local
|
|
|
|
project does not yet exist, it will clone a new local directory from
|
|
|
|
the remote repository and set up tracking branches as specified in
|
|
|
|
the manifest. If the local project already exists, '%prog'
|
|
|
|
will update the remote branches and rebase any new local changes
|
|
|
|
on top of the new remote changes.
|
|
|
|
|
|
|
|
'%prog' will synchronize all projects listed at the command
|
|
|
|
line. Projects can be specified either by name, or by a relative
|
|
|
|
or absolute path to the project's local directory. If no projects
|
|
|
|
are specified, '%prog' will synchronize all projects listed in
|
|
|
|
the manifest.
|
2009-04-10 23:59:36 +00:00
|
|
|
|
|
|
|
The -d/--detach option can be used to switch specified projects
|
|
|
|
back to the manifest revision. This option is especially helpful
|
|
|
|
if the project is currently on a topic branch, but the manifest
|
|
|
|
revision is temporarily needed.
|
2009-04-21 15:02:04 +00:00
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
The -s/--smart-sync option can be used to sync to a known good
|
|
|
|
build as specified by the manifest-server element in the current
|
2011-04-19 08:32:52 +00:00
|
|
|
manifest. The -t/--smart-tag option is similar and allows you to
|
|
|
|
specify a custom tag/label.
|
2010-04-06 17:40:01 +00:00
|
|
|
|
2012-09-14 01:31:42 +00:00
|
|
|
The -u/--manifest-server-username and -p/--manifest-server-password
|
|
|
|
options can be used to specify a username and password to authenticate
|
|
|
|
with the manifest server when using the -s or -t option.
|
|
|
|
|
|
|
|
If -u and -p are not specified when using the -s or -t option, '%prog'
|
|
|
|
will attempt to read authentication credentials for the manifest server
|
|
|
|
from the user's .netrc file.
|
|
|
|
|
|
|
|
'%prog' will not use authentication credentials from -u/-p or .netrc
|
|
|
|
if the manifest server specified in the manifest file already includes
|
|
|
|
credentials.
|
|
|
|
|
2019-08-26 07:12:55 +00:00
|
|
|
By default, all projects will be synced. The --fail-fast option can be used
|
2020-05-24 18:56:52 +00:00
|
|
|
to halt syncing as soon as possible when the first project fails to sync.
|
2010-07-02 22:58:31 +00:00
|
|
|
|
2014-11-12 18:27:45 +00:00
|
|
|
The --force-sync option can be used to overwrite existing git
|
|
|
|
directories if they have previously been linked to a different
|
2020-06-05 17:33:40 +00:00
|
|
|
object directory. WARNING: This may cause data to be lost since
|
2014-11-12 18:27:45 +00:00
|
|
|
refs may be removed when overwriting.
|
|
|
|
|
2018-12-18 00:23:44 +00:00
|
|
|
The --force-remove-dirty option can be used to remove previously used
|
|
|
|
projects with uncommitted changes. WARNING: This may cause data to be
|
|
|
|
lost since uncommitted changes may be removed with projects that no longer
|
|
|
|
exist in the manifest.
|
|
|
|
|
2012-03-14 22:36:59 +00:00
|
|
|
The --no-clone-bundle option disables any attempt to use
|
|
|
|
$URL/clone.bundle to bootstrap a new Git repository from a
|
|
|
|
resumeable bundle file on a content delivery network. This
|
|
|
|
may be necessary if there are problems with the local Python
|
|
|
|
HTTP client or proxy configuration, but the Git binary works.
|
|
|
|
|
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
|
|
|
The --fetch-submodules option enables fetching Git submodules
|
|
|
|
of a project from server.
|
|
|
|
|
2015-01-29 05:36:28 +00:00
|
|
|
The -c/--current-branch option can be used to only fetch objects that
|
|
|
|
are on the branch specified by a project's revision.
|
|
|
|
|
2014-09-04 12:28:09 +00:00
|
|
|
The --optimized-fetch option can be used to only fetch projects that
|
|
|
|
are fixed to a sha1 revision if the sha1 revision does not already
|
|
|
|
exist locally.
|
|
|
|
|
2015-10-14 01:50:15 +00:00
|
|
|
The --prune option can be used to remove any refs that no longer
|
|
|
|
exist on the remote.
|
|
|
|
|
2018-10-10 05:05:11 +00:00
|
|
|
# SSH Connections
|
2009-04-21 15:02:04 +00:00
|
|
|
|
|
|
|
If at least one project remote URL uses an SSH connection (ssh://,
|
|
|
|
git+ssh://, or user@host:path syntax) repo will automatically
|
|
|
|
enable the SSH ControlMaster option when connecting to that host.
|
|
|
|
This feature permits other projects in the same '%prog' session to
|
|
|
|
reuse the same SSH tunnel, saving connection setup overheads.
|
|
|
|
|
|
|
|
To disable this behavior on UNIX platforms, set the GIT_SSH
|
|
|
|
environment variable to 'ssh'. For example:
|
|
|
|
|
|
|
|
export GIT_SSH=ssh
|
|
|
|
%prog
|
|
|
|
|
2018-10-10 05:05:11 +00:00
|
|
|
# Compatibility
|
2009-04-21 15:02:04 +00:00
|
|
|
|
|
|
|
This feature is automatically disabled on Windows, due to the lack
|
|
|
|
of UNIX domain socket support.
|
|
|
|
|
|
|
|
This feature is not compatible with url.insteadof rewrites in the
|
|
|
|
user's ~/.gitconfig. '%prog' is currently not able to perform the
|
|
|
|
rewrite early enough to establish the ControlMaster tunnel.
|
|
|
|
|
|
|
|
If the remote SSH daemon is Gerrit Code Review, version 2.0.10 or
|
|
|
|
later is required to fix a server side protocol bug.
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
"""
|
2021-02-16 06:43:31 +00:00
|
|
|
PARALLEL_JOBS = 1
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2021-04-13 18:57:40 +00:00
|
|
|
def _CommonOptions(self, p):
|
2021-05-04 12:06:36 +00:00
|
|
|
if self.manifest:
|
|
|
|
try:
|
|
|
|
self.PARALLEL_JOBS = self.manifest.default.sync_j
|
|
|
|
except ManifestParseError:
|
|
|
|
pass
|
2021-04-13 18:57:40 +00:00
|
|
|
super()._CommonOptions(p)
|
2011-09-23 00:44:31 +00:00
|
|
|
|
2021-04-13 18:57:40 +00:00
|
|
|
def _Options(self, p, show_smart=True):
|
2021-04-09 04:21:02 +00:00
|
|
|
p.add_option('--jobs-network', default=None, type=int, metavar='JOBS',
|
|
|
|
help='number of network jobs to run in parallel (defaults to --jobs)')
|
|
|
|
p.add_option('--jobs-checkout', default=None, type=int, metavar='JOBS',
|
|
|
|
help='number of local checkout jobs to run in parallel (defaults to --jobs)')
|
|
|
|
|
2010-07-02 22:58:31 +00:00
|
|
|
p.add_option('-f', '--force-broken',
|
2019-08-30 08:20:15 +00:00
|
|
|
dest='force_broken', action='store_true',
|
2019-08-26 07:12:55 +00:00
|
|
|
help='obsolete option (to be deleted in the future)')
|
|
|
|
p.add_option('--fail-fast',
|
|
|
|
dest='fail_fast', action='store_true',
|
|
|
|
help='stop syncing after first error is hit')
|
2014-11-12 18:27:45 +00:00
|
|
|
p.add_option('--force-sync',
|
|
|
|
dest='force_sync', action='store_true',
|
|
|
|
help="overwrite an existing git directory if it needs to "
|
|
|
|
"point to a different object directory. WARNING: this "
|
|
|
|
"may cause loss of data")
|
2018-12-18 00:23:44 +00:00
|
|
|
p.add_option('--force-remove-dirty',
|
|
|
|
dest='force_remove_dirty', action='store_true',
|
|
|
|
help="force remove projects with uncommitted modifications if "
|
|
|
|
"projects no longer exist in the manifest. "
|
|
|
|
"WARNING: this may cause loss of data")
|
2012-11-14 03:09:38 +00:00
|
|
|
p.add_option('-l', '--local-only',
|
2009-04-11 00:04:08 +00:00
|
|
|
dest='local_only', action='store_true',
|
|
|
|
help="only update working tree, don't fetch")
|
2020-02-12 05:31:05 +00:00
|
|
|
p.add_option('--no-manifest-update', '--nmu',
|
2019-11-22 08:04:31 +00:00
|
|
|
dest='mp_update', action='store_false', default='true',
|
|
|
|
help='use the existing manifest checkout as-is. '
|
|
|
|
'(do not update to the latest revision)')
|
2012-11-14 03:09:38 +00:00
|
|
|
p.add_option('-n', '--network-only',
|
2009-04-10 23:29:20 +00:00
|
|
|
dest='network_only', action='store_true',
|
|
|
|
help="fetch only, don't update working tree")
|
2012-11-14 03:09:38 +00:00
|
|
|
p.add_option('-d', '--detach',
|
2009-04-10 23:59:36 +00:00
|
|
|
dest='detach_head', action='store_true',
|
|
|
|
help='detach projects back to manifest revision')
|
2012-11-14 03:09:38 +00:00
|
|
|
p.add_option('-c', '--current-branch',
|
2011-08-26 00:21:47 +00:00
|
|
|
dest='current_branch_only', action='store_true',
|
|
|
|
help='fetch only current branch from server')
|
2021-05-03 05:10:09 +00:00
|
|
|
p.add_option('--no-current-branch',
|
|
|
|
dest='current_branch_only', action='store_false',
|
|
|
|
help='fetch all branches from server')
|
2012-01-26 16:36:18 +00:00
|
|
|
p.add_option('-m', '--manifest-name',
|
|
|
|
dest='manifest_name',
|
|
|
|
help='temporary manifest to use for this sync', metavar='NAME.xml')
|
2020-05-20 23:03:45 +00:00
|
|
|
p.add_option('--clone-bundle', action='store_true',
|
|
|
|
help='enable use of /clone.bundle on HTTP/HTTPS')
|
|
|
|
p.add_option('--no-clone-bundle', dest='clone_bundle', action='store_false',
|
2012-03-14 22:36:59 +00:00
|
|
|
help='disable use of /clone.bundle on HTTP/HTTPS')
|
2012-11-06 21:14:31 +00:00
|
|
|
p.add_option('-u', '--manifest-server-username', action='store',
|
|
|
|
dest='manifest_server_username',
|
|
|
|
help='username to authenticate with the manifest server')
|
|
|
|
p.add_option('-p', '--manifest-server-password', action='store',
|
|
|
|
dest='manifest_server_password',
|
|
|
|
help='password to authenticate with the manifest server')
|
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
|
|
|
p.add_option('--fetch-submodules',
|
|
|
|
dest='fetch_submodules', action='store_true',
|
|
|
|
help='fetch submodules from server')
|
2021-01-15 03:17:50 +00:00
|
|
|
p.add_option('--use-superproject', action='store_true',
|
|
|
|
help='use the manifest superproject to sync projects')
|
2021-05-07 21:01:54 +00:00
|
|
|
p.add_option('--no-use-superproject', action='store_false',
|
|
|
|
dest='use_superproject',
|
|
|
|
help='disable use of manifest superprojects')
|
2021-05-03 05:21:35 +00:00
|
|
|
p.add_option('--tags',
|
|
|
|
action='store_false',
|
|
|
|
help='fetch tags')
|
2012-10-29 17:18:34 +00:00
|
|
|
p.add_option('--no-tags',
|
2021-05-03 05:21:35 +00:00
|
|
|
dest='tags', action='store_false',
|
2012-10-29 17:18:34 +00:00
|
|
|
help="don't fetch tags")
|
2014-09-04 12:28:09 +00:00
|
|
|
p.add_option('--optimized-fetch',
|
|
|
|
dest='optimized_fetch', action='store_true',
|
|
|
|
help='only fetch projects fixed to sha1 if revision does not exist locally')
|
2020-04-02 18:36:09 +00:00
|
|
|
p.add_option('--retry-fetches',
|
|
|
|
default=0, action='store', type='int',
|
|
|
|
help='number of times to retry fetches on transient errors')
|
2015-10-14 01:50:15 +00:00
|
|
|
p.add_option('--prune', dest='prune', action='store_true',
|
|
|
|
help='delete refs that no longer exist on the remote')
|
2010-05-11 19:57:01 +00:00
|
|
|
if show_smart:
|
|
|
|
p.add_option('-s', '--smart-sync',
|
|
|
|
dest='smart_sync', action='store_true',
|
2016-04-13 09:03:00 +00:00
|
|
|
help='smart sync using manifest from the latest known good build')
|
2011-04-19 08:32:52 +00:00
|
|
|
p.add_option('-t', '--smart-tag',
|
|
|
|
dest='smart_tag', action='store',
|
|
|
|
help='smart sync using manifest from a known tag')
|
2009-04-10 23:59:36 +00:00
|
|
|
|
2009-04-18 18:28:57 +00:00
|
|
|
g = p.add_option_group('repo Version options')
|
|
|
|
g.add_option('--no-repo-verify',
|
2020-02-17 19:36:08 +00:00
|
|
|
dest='repo_verify', default=True, action='store_false',
|
2008-10-21 14:00:00 +00:00
|
|
|
help='do not verify repo source code')
|
2009-04-18 18:28:57 +00:00
|
|
|
g.add_option('--repo-upgraded',
|
2008-11-03 18:32:09 +00:00
|
|
|
dest='repo_upgraded', action='store_true',
|
2009-04-10 23:51:53 +00:00
|
|
|
help=SUPPRESS_HELP)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2021-02-08 00:30:27 +00:00
|
|
|
def _GetBranch(self):
|
|
|
|
"""Returns the branch name for getting the approved manifest."""
|
|
|
|
p = self.manifest.manifestProject
|
|
|
|
b = p.GetBranch(p.CurrentBranch)
|
|
|
|
branch = b.merge
|
|
|
|
if branch.startswith(R_HEADS):
|
|
|
|
branch = branch[len(R_HEADS):]
|
|
|
|
return branch
|
|
|
|
|
2021-03-23 22:12:27 +00:00
|
|
|
def _GetCurrentBranchOnly(self, opt):
|
|
|
|
"""Returns True if current-branch or use-superproject options are enabled."""
|
Add the ability to administratively enroll repo into using superproject.
Repo will remember a choice and an expiration time of the choice, per
user, about whether to use superproject by default. When not specified
from command line and the choice is not expired, repo would use the
user default value.
When a user default value is not present and when the system wide
enable default is provided in git's system configuration, repo would
ask the user for a confirmation which will be valid for two weeks.
git_config.py: Add support for system config. When reading system
config, we would use --system to avoid hardcoding a path as the
value may be different on some other distributions.
git_superproject.py: Add a new subroutine, _UseSuperproject(), which
returns whether superproject should be used and whether it
is from a user configuration.
The value is determined in the following order:
1. If the user specifies either --use-superproject or
--no-use-superproject, then that choice is being used.
2. If neither is specified, we would then check the saved value
(upon repo init) and use that choice when there was a choice.
3. We then check if there is a saved and unexpired value for
user's choice in their ~/.gitconfig, and use the unexpired
choice, if available.
4. Finally, if all the above didn't give us a decision, and if
the git system configuration is providing a rollout hint, present
a prompt to user for their decision and save it in ~/.gitconfig.
subcmds/sync.py: Make use of the new UseSuperproject() provided by
git_superproject.py.
While there also silent stderr from git describe when determining the
version of repo.
Bug: [google internal] b/190688390
Change-Id: Iad3ee03026342ee500e5d65e2f0fa600d7637613
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309762
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Xin Li <delphij@google.com>
2021-06-16 17:19:00 +00:00
|
|
|
return opt.current_branch_only or git_superproject.UseSuperproject(opt, self.manifest)
|
2021-03-23 22:12:27 +00:00
|
|
|
|
2021-07-28 21:36:49 +00:00
|
|
|
def _UpdateProjectsRevisionId(self, opt, args, load_local_manifests, superproject_logging_data):
|
2021-02-04 22:39:38 +00:00
|
|
|
"""Update revisionId of every project with the SHA from superproject.
|
|
|
|
|
|
|
|
This function updates each project's revisionId with SHA from superproject.
|
|
|
|
It writes the updated manifest into a file and reloads the manifest from it.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
opt: Program options returned from optparse. See _Options().
|
|
|
|
args: Arguments to pass to GetProjects. See the GetProjects
|
|
|
|
docstring for details.
|
2021-05-03 02:47:29 +00:00
|
|
|
load_local_manifests: Whether to load local manifests.
|
2021-07-28 21:36:49 +00:00
|
|
|
superproject_logging_data: A dictionary of superproject data that is to be logged.
|
2021-02-04 22:39:38 +00:00
|
|
|
|
|
|
|
Returns:
|
superproject: Don't exit if superproject tag doesn't exist in manifest.
Don't exit if there are missing commit ids in superproject.
This change implements the following suggestion from delphij@:
"we should note the event (so we know that --use-superproject but there
were some errors, e.g. manifest didn't specify commit id for some
reason, or if there is no superproject but --use-superproject is
used), print out a message telling the use that this is not support,
but continue as if --no-use-superproject was specified?"
Changes:
superproject:
+ Added git_trace2_event_log as an argument to the constructor.
+ Sync method returns SyncResult a NamedTuple of
++ success - True if sync of superproject is successful, or False.
++ fatal - True if caller should exit, Or False.
+ UpdateProjectsRevisionId returns UpdateProjectsResult a NamedTuple of
++ manifest_path - path name of the overriding manifest file instead
of None
++ fatal - True if caller should exit, Or False
+ _GetAllProjectsCommitIds returns CommitIdsResult a NamedTuple of
++ commit_ids - a dictionary with the projects/commit ids on success,
otherwise None
++ fatal - True if caller should exit, Or False
+ Added _SkipUpdatingProjectRevisionId a helper function to see if a
project's revision id needs to be updated or not. This function is
used to exclude projects from local manifest file.
+ Added the following error events into git_trace2_event_log
++ If superproject is missing in a manifest
++ If there are missing commit ids for projects.
command.py:
+ Deleted unused import - platform
+ Added git_trace2_event_log as a member so all subcmds can log error
events.
main.py:
+ Initialized git_trace2_event_log as a member of command object.
init.py:
+ Deleted unused import - optparse
init.py:
+ Called sys.exit only if Sync returns exit=True
sync.py:
+ Called sys.exit only if Superproject's UpdateProjectsRevisionId returns
exit=True
+ Reloaded the manifest only if manifest path is returned by
UpdateProjectsRevisionId. If not, fall back to the old way of doing
repo sync.
test_git_superproject:
+ Added code to verify error events are being logged.
+ Added a test for no superproject tag
+ Added test for UpdateProjectsRevisionId not updating the revision id
with the commit ids.
Tested the code with the following commands.
+ Positive test case with aosp-master.
$ repo_dev init -u persistent-https://android.git.corp.google.com/platform/manifest -b master --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in .../android/aosp
$ repo_dev sync -j40 --use-superproject
remote: Total 12 (delta 4), reused 12 (delta 4)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
...
repo sync has finished successfully.
+ Negative test case without superproject tag.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: .../android/aosp/.repo/manifest.xml
error: Cannot get project commit ids from manifest
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.589s
repo sync has finished successfully.
+ Test for missing commit_id for a project.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
error: please file a bug using go/repo-bug to report missing commit_ids for: ['build/blueprint']
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.364s
repo sync has finished successfully.
$ ./run_tests -v
...
...== 164 passed in 2.87s ==...
Bug: [google internal] b/189371541
Change-Id: I5ea49f87e8fa41be590fc0c914573e16c8cdfcfa
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309162
Tested-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
2021-06-12 00:29:45 +00:00
|
|
|
Returns path to the overriding manifest file instead of None.
|
2021-02-04 22:39:38 +00:00
|
|
|
"""
|
2021-08-13 18:47:24 +00:00
|
|
|
print_messages = git_superproject.PrintMessages(opt, self.manifest)
|
2021-02-09 08:26:31 +00:00
|
|
|
superproject = git_superproject.Superproject(self.manifest,
|
2021-03-04 18:29:40 +00:00
|
|
|
self.repodir,
|
superproject: Don't exit if superproject tag doesn't exist in manifest.
Don't exit if there are missing commit ids in superproject.
This change implements the following suggestion from delphij@:
"we should note the event (so we know that --use-superproject but there
were some errors, e.g. manifest didn't specify commit id for some
reason, or if there is no superproject but --use-superproject is
used), print out a message telling the use that this is not support,
but continue as if --no-use-superproject was specified?"
Changes:
superproject:
+ Added git_trace2_event_log as an argument to the constructor.
+ Sync method returns SyncResult a NamedTuple of
++ success - True if sync of superproject is successful, or False.
++ fatal - True if caller should exit, Or False.
+ UpdateProjectsRevisionId returns UpdateProjectsResult a NamedTuple of
++ manifest_path - path name of the overriding manifest file instead
of None
++ fatal - True if caller should exit, Or False
+ _GetAllProjectsCommitIds returns CommitIdsResult a NamedTuple of
++ commit_ids - a dictionary with the projects/commit ids on success,
otherwise None
++ fatal - True if caller should exit, Or False
+ Added _SkipUpdatingProjectRevisionId a helper function to see if a
project's revision id needs to be updated or not. This function is
used to exclude projects from local manifest file.
+ Added the following error events into git_trace2_event_log
++ If superproject is missing in a manifest
++ If there are missing commit ids for projects.
command.py:
+ Deleted unused import - platform
+ Added git_trace2_event_log as a member so all subcmds can log error
events.
main.py:
+ Initialized git_trace2_event_log as a member of command object.
init.py:
+ Deleted unused import - optparse
init.py:
+ Called sys.exit only if Sync returns exit=True
sync.py:
+ Called sys.exit only if Superproject's UpdateProjectsRevisionId returns
exit=True
+ Reloaded the manifest only if manifest path is returned by
UpdateProjectsRevisionId. If not, fall back to the old way of doing
repo sync.
test_git_superproject:
+ Added code to verify error events are being logged.
+ Added a test for no superproject tag
+ Added test for UpdateProjectsRevisionId not updating the revision id
with the commit ids.
Tested the code with the following commands.
+ Positive test case with aosp-master.
$ repo_dev init -u persistent-https://android.git.corp.google.com/platform/manifest -b master --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in .../android/aosp
$ repo_dev sync -j40 --use-superproject
remote: Total 12 (delta 4), reused 12 (delta 4)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
...
repo sync has finished successfully.
+ Negative test case without superproject tag.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: .../android/aosp/.repo/manifest.xml
error: Cannot get project commit ids from manifest
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.589s
repo sync has finished successfully.
+ Test for missing commit_id for a project.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
error: please file a bug using go/repo-bug to report missing commit_ids for: ['build/blueprint']
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.364s
repo sync has finished successfully.
$ ./run_tests -v
...
...== 164 passed in 2.87s ==...
Bug: [google internal] b/189371541
Change-Id: I5ea49f87e8fa41be590fc0c914573e16c8cdfcfa
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309162
Tested-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
2021-06-12 00:29:45 +00:00
|
|
|
self.git_event_log,
|
2021-08-13 18:47:24 +00:00
|
|
|
quiet=opt.quiet,
|
|
|
|
print_messages=print_messages)
|
2021-07-27 15:54:59 +00:00
|
|
|
if opt.local_only:
|
|
|
|
manifest_path = superproject.manifest_path
|
|
|
|
if manifest_path:
|
|
|
|
self._ReloadManifest(manifest_path, load_local_manifests)
|
|
|
|
return manifest_path
|
|
|
|
|
2021-02-04 22:39:38 +00:00
|
|
|
all_projects = self.GetProjects(args,
|
|
|
|
missing_ok=True,
|
|
|
|
submodules_ok=opt.fetch_submodules)
|
superproject: Don't exit if superproject tag doesn't exist in manifest.
Don't exit if there are missing commit ids in superproject.
This change implements the following suggestion from delphij@:
"we should note the event (so we know that --use-superproject but there
were some errors, e.g. manifest didn't specify commit id for some
reason, or if there is no superproject but --use-superproject is
used), print out a message telling the use that this is not support,
but continue as if --no-use-superproject was specified?"
Changes:
superproject:
+ Added git_trace2_event_log as an argument to the constructor.
+ Sync method returns SyncResult a NamedTuple of
++ success - True if sync of superproject is successful, or False.
++ fatal - True if caller should exit, Or False.
+ UpdateProjectsRevisionId returns UpdateProjectsResult a NamedTuple of
++ manifest_path - path name of the overriding manifest file instead
of None
++ fatal - True if caller should exit, Or False
+ _GetAllProjectsCommitIds returns CommitIdsResult a NamedTuple of
++ commit_ids - a dictionary with the projects/commit ids on success,
otherwise None
++ fatal - True if caller should exit, Or False
+ Added _SkipUpdatingProjectRevisionId a helper function to see if a
project's revision id needs to be updated or not. This function is
used to exclude projects from local manifest file.
+ Added the following error events into git_trace2_event_log
++ If superproject is missing in a manifest
++ If there are missing commit ids for projects.
command.py:
+ Deleted unused import - platform
+ Added git_trace2_event_log as a member so all subcmds can log error
events.
main.py:
+ Initialized git_trace2_event_log as a member of command object.
init.py:
+ Deleted unused import - optparse
init.py:
+ Called sys.exit only if Sync returns exit=True
sync.py:
+ Called sys.exit only if Superproject's UpdateProjectsRevisionId returns
exit=True
+ Reloaded the manifest only if manifest path is returned by
UpdateProjectsRevisionId. If not, fall back to the old way of doing
repo sync.
test_git_superproject:
+ Added code to verify error events are being logged.
+ Added a test for no superproject tag
+ Added test for UpdateProjectsRevisionId not updating the revision id
with the commit ids.
Tested the code with the following commands.
+ Positive test case with aosp-master.
$ repo_dev init -u persistent-https://android.git.corp.google.com/platform/manifest -b master --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in .../android/aosp
$ repo_dev sync -j40 --use-superproject
remote: Total 12 (delta 4), reused 12 (delta 4)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
...
repo sync has finished successfully.
+ Negative test case without superproject tag.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: .../android/aosp/.repo/manifest.xml
error: Cannot get project commit ids from manifest
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.589s
repo sync has finished successfully.
+ Test for missing commit_id for a project.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
error: please file a bug using go/repo-bug to report missing commit_ids for: ['build/blueprint']
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.364s
repo sync has finished successfully.
$ ./run_tests -v
...
...== 164 passed in 2.87s ==...
Bug: [google internal] b/189371541
Change-Id: I5ea49f87e8fa41be590fc0c914573e16c8cdfcfa
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309162
Tested-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
2021-06-12 00:29:45 +00:00
|
|
|
update_result = superproject.UpdateProjectsRevisionId(all_projects)
|
|
|
|
manifest_path = update_result.manifest_path
|
2021-07-28 21:36:49 +00:00
|
|
|
superproject_logging_data['updatedrevisionid'] = bool(manifest_path)
|
superproject: Don't exit if superproject tag doesn't exist in manifest.
Don't exit if there are missing commit ids in superproject.
This change implements the following suggestion from delphij@:
"we should note the event (so we know that --use-superproject but there
were some errors, e.g. manifest didn't specify commit id for some
reason, or if there is no superproject but --use-superproject is
used), print out a message telling the use that this is not support,
but continue as if --no-use-superproject was specified?"
Changes:
superproject:
+ Added git_trace2_event_log as an argument to the constructor.
+ Sync method returns SyncResult a NamedTuple of
++ success - True if sync of superproject is successful, or False.
++ fatal - True if caller should exit, Or False.
+ UpdateProjectsRevisionId returns UpdateProjectsResult a NamedTuple of
++ manifest_path - path name of the overriding manifest file instead
of None
++ fatal - True if caller should exit, Or False
+ _GetAllProjectsCommitIds returns CommitIdsResult a NamedTuple of
++ commit_ids - a dictionary with the projects/commit ids on success,
otherwise None
++ fatal - True if caller should exit, Or False
+ Added _SkipUpdatingProjectRevisionId a helper function to see if a
project's revision id needs to be updated or not. This function is
used to exclude projects from local manifest file.
+ Added the following error events into git_trace2_event_log
++ If superproject is missing in a manifest
++ If there are missing commit ids for projects.
command.py:
+ Deleted unused import - platform
+ Added git_trace2_event_log as a member so all subcmds can log error
events.
main.py:
+ Initialized git_trace2_event_log as a member of command object.
init.py:
+ Deleted unused import - optparse
init.py:
+ Called sys.exit only if Sync returns exit=True
sync.py:
+ Called sys.exit only if Superproject's UpdateProjectsRevisionId returns
exit=True
+ Reloaded the manifest only if manifest path is returned by
UpdateProjectsRevisionId. If not, fall back to the old way of doing
repo sync.
test_git_superproject:
+ Added code to verify error events are being logged.
+ Added a test for no superproject tag
+ Added test for UpdateProjectsRevisionId not updating the revision id
with the commit ids.
Tested the code with the following commands.
+ Positive test case with aosp-master.
$ repo_dev init -u persistent-https://android.git.corp.google.com/platform/manifest -b master --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in .../android/aosp
$ repo_dev sync -j40 --use-superproject
remote: Total 12 (delta 4), reused 12 (delta 4)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
...
repo sync has finished successfully.
+ Negative test case without superproject tag.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: .../android/aosp/.repo/manifest.xml
error: Cannot get project commit ids from manifest
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.589s
repo sync has finished successfully.
+ Test for missing commit_id for a project.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
error: please file a bug using go/repo-bug to report missing commit_ids for: ['build/blueprint']
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.364s
repo sync has finished successfully.
$ ./run_tests -v
...
...== 164 passed in 2.87s ==...
Bug: [google internal] b/189371541
Change-Id: I5ea49f87e8fa41be590fc0c914573e16c8cdfcfa
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309162
Tested-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
2021-06-12 00:29:45 +00:00
|
|
|
if manifest_path:
|
|
|
|
self._ReloadManifest(manifest_path, load_local_manifests)
|
|
|
|
else:
|
2021-08-13 18:47:24 +00:00
|
|
|
if print_messages:
|
|
|
|
print('warning: Update of revisionId from superproject has failed, '
|
|
|
|
'repo sync will not use superproject to fetch the source. ',
|
|
|
|
'Please resync with the --no-use-superproject option to avoid this repo warning.',
|
|
|
|
file=sys.stderr)
|
superproject - More friendly user message when superproject failed.
superproject is going to be default for some users. This change
doesn't fail for repo init or repo sync if source couldn't be synced
because of errors in superproject and superproject=true in the config
file. The commands will fail if --use-superproject is specified on
the command line explicitly.
The error messages are logged with trace2 event logs and will be
monitored.
+ sync - When there are errors with superproject and git_superproject
says it is fatal failure, sync will exit only when --use-superproject
option is specified on the command line.
+ init - command doesn't fail *if there are any superproject errors),
but it will print a warning message and logs message via trace2 event
logs. For fatal errors, init will exit only when --use-superproject
option is specified on the command line.
+ All git commands log the command that is being executed so trace2
event logs will know the manifest, remote url and the branch name.
There is no functional change other than fatal errors are honored with
--use-supeproject option with init/sync commands.
Tested the code with the following commands.
$ ./run_tests -v
Test 1 - sync'ing without errors
--------------------------------
Added the following lines to '~/.repoconfig/config
[repo]
superproject = true
$ repo_dev init -u https://android.googlesource.com/platform/manifest -b android-s-beta-2
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo: error: git fetch call failed, command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2
warning: git update of superproject failed, repo sync will not use superproject to fetch source; while this error is not fatal, and you can continue to run repo sync, please run repo init with the --no-use-superproject option to stop seeing this warning
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in /usr/local/google/home/rtenneti/work/drive2/android/test
$ repo_dev sync
remote: Total 4 (delta 1), reused 4 (delta 1)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
/usr/local/google/home/rtenneti/work/drive2/android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
...
Test 2 - init and sync fail when --use-superproject option is passed
--------------------------------------------------------------------
$ repo_dev init -u https://android.googlesource.com/platform/manifest -b android-s-beta-2 --use-superproject
remote: Total 57 (delta 16), reused 56 (delta 16)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo: error: git fetch call failed, command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2
warning: git update of superproject failed, repo sync will not use superproject to fetch source; while this error is not fatal, and you can continue to run repo sync, please run repo init with the --no-use-superproject option to stop seeing this warning
rtenneti@rtenneti2:~/work/drive2/android/test$ repo_dev sync --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo: error: git fetch call failed, command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2
warning: Cannot get project commit ids from manifest
warning: Update of revisionId from superproject has failed, repo sync will not use superproject to fetch the source. Please resync with the --no-use-superproject option to avoid this repo warning.
Test 3 - git fetch command fails and git command is printed
-----------------------------------------------------------
With config change
$ repo_dev init -u https://android.googlesource.com/platform/manifest -b android-s-beta-2
...
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/test/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Performing initial setup for superproject; this might take several minutes.
repo: error: git fetch call failed,command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2
warning: git update of superproject failed, repo sync will not use superproject to fetch source; while this error is not fatal and you can continue to run repo sync please run repo init with the --no-use-superproject option to avoid the repo warning
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in ....
Test 4 - no superproject tag
-----------------------------
$ repo_dev init -u https://android.googlesource.com/platform/manifest -b pie-dev
...
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: .../android/pie_dev/.repo/manifest.xml
warning: git update of superproject failed, repo sync will not use superproject to fetch source; while this error is not fatal and you can continue to run repo sync please run repo init with the --no-use-superproject option to avoid the repo warning
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in ...
$ repo_dev sync
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: /usr/local/google/home/rtenneti/work/drive2/android/pie_dev/.repo/manifest.xml
warning: Cannot get project commit ids from manifest
warning: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option to avoid the repo warning.
Bug: [google internal] b/192614798
Bug: [google internal] b/Bug: [google internal] b/192614798
Change-Id: I9a97a0e7d9e609fad151bd7dd9cfc523eaa887cd
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/311502
Reviewed-by: Amith Dsouza <amithds@google.com>
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Raman Tenneti <rtenneti@google.com>
2021-07-07 04:30:06 +00:00
|
|
|
if update_result.fatal and opt.use_superproject is not None:
|
superproject: Don't exit if superproject tag doesn't exist in manifest.
Don't exit if there are missing commit ids in superproject.
This change implements the following suggestion from delphij@:
"we should note the event (so we know that --use-superproject but there
were some errors, e.g. manifest didn't specify commit id for some
reason, or if there is no superproject but --use-superproject is
used), print out a message telling the use that this is not support,
but continue as if --no-use-superproject was specified?"
Changes:
superproject:
+ Added git_trace2_event_log as an argument to the constructor.
+ Sync method returns SyncResult a NamedTuple of
++ success - True if sync of superproject is successful, or False.
++ fatal - True if caller should exit, Or False.
+ UpdateProjectsRevisionId returns UpdateProjectsResult a NamedTuple of
++ manifest_path - path name of the overriding manifest file instead
of None
++ fatal - True if caller should exit, Or False
+ _GetAllProjectsCommitIds returns CommitIdsResult a NamedTuple of
++ commit_ids - a dictionary with the projects/commit ids on success,
otherwise None
++ fatal - True if caller should exit, Or False
+ Added _SkipUpdatingProjectRevisionId a helper function to see if a
project's revision id needs to be updated or not. This function is
used to exclude projects from local manifest file.
+ Added the following error events into git_trace2_event_log
++ If superproject is missing in a manifest
++ If there are missing commit ids for projects.
command.py:
+ Deleted unused import - platform
+ Added git_trace2_event_log as a member so all subcmds can log error
events.
main.py:
+ Initialized git_trace2_event_log as a member of command object.
init.py:
+ Deleted unused import - optparse
init.py:
+ Called sys.exit only if Sync returns exit=True
sync.py:
+ Called sys.exit only if Superproject's UpdateProjectsRevisionId returns
exit=True
+ Reloaded the manifest only if manifest path is returned by
UpdateProjectsRevisionId. If not, fall back to the old way of doing
repo sync.
test_git_superproject:
+ Added code to verify error events are being logged.
+ Added a test for no superproject tag
+ Added test for UpdateProjectsRevisionId not updating the revision id
with the commit ids.
Tested the code with the following commands.
+ Positive test case with aosp-master.
$ repo_dev init -u persistent-https://android.git.corp.google.com/platform/manifest -b master --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
Your identity is: Raman Tenneti <rtenneti@google.com>
If you want to change this, please re-run 'repo init' with --config-name
repo has been initialized in .../android/aosp
$ repo_dev sync -j40 --use-superproject
remote: Total 12 (delta 4), reused 12 (delta 4)
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
...
repo sync has finished successfully.
+ Negative test case without superproject tag.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
repo error: superproject tag is not defined in manifest: .../android/aosp/.repo/manifest.xml
error: Cannot get project commit ids from manifest
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.589s
repo sync has finished successfully.
+ Test for missing commit_id for a project.
$ repo_dev sync -j40 --use-superproject
NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version`
.../android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed.
error: please file a bug using go/repo-bug to report missing commit_ids for: ['build/blueprint']
error: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option
...
Checking out: 100% (1022/1022), done in 3.364s
repo sync has finished successfully.
$ ./run_tests -v
...
...== 164 passed in 2.87s ==...
Bug: [google internal] b/189371541
Change-Id: I5ea49f87e8fa41be590fc0c914573e16c8cdfcfa
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309162
Tested-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
2021-06-12 00:29:45 +00:00
|
|
|
sys.exit(1)
|
2021-02-04 22:39:38 +00:00
|
|
|
return manifest_path
|
|
|
|
|
2021-02-24 05:15:32 +00:00
|
|
|
def _FetchProjectList(self, opt, projects):
|
|
|
|
"""Main function of the fetch worker.
|
|
|
|
|
|
|
|
The projects we're given share the same underlying git object store, so we
|
|
|
|
have to fetch them in serial.
|
2012-11-14 02:36:51 +00:00
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
Delegates most of the work to _FetchHelper.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
opt: Program options returned from optparse. See _Options().
|
|
|
|
projects: Projects to fetch.
|
|
|
|
"""
|
2021-02-24 05:15:32 +00:00
|
|
|
return [self._FetchOne(opt, x) for x in projects]
|
2013-10-12 00:03:19 +00:00
|
|
|
|
2021-02-24 05:15:32 +00:00
|
|
|
def _FetchOne(self, opt, project):
|
2013-10-12 00:03:19 +00:00
|
|
|
"""Fetch git objects for a single project.
|
|
|
|
|
2012-11-14 02:36:51 +00:00
|
|
|
Args:
|
|
|
|
opt: Program options returned from optparse. See _Options().
|
|
|
|
project: Project object for the project to fetch.
|
2013-10-12 00:03:19 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Whether the fetch was successful.
|
2012-11-14 02:36:51 +00:00
|
|
|
"""
|
2017-04-05 07:02:59 +00:00
|
|
|
start = time.time()
|
|
|
|
success = False
|
2021-02-23 23:38:39 +00:00
|
|
|
buf = io.StringIO()
|
2012-11-14 02:36:51 +00:00
|
|
|
try:
|
2021-02-24 05:15:32 +00:00
|
|
|
success = project.Sync_NetworkHalf(
|
|
|
|
quiet=opt.quiet,
|
|
|
|
verbose=opt.verbose,
|
|
|
|
output_redir=buf,
|
|
|
|
current_branch_only=self._GetCurrentBranchOnly(opt),
|
|
|
|
force_sync=opt.force_sync,
|
|
|
|
clone_bundle=opt.clone_bundle,
|
|
|
|
tags=opt.tags, archive=self.manifest.IsArchive,
|
|
|
|
optimized_fetch=opt.optimized_fetch,
|
|
|
|
retry_fetches=opt.retry_fetches,
|
|
|
|
prune=opt.prune,
|
2021-05-06 04:44:42 +00:00
|
|
|
ssh_proxy=self.ssh_proxy,
|
2021-04-13 03:57:25 +00:00
|
|
|
clone_filter=self.manifest.CloneFilter,
|
|
|
|
partial_clone_exclude=self.manifest.PartialCloneExclude)
|
2021-02-24 05:15:32 +00:00
|
|
|
|
|
|
|
output = buf.getvalue()
|
2021-07-02 04:29:35 +00:00
|
|
|
if (opt.verbose or not success) and output:
|
2021-02-24 05:15:32 +00:00
|
|
|
print('\n' + output.rstrip())
|
|
|
|
|
|
|
|
if not success:
|
|
|
|
print('error: Cannot fetch %s from %s'
|
|
|
|
% (project.name, project.remote.url),
|
|
|
|
file=sys.stderr)
|
2021-04-15 16:20:51 +00:00
|
|
|
except GitError as e:
|
|
|
|
print('error.GitError: Cannot fetch %s' % str(e), file=sys.stderr)
|
2021-02-24 05:15:32 +00:00
|
|
|
except Exception as e:
|
|
|
|
print('error: Cannot fetch %s (%s: %s)'
|
|
|
|
% (project.name, type(e).__name__, str(e)), file=sys.stderr)
|
|
|
|
raise
|
2010-05-08 20:32:08 +00:00
|
|
|
|
2021-02-24 05:15:32 +00:00
|
|
|
finish = time.time()
|
|
|
|
return (success, project, start, finish)
|
2013-10-12 00:03:19 +00:00
|
|
|
|
2021-05-06 04:44:42 +00:00
|
|
|
@classmethod
|
|
|
|
def _FetchInitChild(cls, ssh_proxy):
|
|
|
|
cls.ssh_proxy = ssh_proxy
|
|
|
|
|
|
|
|
def _Fetch(self, projects, opt, err_event, ssh_proxy):
|
2021-02-24 05:15:32 +00:00
|
|
|
ret = True
|
|
|
|
|
2021-04-09 04:21:02 +00:00
|
|
|
jobs = opt.jobs_network if opt.jobs_network else self.jobs
|
2008-10-21 14:00:00 +00:00
|
|
|
fetched = set()
|
2021-04-13 19:07:21 +00:00
|
|
|
pm = Progress('Fetching', len(projects), delay=False, quiet=opt.quiet)
|
2010-05-08 20:32:08 +00:00
|
|
|
|
2014-01-10 02:51:58 +00:00
|
|
|
objdir_project_map = dict()
|
|
|
|
for project in projects:
|
|
|
|
objdir_project_map.setdefault(project.objdir, []).append(project)
|
2021-02-24 05:15:32 +00:00
|
|
|
projects_list = list(objdir_project_map.values())
|
|
|
|
|
|
|
|
def _ProcessResults(results_sets):
|
|
|
|
ret = True
|
|
|
|
for results in results_sets:
|
|
|
|
for (success, project, start, finish) in results:
|
|
|
|
self._fetch_times.Set(project, finish - start)
|
|
|
|
self.event_log.AddSync(project, event_log.TASK_SYNC_NETWORK,
|
|
|
|
start, finish, success)
|
|
|
|
# Check for any errors before running any more tasks.
|
|
|
|
# ...we'll let existing jobs finish, though.
|
|
|
|
if not success:
|
|
|
|
ret = False
|
|
|
|
else:
|
|
|
|
fetched.add(project.gitdir)
|
|
|
|
pm.update(msg=project.name)
|
|
|
|
if not ret and opt.fail_fast:
|
|
|
|
break
|
|
|
|
return ret
|
2014-01-10 02:51:58 +00:00
|
|
|
|
2021-05-06 04:44:42 +00:00
|
|
|
# We pass the ssh proxy settings via the class. This allows multiprocessing
|
|
|
|
# to pickle it up when spawning children. We can't pass it as an argument
|
|
|
|
# to _FetchProjectList below as multiprocessing is unable to pickle those.
|
|
|
|
Sync.ssh_proxy = None
|
|
|
|
|
2021-02-24 05:15:32 +00:00
|
|
|
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
2021-04-09 04:21:02 +00:00
|
|
|
if len(projects_list) == 1 or jobs == 1:
|
2021-05-06 04:44:42 +00:00
|
|
|
self._FetchInitChild(ssh_proxy)
|
2021-02-24 05:15:32 +00:00
|
|
|
if not _ProcessResults(self._FetchProjectList(opt, x) for x in projects_list):
|
|
|
|
ret = False
|
|
|
|
else:
|
|
|
|
# Favor throughput over responsiveness when quiet. It seems that imap()
|
|
|
|
# will yield results in batches relative to chunksize, so even as the
|
|
|
|
# children finish a sync, we won't see the result until one child finishes
|
|
|
|
# ~chunksize jobs. When using a large --jobs with large chunksize, this
|
|
|
|
# can be jarring as there will be a large initial delay where repo looks
|
|
|
|
# like it isn't doing anything and sits at 0%, but then suddenly completes
|
|
|
|
# a lot of jobs all at once. Since this code is more network bound, we
|
|
|
|
# can accept a bit more CPU overhead with a smaller chunksize so that the
|
|
|
|
# user sees more immediate & continuous feedback.
|
|
|
|
if opt.quiet:
|
|
|
|
chunksize = WORKER_BATCH_SIZE
|
2014-01-10 02:51:58 +00:00
|
|
|
else:
|
2021-02-24 05:15:32 +00:00
|
|
|
pm.update(inc=0, msg='warming up')
|
|
|
|
chunksize = 4
|
2021-05-06 04:44:42 +00:00
|
|
|
with multiprocessing.Pool(
|
|
|
|
jobs, initializer=self._FetchInitChild, initargs=(ssh_proxy,)) as pool:
|
2021-02-24 05:15:32 +00:00
|
|
|
results = pool.imap_unordered(
|
|
|
|
functools.partial(self._FetchProjectList, opt),
|
|
|
|
projects_list,
|
|
|
|
chunksize=chunksize)
|
|
|
|
if not _ProcessResults(results):
|
|
|
|
ret = False
|
|
|
|
pool.close()
|
2010-05-08 20:32:08 +00:00
|
|
|
|
2021-05-06 04:44:42 +00:00
|
|
|
# Cleanup the reference now that we're done with it, and we're going to
|
|
|
|
# release any resources it points to. If we don't, later multiprocessing
|
|
|
|
# usage (e.g. checkouts) will try to pickle and then crash.
|
|
|
|
del Sync.ssh_proxy
|
|
|
|
|
2009-04-10 23:48:52 +00:00
|
|
|
pm.end()
|
2012-10-23 22:00:54 +00:00
|
|
|
self._fetch_times.Save()
|
2012-10-24 00:02:59 +00:00
|
|
|
|
2013-10-16 09:02:35 +00:00
|
|
|
if not self.manifest.IsArchive:
|
2019-09-23 23:21:20 +00:00
|
|
|
self._GCProjects(projects, opt, err_event)
|
2013-10-16 09:02:35 +00:00
|
|
|
|
2021-02-24 05:15:32 +00:00
|
|
|
return (ret, fetched)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2021-05-06 00:03:26 +00:00
|
|
|
def _FetchMain(self, opt, args, all_projects, err_event, manifest_name,
|
2021-05-06 04:44:42 +00:00
|
|
|
load_local_manifests, ssh_proxy):
|
2021-05-06 00:03:26 +00:00
|
|
|
"""The main network fetch loop.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
opt: Program options returned from optparse. See _Options().
|
|
|
|
args: Command line args used to filter out projects.
|
2021-05-19 17:37:23 +00:00
|
|
|
all_projects: List of all projects that should be fetched.
|
2021-05-06 00:03:26 +00:00
|
|
|
err_event: Whether an error was hit while processing.
|
|
|
|
manifest_name: Manifest file to be reloaded.
|
|
|
|
load_local_manifests: Whether to load local manifests.
|
2021-05-06 04:44:42 +00:00
|
|
|
ssh_proxy: SSH manager for clients & masters.
|
2021-05-19 17:37:23 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
List of all projects that should be checked out.
|
2021-05-06 00:03:26 +00:00
|
|
|
"""
|
|
|
|
rp = self.manifest.repoProject
|
|
|
|
|
|
|
|
to_fetch = []
|
|
|
|
now = time.time()
|
|
|
|
if _ONE_DAY_S <= (now - rp.LastFetch):
|
|
|
|
to_fetch.append(rp)
|
|
|
|
to_fetch.extend(all_projects)
|
|
|
|
to_fetch.sort(key=self._fetch_times.Get, reverse=True)
|
|
|
|
|
2021-05-06 04:44:42 +00:00
|
|
|
success, fetched = self._Fetch(to_fetch, opt, err_event, ssh_proxy)
|
2021-05-06 00:03:26 +00:00
|
|
|
if not success:
|
|
|
|
err_event.set()
|
|
|
|
|
|
|
|
_PostRepoFetch(rp, opt.repo_verify)
|
|
|
|
if opt.network_only:
|
|
|
|
# bail out now; the rest touches the working tree
|
|
|
|
if err_event.is_set():
|
|
|
|
print('\nerror: Exited sync due to fetch errors.\n', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
return
|
|
|
|
|
|
|
|
# Iteratively fetch missing and/or nested unregistered submodules
|
|
|
|
previously_missing_set = set()
|
|
|
|
while True:
|
|
|
|
self._ReloadManifest(manifest_name, load_local_manifests)
|
|
|
|
all_projects = self.GetProjects(args,
|
|
|
|
missing_ok=True,
|
|
|
|
submodules_ok=opt.fetch_submodules)
|
|
|
|
missing = []
|
|
|
|
for project in all_projects:
|
|
|
|
if project.gitdir not in fetched:
|
|
|
|
missing.append(project)
|
|
|
|
if not missing:
|
|
|
|
break
|
|
|
|
# Stop us from non-stopped fetching actually-missing repos: If set of
|
|
|
|
# missing repos has not been changed from last fetch, we break.
|
|
|
|
missing_set = set(p.name for p in missing)
|
|
|
|
if previously_missing_set == missing_set:
|
|
|
|
break
|
|
|
|
previously_missing_set = missing_set
|
2021-05-06 04:44:42 +00:00
|
|
|
success, new_fetched = self._Fetch(missing, opt, err_event, ssh_proxy)
|
2021-05-06 00:03:26 +00:00
|
|
|
if not success:
|
|
|
|
err_event.set()
|
|
|
|
fetched.update(new_fetched)
|
|
|
|
|
2021-05-19 17:37:23 +00:00
|
|
|
return all_projects
|
|
|
|
|
2021-03-01 05:56:38 +00:00
|
|
|
def _CheckoutOne(self, detach_head, force_sync, project):
|
2019-06-03 18:24:30 +00:00
|
|
|
"""Checkout work tree for one project
|
|
|
|
|
|
|
|
Args:
|
2021-03-01 05:56:38 +00:00
|
|
|
detach_head: Whether to leave a detached HEAD.
|
|
|
|
force_sync: Force checking out of the repo.
|
2019-06-03 18:24:30 +00:00
|
|
|
project: Project object for the project to checkout.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Whether the fetch was successful.
|
|
|
|
"""
|
|
|
|
start = time.time()
|
|
|
|
syncbuf = SyncBuffer(self.manifest.manifestProject.config,
|
2021-03-01 05:56:38 +00:00
|
|
|
detach_head=detach_head)
|
2019-06-03 18:24:30 +00:00
|
|
|
success = False
|
|
|
|
try:
|
2021-03-01 05:56:38 +00:00
|
|
|
project.Sync_LocalHalf(syncbuf, force_sync=force_sync)
|
2021-02-24 01:48:04 +00:00
|
|
|
success = syncbuf.Finish()
|
2021-04-15 16:20:51 +00:00
|
|
|
except GitError as e:
|
|
|
|
print('error.GitError: Cannot checkout %s: %s' %
|
|
|
|
(project.name, str(e)), file=sys.stderr)
|
2021-02-24 01:48:04 +00:00
|
|
|
except Exception as e:
|
|
|
|
print('error: Cannot checkout %s: %s: %s' %
|
|
|
|
(project.name, type(e).__name__, str(e)),
|
|
|
|
file=sys.stderr)
|
|
|
|
raise
|
2019-06-03 18:24:30 +00:00
|
|
|
|
2021-02-24 01:48:04 +00:00
|
|
|
if not success:
|
|
|
|
print('error: Cannot checkout %s' % (project.name), file=sys.stderr)
|
|
|
|
finish = time.time()
|
|
|
|
return (success, project, start, finish)
|
2019-06-03 18:24:30 +00:00
|
|
|
|
2021-02-24 01:48:04 +00:00
|
|
|
def _Checkout(self, all_projects, opt, err_results):
|
2019-06-03 18:24:30 +00:00
|
|
|
"""Checkout projects listed in all_projects
|
|
|
|
|
|
|
|
Args:
|
|
|
|
all_projects: List of all projects that should be checked out.
|
|
|
|
opt: Program options returned from optparse. See _Options().
|
2021-02-24 01:48:04 +00:00
|
|
|
err_results: A list of strings, paths to git repos where checkout failed.
|
2019-06-03 18:24:30 +00:00
|
|
|
"""
|
2021-02-24 01:48:04 +00:00
|
|
|
# Only checkout projects with worktrees.
|
|
|
|
all_projects = [x for x in all_projects if x.worktree]
|
2019-06-03 18:24:30 +00:00
|
|
|
|
2021-03-01 05:56:38 +00:00
|
|
|
def _ProcessResults(pool, pm, results):
|
|
|
|
ret = True
|
2021-02-24 01:48:04 +00:00
|
|
|
for (success, project, start, finish) in results:
|
|
|
|
self.event_log.AddSync(project, event_log.TASK_SYNC_LOCAL,
|
|
|
|
start, finish, success)
|
|
|
|
# Check for any errors before running any more tasks.
|
2021-02-24 05:15:32 +00:00
|
|
|
# ...we'll let existing jobs finish, though.
|
2021-02-24 01:48:04 +00:00
|
|
|
if not success:
|
2021-03-01 05:56:38 +00:00
|
|
|
ret = False
|
2021-02-24 01:48:04 +00:00
|
|
|
err_results.append(project.relpath)
|
|
|
|
if opt.fail_fast:
|
2021-03-01 05:56:38 +00:00
|
|
|
if pool:
|
|
|
|
pool.close()
|
|
|
|
return ret
|
2021-02-24 01:48:04 +00:00
|
|
|
pm.update(msg=project.name)
|
2021-03-01 05:56:38 +00:00
|
|
|
return ret
|
2019-06-03 18:24:30 +00:00
|
|
|
|
2021-03-01 05:56:38 +00:00
|
|
|
return self.ExecuteInParallel(
|
|
|
|
opt.jobs_checkout if opt.jobs_checkout else self.jobs,
|
|
|
|
functools.partial(self._CheckoutOne, opt.detach_head, opt.force_sync),
|
|
|
|
all_projects,
|
|
|
|
callback=_ProcessResults,
|
|
|
|
output=Progress('Checking out', len(all_projects), quiet=opt.quiet)) and not err_results
|
2021-02-24 01:48:04 +00:00
|
|
|
|
2019-09-23 23:21:20 +00:00
|
|
|
def _GCProjects(self, projects, opt, err_event):
|
2021-04-13 19:07:21 +00:00
|
|
|
pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet)
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.update(inc=0, msg='prescan')
|
|
|
|
|
2014-10-10 00:54:35 +00:00
|
|
|
gc_gitdirs = {}
|
2013-10-12 00:03:19 +00:00
|
|
|
for project in projects:
|
2020-02-11 08:23:24 +00:00
|
|
|
# Make sure pruning never kicks in with shared projects.
|
2020-02-09 07:28:34 +00:00
|
|
|
if (not project.use_git_worktrees and
|
2020-02-20 01:47:26 +00:00
|
|
|
len(project.manifest.GetProjectsWithName(project.name)) > 1):
|
2021-01-18 09:32:36 +00:00
|
|
|
if not opt.quiet:
|
2021-04-09 02:47:44 +00:00
|
|
|
print('\r%s: Shared project %s found, disabling pruning.' %
|
2021-01-18 09:32:36 +00:00
|
|
|
(project.relpath, project.name))
|
2020-02-11 08:23:24 +00:00
|
|
|
if git_require((2, 7, 0)):
|
2020-02-19 20:50:00 +00:00
|
|
|
project.EnableRepositoryExtension('preciousObjects')
|
2020-02-11 08:23:24 +00:00
|
|
|
else:
|
|
|
|
# This isn't perfect, but it's the best we can do with old git.
|
2021-04-09 02:47:44 +00:00
|
|
|
print('\r%s: WARNING: shared projects are unreliable when using old '
|
2020-02-11 08:23:24 +00:00
|
|
|
'versions of git; please upgrade to git-2.7.0+.'
|
|
|
|
% (project.relpath,),
|
|
|
|
file=sys.stderr)
|
|
|
|
project.config.SetString('gc.pruneExpire', 'never')
|
2014-10-10 00:54:35 +00:00
|
|
|
gc_gitdirs[project.gitdir] = project.bare_git
|
2013-10-12 00:03:19 +00:00
|
|
|
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.update(inc=len(projects) - len(gc_gitdirs), msg='warming up')
|
|
|
|
|
|
|
|
cpu_count = os.cpu_count()
|
2012-10-24 00:02:59 +00:00
|
|
|
jobs = min(self.jobs, cpu_count)
|
|
|
|
|
|
|
|
if jobs < 2:
|
2014-10-10 00:54:35 +00:00
|
|
|
for bare_git in gc_gitdirs.values():
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.update(msg=bare_git._project.name)
|
2013-10-12 00:03:19 +00:00
|
|
|
bare_git.gc('--auto')
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.end()
|
2012-10-24 00:02:59 +00:00
|
|
|
return
|
|
|
|
|
2019-06-13 16:42:39 +00:00
|
|
|
config = {'pack.threads': cpu_count // jobs if cpu_count > jobs else 1}
|
2012-10-24 00:02:59 +00:00
|
|
|
|
|
|
|
threads = set()
|
|
|
|
sem = _threading.Semaphore(jobs)
|
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
def GC(bare_git):
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.start(bare_git._project.name)
|
2012-10-24 00:02:59 +00:00
|
|
|
try:
|
|
|
|
try:
|
2013-10-12 00:03:19 +00:00
|
|
|
bare_git.gc('--auto', config=config)
|
2012-10-24 00:02:59 +00:00
|
|
|
except GitError:
|
|
|
|
err_event.set()
|
2020-02-12 06:40:47 +00:00
|
|
|
except Exception:
|
2012-10-24 00:02:59 +00:00
|
|
|
err_event.set()
|
|
|
|
raise
|
|
|
|
finally:
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.finish(bare_git._project.name)
|
2012-10-24 00:02:59 +00:00
|
|
|
sem.release()
|
|
|
|
|
2014-10-10 00:54:35 +00:00
|
|
|
for bare_git in gc_gitdirs.values():
|
2021-02-23 08:24:12 +00:00
|
|
|
if err_event.is_set() and opt.fail_fast:
|
2012-10-24 00:02:59 +00:00
|
|
|
break
|
|
|
|
sem.acquire()
|
2013-10-12 00:03:19 +00:00
|
|
|
t = _threading.Thread(target=GC, args=(bare_git,))
|
2012-10-24 00:02:59 +00:00
|
|
|
t.daemon = True
|
|
|
|
threads.add(t)
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
2021-04-09 02:47:44 +00:00
|
|
|
pm.end()
|
2012-10-24 00:02:59 +00:00
|
|
|
|
2021-05-03 02:47:29 +00:00
|
|
|
def _ReloadManifest(self, manifest_name=None, load_local_manifests=True):
|
|
|
|
"""Reload the manfiest from the file specified by the |manifest_name|.
|
|
|
|
|
|
|
|
It unloads the manifest if |manifest_name| is None.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
manifest_name: Manifest file to be reloaded.
|
|
|
|
load_local_manifests: Whether to load local manifests.
|
|
|
|
"""
|
2013-03-08 23:02:49 +00:00
|
|
|
if manifest_name:
|
|
|
|
# Override calls _Unload already
|
2021-05-03 02:47:29 +00:00
|
|
|
self.manifest.Override(manifest_name, load_local_manifests=load_local_manifests)
|
2013-03-08 23:02:49 +00:00
|
|
|
else:
|
|
|
|
self.manifest._Unload()
|
|
|
|
|
2018-12-18 00:23:44 +00:00
|
|
|
def UpdateProjectList(self, opt):
|
2009-06-02 04:10:33 +00:00
|
|
|
new_project_paths = []
|
2012-03-29 03:15:45 +00:00
|
|
|
for project in self.GetProjects(None, missing_ok=True):
|
2009-06-04 23:18:09 +00:00
|
|
|
if project.relpath:
|
|
|
|
new_project_paths.append(project.relpath)
|
2009-06-02 04:10:33 +00:00
|
|
|
file_name = 'project.list'
|
2021-02-10 04:45:28 +00:00
|
|
|
file_path = os.path.join(self.repodir, file_name)
|
2009-06-02 04:10:33 +00:00
|
|
|
old_project_paths = []
|
|
|
|
|
|
|
|
if os.path.exists(file_path):
|
2019-11-11 10:40:22 +00:00
|
|
|
with open(file_path, 'r') as fd:
|
2009-06-02 04:10:33 +00:00
|
|
|
old_project_paths = fd.read().split('\n')
|
2019-04-05 16:49:47 +00:00
|
|
|
# In reversed order, so subfolders are deleted before parent folder.
|
|
|
|
for path in sorted(old_project_paths, reverse=True):
|
2009-06-04 23:18:09 +00:00
|
|
|
if not path:
|
|
|
|
continue
|
2009-06-02 04:10:33 +00:00
|
|
|
if path not in new_project_paths:
|
2012-09-24 03:15:13 +00:00
|
|
|
# If the path has already been deleted, we don't need to do it
|
On project cleanup, don't remove nested projects
When there are nested projects in a manifest, like on AOSP right now:
<project path="build" name="platform/build" />
<project path="build/blueprint" name="platform/build/blueprint" />
<project path="build/kati" name="platform/build/kati" />
<project path="build/soong" name="platform/build/soong" />
And the top "build" project is removed (or renamed to remove the
nesting), repo just wipes away everything under build/ and re-creates
the projects that are still there. But it only checks to see if the
build/ project is dirty, so if there are dirty files in a nested
project, they'll just be blown away, and a fresh worktree checked out.
Instead, behave similarly to how `git clean -dxf` behaves and preserve
any subdirectories that have git repositories in them. This isn't as
strict as git -- it does not check to see if the '.git' entry is a
readable gitdir, just whether an entry named '.git' exists.
If it encounters any errors removing files, we'll print them all out to
stderr and tell the user that we were unable to clean up the obsolete
project, that they should clean it up manually, then sync again.
Change-Id: I2f6a7dd205a8e0b7590ca5369e9b0ba21d5a6f77
2016-09-01 23:26:02 +00:00
|
|
|
gitdir = os.path.join(self.manifest.topdir, path, '.git')
|
|
|
|
if os.path.exists(gitdir):
|
2012-11-14 02:36:51 +00:00
|
|
|
project = Project(
|
2020-02-12 05:58:39 +00:00
|
|
|
manifest=self.manifest,
|
|
|
|
name=path,
|
|
|
|
remote=RemoteSpec('origin'),
|
|
|
|
gitdir=gitdir,
|
|
|
|
objdir=gitdir,
|
2020-02-20 00:19:18 +00:00
|
|
|
use_git_worktrees=os.path.isfile(gitdir),
|
2020-02-12 05:58:39 +00:00
|
|
|
worktree=os.path.join(self.manifest.topdir, path),
|
|
|
|
relpath=path,
|
|
|
|
revisionExpr='HEAD',
|
|
|
|
revisionId=None,
|
|
|
|
groups=None)
|
2020-02-20 00:19:18 +00:00
|
|
|
if not project.DeleteWorktree(
|
2020-02-20 01:47:26 +00:00
|
|
|
quiet=opt.quiet,
|
|
|
|
force=opt.force_remove_dirty):
|
2019-08-07 21:19:24 +00:00
|
|
|
return 1
|
2009-06-02 04:10:33 +00:00
|
|
|
|
2009-06-05 03:41:02 +00:00
|
|
|
new_project_paths.sort()
|
2019-11-11 10:40:22 +00:00
|
|
|
with open(file_path, 'w') as fd:
|
2009-06-02 04:10:33 +00:00
|
|
|
fd.write('\n'.join(new_project_paths))
|
2009-06-04 23:18:09 +00:00
|
|
|
fd.write('\n')
|
2009-06-02 04:10:33 +00:00
|
|
|
return 0
|
|
|
|
|
2021-04-25 12:02:02 +00:00
|
|
|
def UpdateCopyLinkfileList(self):
|
|
|
|
"""Save all dests of copyfile and linkfile, and update them if needed.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Whether update was successful.
|
|
|
|
"""
|
|
|
|
new_paths = {}
|
|
|
|
new_linkfile_paths = []
|
|
|
|
new_copyfile_paths = []
|
|
|
|
for project in self.GetProjects(None, missing_ok=True):
|
|
|
|
new_linkfile_paths.extend(x.dest for x in project.linkfiles)
|
|
|
|
new_copyfile_paths.extend(x.dest for x in project.copyfiles)
|
|
|
|
|
|
|
|
new_paths = {
|
|
|
|
'linkfile': new_linkfile_paths,
|
|
|
|
'copyfile': new_copyfile_paths,
|
|
|
|
}
|
|
|
|
|
|
|
|
copylinkfile_name = 'copy-link-files.json'
|
|
|
|
copylinkfile_path = os.path.join(self.manifest.repodir, copylinkfile_name)
|
|
|
|
old_copylinkfile_paths = {}
|
|
|
|
|
|
|
|
if os.path.exists(copylinkfile_path):
|
|
|
|
with open(copylinkfile_path, 'rb') as fp:
|
|
|
|
try:
|
|
|
|
old_copylinkfile_paths = json.load(fp)
|
|
|
|
except:
|
|
|
|
print('error: %s is not a json formatted file.' %
|
|
|
|
copylinkfile_path, file=sys.stderr)
|
|
|
|
platform_utils.remove(copylinkfile_path)
|
|
|
|
return False
|
|
|
|
|
|
|
|
need_remove_files = []
|
|
|
|
need_remove_files.extend(
|
|
|
|
set(old_copylinkfile_paths.get('linkfile', [])) -
|
|
|
|
set(new_linkfile_paths))
|
|
|
|
need_remove_files.extend(
|
|
|
|
set(old_copylinkfile_paths.get('copyfile', [])) -
|
|
|
|
set(new_copyfile_paths))
|
|
|
|
|
|
|
|
for need_remove_file in need_remove_files:
|
|
|
|
try:
|
|
|
|
platform_utils.remove(need_remove_file)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.ENOENT:
|
|
|
|
# Try to remove the updated copyfile or linkfile.
|
|
|
|
# So, if the file is not exist, nothing need to do.
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Create copy-link-files.json, save dest path of "copyfile" and "linkfile".
|
|
|
|
with open(copylinkfile_path, 'w', encoding='utf-8') as fp:
|
|
|
|
json.dump(new_paths, fp)
|
|
|
|
return True
|
|
|
|
|
2019-08-27 05:56:43 +00:00
|
|
|
def _SmartSyncSetup(self, opt, smart_sync_manifest_path):
|
|
|
|
if not self.manifest.manifest_server:
|
|
|
|
print('error: cannot smart sync: no manifest server defined in '
|
|
|
|
'manifest', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
manifest_server = self.manifest.manifest_server
|
|
|
|
if not opt.quiet:
|
|
|
|
print('Using manifest server %s' % manifest_server)
|
|
|
|
|
2020-02-12 02:24:10 +00:00
|
|
|
if '@' not in manifest_server:
|
2019-08-27 05:56:43 +00:00
|
|
|
username = None
|
|
|
|
password = None
|
|
|
|
if opt.manifest_server_username and opt.manifest_server_password:
|
|
|
|
username = opt.manifest_server_username
|
|
|
|
password = opt.manifest_server_password
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
info = netrc.netrc()
|
|
|
|
except IOError:
|
|
|
|
# .netrc file does not exist or could not be opened
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
parse_result = urllib.parse.urlparse(manifest_server)
|
|
|
|
if parse_result.hostname:
|
|
|
|
auth = info.authenticators(parse_result.hostname)
|
|
|
|
if auth:
|
|
|
|
username, _account, password = auth
|
|
|
|
else:
|
|
|
|
print('No credentials found for %s in .netrc'
|
|
|
|
% parse_result.hostname, file=sys.stderr)
|
|
|
|
except netrc.NetrcParseError as e:
|
|
|
|
print('Error parsing .netrc file: %s' % e, file=sys.stderr)
|
|
|
|
|
|
|
|
if (username and password):
|
|
|
|
manifest_server = manifest_server.replace('://', '://%s:%s@' %
|
|
|
|
(username, password),
|
|
|
|
1)
|
|
|
|
|
|
|
|
transport = PersistentTransport(manifest_server)
|
|
|
|
if manifest_server.startswith('persistent-'):
|
|
|
|
manifest_server = manifest_server[len('persistent-'):]
|
|
|
|
|
|
|
|
try:
|
|
|
|
server = xmlrpc.client.Server(manifest_server, transport=transport)
|
|
|
|
if opt.smart_sync:
|
2021-02-08 00:30:27 +00:00
|
|
|
branch = self._GetBranch()
|
2019-08-27 05:56:43 +00:00
|
|
|
|
2019-12-05 00:30:48 +00:00
|
|
|
if 'SYNC_TARGET' in os.environ:
|
2020-03-07 06:53:53 +00:00
|
|
|
target = os.environ['SYNC_TARGET']
|
2019-08-27 05:56:43 +00:00
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
2019-12-05 00:30:48 +00:00
|
|
|
elif ('TARGET_PRODUCT' in os.environ and
|
|
|
|
'TARGET_BUILD_VARIANT' in os.environ):
|
2020-03-07 06:53:53 +00:00
|
|
|
target = '%s-%s' % (os.environ['TARGET_PRODUCT'],
|
|
|
|
os.environ['TARGET_BUILD_VARIANT'])
|
2019-08-27 05:56:43 +00:00
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
|
|
|
else:
|
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch)
|
|
|
|
else:
|
|
|
|
assert(opt.smart_tag)
|
|
|
|
[success, manifest_str] = server.GetManifest(opt.smart_tag)
|
|
|
|
|
|
|
|
if success:
|
|
|
|
manifest_name = os.path.basename(smart_sync_manifest_path)
|
|
|
|
try:
|
2019-11-11 10:40:22 +00:00
|
|
|
with open(smart_sync_manifest_path, 'w') as f:
|
2019-08-27 05:56:43 +00:00
|
|
|
f.write(manifest_str)
|
|
|
|
except IOError as e:
|
|
|
|
print('error: cannot write manifest to %s:\n%s'
|
|
|
|
% (smart_sync_manifest_path, e),
|
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
self._ReloadManifest(manifest_name)
|
|
|
|
else:
|
|
|
|
print('error: manifest server RPC call failed: %s' %
|
|
|
|
manifest_str, file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
except (socket.error, IOError, xmlrpc.client.Fault) as e:
|
|
|
|
print('error: cannot connect to manifest server %s:\n%s'
|
|
|
|
% (self.manifest.manifest_server, e), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
except xmlrpc.client.ProtocolError as e:
|
|
|
|
print('error: cannot connect to manifest server %s:\n%d %s'
|
|
|
|
% (self.manifest.manifest_server, e.errcode, e.errmsg),
|
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
return manifest_name
|
|
|
|
|
2019-08-27 06:34:32 +00:00
|
|
|
def _UpdateManifestProject(self, opt, mp, manifest_name):
|
|
|
|
"""Fetch & update the local manifest project."""
|
|
|
|
if not opt.local_only:
|
|
|
|
start = time.time()
|
2020-02-17 06:51:49 +00:00
|
|
|
success = mp.Sync_NetworkHalf(quiet=opt.quiet, verbose=opt.verbose,
|
2021-03-23 22:12:27 +00:00
|
|
|
current_branch_only=self._GetCurrentBranchOnly(opt),
|
2019-06-18 11:49:12 +00:00
|
|
|
force_sync=opt.force_sync,
|
2020-02-17 19:36:08 +00:00
|
|
|
tags=opt.tags,
|
2019-08-27 06:34:32 +00:00
|
|
|
optimized_fetch=opt.optimized_fetch,
|
2020-04-02 18:36:09 +00:00
|
|
|
retry_fetches=opt.retry_fetches,
|
2019-08-27 06:34:32 +00:00
|
|
|
submodules=self.manifest.HasSubmodules,
|
2021-04-13 03:57:25 +00:00
|
|
|
clone_filter=self.manifest.CloneFilter,
|
|
|
|
partial_clone_exclude=self.manifest.PartialCloneExclude)
|
2019-08-27 06:34:32 +00:00
|
|
|
finish = time.time()
|
|
|
|
self.event_log.AddSync(mp, event_log.TASK_SYNC_NETWORK,
|
|
|
|
start, finish, success)
|
|
|
|
|
|
|
|
if mp.HasChanges:
|
|
|
|
syncbuf = SyncBuffer(mp.config)
|
|
|
|
start = time.time()
|
|
|
|
mp.Sync_LocalHalf(syncbuf, submodules=self.manifest.HasSubmodules)
|
|
|
|
clean = syncbuf.Finish()
|
|
|
|
self.event_log.AddSync(mp, event_log.TASK_SYNC_LOCAL,
|
|
|
|
start, time.time(), clean)
|
|
|
|
if not clean:
|
|
|
|
sys.exit(1)
|
2021-05-04 19:33:31 +00:00
|
|
|
self._ReloadManifest(manifest_name)
|
2019-08-27 06:34:32 +00:00
|
|
|
if opt.jobs is None:
|
|
|
|
self.jobs = self.manifest.default.sync_j
|
|
|
|
|
2019-08-27 05:10:59 +00:00
|
|
|
def ValidateOptions(self, opt, args):
|
2019-08-26 07:12:55 +00:00
|
|
|
if opt.force_broken:
|
|
|
|
print('warning: -f/--force-broken is now the default behavior, and the '
|
|
|
|
'options are deprecated', file=sys.stderr)
|
2009-04-10 23:59:36 +00:00
|
|
|
if opt.network_only and opt.detach_head:
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('cannot combine -n and -d')
|
2009-04-11 00:04:08 +00:00
|
|
|
if opt.network_only and opt.local_only:
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('cannot combine -n and -l')
|
2012-01-26 16:36:18 +00:00
|
|
|
if opt.manifest_name and opt.smart_sync:
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('cannot combine -m and -s')
|
2012-01-26 16:36:18 +00:00
|
|
|
if opt.manifest_name and opt.smart_tag:
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('cannot combine -m and -t')
|
2012-09-14 01:31:42 +00:00
|
|
|
if opt.manifest_server_username or opt.manifest_server_password:
|
|
|
|
if not (opt.smart_sync or opt.smart_tag):
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('-u and -p may only be combined with -s or -t')
|
2012-09-14 01:31:42 +00:00
|
|
|
if None in [opt.manifest_server_username, opt.manifest_server_password]:
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('both -u and -p must be given')
|
|
|
|
|
|
|
|
def Execute(self, opt, args):
|
|
|
|
if opt.jobs:
|
|
|
|
self.jobs = opt.jobs
|
|
|
|
if self.jobs > 1:
|
|
|
|
soft_limit, _ = _rlimit_nofile()
|
|
|
|
self.jobs = min(self.jobs, (soft_limit - 5) // 3)
|
2012-01-26 16:36:18 +00:00
|
|
|
|
|
|
|
if opt.manifest_name:
|
|
|
|
self.manifest.Override(opt.manifest_name)
|
2009-04-10 23:59:36 +00:00
|
|
|
|
2013-06-11 08:48:46 +00:00
|
|
|
manifest_name = opt.manifest_name
|
2015-05-07 05:36:09 +00:00
|
|
|
smart_sync_manifest_path = os.path.join(
|
2020-02-12 05:58:39 +00:00
|
|
|
self.manifest.manifestProject.worktree, 'smart_sync_override.xml')
|
2013-06-11 08:48:46 +00:00
|
|
|
|
2020-05-20 23:03:45 +00:00
|
|
|
if opt.clone_bundle is None:
|
|
|
|
opt.clone_bundle = self.manifest.CloneBundle
|
|
|
|
|
2011-04-19 08:32:52 +00:00
|
|
|
if opt.smart_sync or opt.smart_tag:
|
2019-08-27 05:56:43 +00:00
|
|
|
manifest_name = self._SmartSyncSetup(opt, smart_sync_manifest_path)
|
|
|
|
else:
|
2015-05-07 05:36:09 +00:00
|
|
|
if os.path.isfile(smart_sync_manifest_path):
|
|
|
|
try:
|
2016-11-11 22:25:29 +00:00
|
|
|
platform_utils.remove(smart_sync_manifest_path)
|
2015-05-07 05:36:09 +00:00
|
|
|
except OSError as e:
|
|
|
|
print('error: failed to remove existing smart sync override manifest: %s' %
|
|
|
|
e, file=sys.stderr)
|
2010-04-06 17:40:01 +00:00
|
|
|
|
2021-05-04 19:32:43 +00:00
|
|
|
err_event = multiprocessing.Event()
|
2019-09-23 23:21:20 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
rp = self.manifest.repoProject
|
|
|
|
rp.PreSync()
|
2020-02-29 07:52:44 +00:00
|
|
|
cb = rp.CurrentBranch
|
|
|
|
if cb:
|
|
|
|
base = rp.GetBranch(cb).merge
|
|
|
|
if not base or not base.startswith('refs/heads/'):
|
|
|
|
print('warning: repo is not tracking a remote branch, so it will not '
|
2020-03-14 18:35:26 +00:00
|
|
|
'receive updates; run `repo init --repo-rev=stable` to fix.',
|
2020-02-29 07:52:44 +00:00
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
mp = self.manifest.manifestProject
|
|
|
|
mp.PreSync()
|
|
|
|
|
2008-11-03 18:32:09 +00:00
|
|
|
if opt.repo_upgraded:
|
2012-10-26 19:23:05 +00:00
|
|
|
_PostRepoUpgrade(self.manifest, quiet=opt.quiet)
|
2008-11-03 18:32:09 +00:00
|
|
|
|
2019-11-22 08:04:31 +00:00
|
|
|
if not opt.mp_update:
|
|
|
|
print('Skipping update of local manifest project.')
|
|
|
|
else:
|
|
|
|
self._UpdateManifestProject(opt, mp, manifest_name)
|
2015-08-20 19:19:28 +00:00
|
|
|
|
2021-05-03 02:47:29 +00:00
|
|
|
load_local_manifests = not self.manifest.HasLocalManifests
|
2021-07-28 21:36:49 +00:00
|
|
|
use_superproject = git_superproject.UseSuperproject(opt, self.manifest)
|
|
|
|
superproject_logging_data = {
|
|
|
|
'superproject': use_superproject,
|
|
|
|
'haslocalmanifests': bool(self.manifest.HasLocalManifests),
|
2021-08-13 18:47:24 +00:00
|
|
|
'hassuperprojecttag': bool(self.manifest.superproject),
|
2021-07-28 21:36:49 +00:00
|
|
|
}
|
|
|
|
if use_superproject:
|
|
|
|
manifest_name = self._UpdateProjectsRevisionId(
|
|
|
|
opt, args, load_local_manifests, superproject_logging_data) or opt.manifest_name
|
2021-02-04 22:39:38 +00:00
|
|
|
|
2015-08-20 19:19:28 +00:00
|
|
|
if self.gitc_manifest:
|
|
|
|
gitc_manifest_projects = self.GetProjects(args,
|
|
|
|
missing_ok=True)
|
|
|
|
gitc_projects = []
|
|
|
|
opened_projects = []
|
|
|
|
for project in gitc_manifest_projects:
|
2015-09-08 20:27:20 +00:00
|
|
|
if project.relpath in self.gitc_manifest.paths and \
|
|
|
|
self.gitc_manifest.paths[project.relpath].old_revision:
|
|
|
|
opened_projects.append(project.relpath)
|
2015-08-20 19:19:28 +00:00
|
|
|
else:
|
2015-09-08 20:27:20 +00:00
|
|
|
gitc_projects.append(project.relpath)
|
2015-08-20 19:19:28 +00:00
|
|
|
|
2015-09-08 20:27:20 +00:00
|
|
|
if not args:
|
|
|
|
gitc_projects = None
|
|
|
|
|
|
|
|
if gitc_projects != [] and not opt.local_only:
|
2015-08-20 19:19:28 +00:00
|
|
|
print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name)
|
2015-09-08 20:27:20 +00:00
|
|
|
manifest = GitcManifest(self.repodir, self.gitc_manifest.gitc_client_name)
|
|
|
|
if manifest_name:
|
|
|
|
manifest.Override(manifest_name)
|
|
|
|
else:
|
|
|
|
manifest.Override(self.manifest.manifestFile)
|
|
|
|
gitc_utils.generate_gitc_manifest(self.gitc_manifest,
|
|
|
|
manifest,
|
2015-08-20 19:19:28 +00:00
|
|
|
gitc_projects)
|
|
|
|
print('GITC client successfully synced.')
|
|
|
|
|
|
|
|
# The opened projects need to be synced as normal, therefore we
|
|
|
|
# generate a new args list to represent the opened projects.
|
2015-09-08 20:27:20 +00:00
|
|
|
# TODO: make this more reliable -- if there's a project name/path overlap,
|
|
|
|
# this may choose the wrong project.
|
2017-07-10 13:42:22 +00:00
|
|
|
args = [os.path.relpath(self.manifest.paths[path].worktree, os.getcwd())
|
|
|
|
for path in opened_projects]
|
2015-08-20 19:19:28 +00:00
|
|
|
if not args:
|
|
|
|
return
|
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
|
|
|
all_projects = self.GetProjects(args,
|
|
|
|
missing_ok=True,
|
|
|
|
submodules_ok=opt.fetch_submodules)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2019-09-23 23:21:20 +00:00
|
|
|
err_network_sync = False
|
|
|
|
err_update_projects = False
|
|
|
|
|
2012-10-23 22:00:54 +00:00
|
|
|
self._fetch_times = _FetchTimes(self.manifest)
|
2009-04-11 00:04:08 +00:00
|
|
|
if not opt.local_only:
|
2021-05-06 04:44:42 +00:00
|
|
|
with multiprocessing.Manager() as manager:
|
|
|
|
with ssh.ProxyManager(manager) as ssh_proxy:
|
|
|
|
# Initialize the socket dir once in the parent.
|
|
|
|
ssh_proxy.sock()
|
2021-05-19 17:37:23 +00:00
|
|
|
all_projects = self._FetchMain(opt, args, all_projects, err_event,
|
|
|
|
manifest_name, load_local_manifests,
|
|
|
|
ssh_proxy)
|
2021-05-06 04:44:42 +00:00
|
|
|
|
|
|
|
if opt.network_only:
|
|
|
|
return
|
2019-09-23 23:21:20 +00:00
|
|
|
|
|
|
|
# If we saw an error, exit with code 1 so that other scripts can check.
|
2021-02-23 08:24:12 +00:00
|
|
|
if err_event.is_set():
|
2019-09-23 23:21:20 +00:00
|
|
|
err_network_sync = True
|
|
|
|
if opt.fail_fast:
|
|
|
|
print('\nerror: Exited sync due to fetch errors.\n'
|
|
|
|
'Local checkouts *not* updated. Resolve network issues & '
|
|
|
|
'retry.\n'
|
|
|
|
'`repo sync -l` will update some local checkouts.',
|
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
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
|
|
|
|
2013-10-16 09:02:35 +00:00
|
|
|
if self.manifest.IsMirror or self.manifest.IsArchive:
|
2009-06-04 23:15:53 +00:00
|
|
|
# bail out now, we have no working tree
|
|
|
|
return
|
|
|
|
|
2018-12-18 00:23:44 +00:00
|
|
|
if self.UpdateProjectList(opt):
|
2019-09-23 23:21:20 +00:00
|
|
|
err_event.set()
|
|
|
|
err_update_projects = True
|
|
|
|
if opt.fail_fast:
|
|
|
|
print('\nerror: Local checkouts *not* updated.', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2009-06-02 04:10:33 +00:00
|
|
|
|
2021-05-04 19:31:51 +00:00
|
|
|
err_update_linkfiles = not self.UpdateCopyLinkfileList()
|
|
|
|
if err_update_linkfiles:
|
2021-04-25 12:02:02 +00:00
|
|
|
err_event.set()
|
|
|
|
if opt.fail_fast:
|
|
|
|
print('\nerror: Local update copyfile or linkfile failed.', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-09-23 23:21:20 +00:00
|
|
|
err_results = []
|
2021-02-24 01:48:04 +00:00
|
|
|
# NB: We don't exit here because this is the last step.
|
|
|
|
err_checkout = not self._Checkout(all_projects, opt, err_results)
|
|
|
|
if err_checkout:
|
|
|
|
err_event.set()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2010-11-01 22:08:06 +00:00
|
|
|
# If there's a notice that's supposed to print at the end of the sync, print
|
|
|
|
# it now...
|
|
|
|
if self.manifest.notice:
|
2012-11-02 05:59:27 +00:00
|
|
|
print(self.manifest.notice)
|
2010-11-01 22:08:06 +00:00
|
|
|
|
2019-09-23 23:21:20 +00:00
|
|
|
# If we saw an error, exit with code 1 so that other scripts can check.
|
2021-02-23 08:24:12 +00:00
|
|
|
if err_event.is_set():
|
2019-09-23 23:21:20 +00:00
|
|
|
print('\nerror: Unable to fully sync the tree.', file=sys.stderr)
|
|
|
|
if err_network_sync:
|
|
|
|
print('error: Downloading network changes failed.', file=sys.stderr)
|
|
|
|
if err_update_projects:
|
|
|
|
print('error: Updating local project lists failed.', file=sys.stderr)
|
2021-04-25 12:02:02 +00:00
|
|
|
if err_update_linkfiles:
|
|
|
|
print('error: Updating copyfiles or linkfiles failed.', file=sys.stderr)
|
2019-09-23 23:21:20 +00:00
|
|
|
if err_checkout:
|
|
|
|
print('error: Checking out local projects failed.', file=sys.stderr)
|
|
|
|
if err_results:
|
|
|
|
print('Failing repos:\n%s' % '\n'.join(err_results), file=sys.stderr)
|
|
|
|
print('Try re-running with "-j1 --fail-fast" to exit at the first error.',
|
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-07-28 21:36:49 +00:00
|
|
|
# Log the previous sync analysis state from the config.
|
sync: Log repo sync state events as 'data' events.
git_trace2_event_log.py:
+ Added LogDataConfigEvents method to log 'data' events.
Sync's current_sync_state and previous_sync_state are logged
as 'data' events in the current log.
It logs are key/value in the |config| argument. Each key is
prefixed with |prefix| argument.
The following are sample events that are logged during repo sync.
{"event":"data",
"sid":"repo-20210914T181545Z-P000330c0/repo-20210914T181545Z-P000330c0",
"thread":"MainThread",
"time":"2021-09-14T18:16:19.935846Z",
"key":"previous_sync_state/repo.syncstate.main.synctime",
"value":"2021-09-14T17:27:11.573717Z"}
{"event":"data",
"sid":"repo-20210914T181545Z-P000330c0/repo-20210914T181545Z-P000330c0",
"thread":"MainThread",
"time":"2021-09-14T18:16:19.955546Z",
"key":"current_sync_state/repo.syncstate.main.synctime",
"value":"2021-09-14T18:16:19.935979Z"}
tests/test_git_trace2_event_log.py:
+ Added unit tests
sync.py:
+ Changed logging calls to LogDataConfigEvents.
Tested:
$ ./run_tests
Tested it by running the following command multiple times.
$ repo_dev sync -j 20
repo sync has finished successfully
Verified config data is looged in trace2 event logs.
Bug: [google internal] b/199758376
Change-Id: I75fd830e90c1811ec28510538c99a2632b104e85
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/317823
Reviewed-by: Josh Steadmon <steadmon@google.com>
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Raman Tenneti <rtenneti@google.com>
2021-09-14 00:40:07 +00:00
|
|
|
self.git_event_log.LogDataConfigEvents(mp.config.GetSyncAnalysisStateData(),
|
|
|
|
'previous_sync_state')
|
2021-07-28 21:36:49 +00:00
|
|
|
|
|
|
|
# Update and log with the new sync analysis state.
|
|
|
|
mp.config.UpdateSyncAnalysisState(opt, superproject_logging_data)
|
sync: Log repo sync state events as 'data' events.
git_trace2_event_log.py:
+ Added LogDataConfigEvents method to log 'data' events.
Sync's current_sync_state and previous_sync_state are logged
as 'data' events in the current log.
It logs are key/value in the |config| argument. Each key is
prefixed with |prefix| argument.
The following are sample events that are logged during repo sync.
{"event":"data",
"sid":"repo-20210914T181545Z-P000330c0/repo-20210914T181545Z-P000330c0",
"thread":"MainThread",
"time":"2021-09-14T18:16:19.935846Z",
"key":"previous_sync_state/repo.syncstate.main.synctime",
"value":"2021-09-14T17:27:11.573717Z"}
{"event":"data",
"sid":"repo-20210914T181545Z-P000330c0/repo-20210914T181545Z-P000330c0",
"thread":"MainThread",
"time":"2021-09-14T18:16:19.955546Z",
"key":"current_sync_state/repo.syncstate.main.synctime",
"value":"2021-09-14T18:16:19.935979Z"}
tests/test_git_trace2_event_log.py:
+ Added unit tests
sync.py:
+ Changed logging calls to LogDataConfigEvents.
Tested:
$ ./run_tests
Tested it by running the following command multiple times.
$ repo_dev sync -j 20
repo sync has finished successfully
Verified config data is looged in trace2 event logs.
Bug: [google internal] b/199758376
Change-Id: I75fd830e90c1811ec28510538c99a2632b104e85
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/317823
Reviewed-by: Josh Steadmon <steadmon@google.com>
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Raman Tenneti <rtenneti@google.com>
2021-09-14 00:40:07 +00:00
|
|
|
self.git_event_log.LogDataConfigEvents(mp.config.GetSyncAnalysisStateData(),
|
|
|
|
'current_sync_state')
|
2021-07-28 21:36:49 +00:00
|
|
|
|
2020-02-12 16:23:32 +00:00
|
|
|
if not opt.quiet:
|
|
|
|
print('repo sync has finished successfully.')
|
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2012-10-26 19:23:05 +00:00
|
|
|
def _PostRepoUpgrade(manifest, quiet=False):
|
2014-01-30 23:09:59 +00:00
|
|
|
wrapper = Wrapper()
|
2012-10-01 23:12:28 +00:00
|
|
|
if wrapper.NeedSetupGnuPG():
|
2012-10-26 19:23:05 +00:00
|
|
|
wrapper.SetupGnuPG(quiet)
|
2014-01-29 21:53:43 +00:00
|
|
|
for project in manifest.projects:
|
2009-04-13 18:51:15 +00:00
|
|
|
if project.Exists:
|
|
|
|
project.PostRepoUpgrade()
|
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2020-02-17 19:36:08 +00:00
|
|
|
def _PostRepoFetch(rp, repo_verify=True, verbose=False):
|
2009-04-13 18:51:15 +00:00
|
|
|
if rp.HasChanges:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('info: A new version of repo is available', file=sys.stderr)
|
2021-03-15 18:58:52 +00:00
|
|
|
wrapper = Wrapper()
|
|
|
|
try:
|
|
|
|
rev = rp.bare_git.describe(rp.GetRevisionId())
|
|
|
|
except GitError:
|
|
|
|
rev = None
|
|
|
|
_, new_rev = wrapper.check_repo_rev(rp.gitdir, rev, repo_verify=repo_verify)
|
|
|
|
# See if we're held back due to missing signed tag.
|
|
|
|
current_revid = rp.bare_git.rev_parse('HEAD')
|
|
|
|
new_revid = rp.bare_git.rev_parse('--verify', new_rev)
|
|
|
|
if current_revid != new_revid:
|
|
|
|
# We want to switch to the new rev, but also not trash any uncommitted
|
|
|
|
# changes. This helps with local testing/hacking.
|
|
|
|
# If a local change has been made, we will throw that away.
|
|
|
|
# We also have to make sure this will switch to an older commit if that's
|
|
|
|
# the latest tag in order to support release rollback.
|
|
|
|
try:
|
|
|
|
rp.work_git.reset('--keep', new_rev)
|
|
|
|
except GitError as e:
|
|
|
|
sys.exit(str(e))
|
2012-11-02 05:59:27 +00:00
|
|
|
print('info: Restarting repo with latest version', file=sys.stderr)
|
2009-04-13 18:51:15 +00:00
|
|
|
raise RepoChangedException(['--repo-upgraded'])
|
|
|
|
else:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('warning: Skipped upgrade to unverified version', file=sys.stderr)
|
2009-04-13 18:51:15 +00:00
|
|
|
else:
|
|
|
|
if verbose:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('repo version %s is current' % rp.work_git.describe(HEAD),
|
|
|
|
file=sys.stderr)
|
2009-04-13 18:51:15 +00:00
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2012-10-23 22:00:54 +00:00
|
|
|
class _FetchTimes(object):
|
2012-10-23 23:35:39 +00:00
|
|
|
_ALPHA = 0.5
|
|
|
|
|
2012-10-23 22:00:54 +00:00
|
|
|
def __init__(self, manifest):
|
2014-05-06 14:57:48 +00:00
|
|
|
self._path = os.path.join(manifest.repodir, '.repo_fetchtimes.json')
|
2012-10-23 22:00:54 +00:00
|
|
|
self._times = None
|
2012-10-23 23:35:39 +00:00
|
|
|
self._seen = set()
|
2012-10-23 22:00:54 +00:00
|
|
|
|
|
|
|
def Get(self, project):
|
|
|
|
self._Load()
|
|
|
|
return self._times.get(project.name, _ONE_DAY_S)
|
|
|
|
|
|
|
|
def Set(self, project, t):
|
2012-10-23 23:35:39 +00:00
|
|
|
self._Load()
|
|
|
|
name = project.name
|
|
|
|
old = self._times.get(name, t)
|
|
|
|
self._seen.add(name)
|
|
|
|
a = self._ALPHA
|
2020-02-12 05:31:05 +00:00
|
|
|
self._times[name] = (a * t) + ((1 - a) * old)
|
2012-10-23 22:00:54 +00:00
|
|
|
|
|
|
|
def _Load(self):
|
|
|
|
if self._times is None:
|
|
|
|
try:
|
2019-11-11 10:40:22 +00:00
|
|
|
with open(self._path) as f:
|
2014-05-06 14:57:48 +00:00
|
|
|
self._times = json.load(f)
|
|
|
|
except (IOError, ValueError):
|
|
|
|
try:
|
2016-11-11 22:25:29 +00:00
|
|
|
platform_utils.remove(self._path)
|
2014-05-06 14:57:48 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
self._times = {}
|
2012-10-23 22:00:54 +00:00
|
|
|
|
|
|
|
def Save(self):
|
|
|
|
if self._times is None:
|
|
|
|
return
|
2012-10-23 23:35:39 +00:00
|
|
|
|
|
|
|
to_delete = []
|
|
|
|
for name in self._times:
|
|
|
|
if name not in self._seen:
|
|
|
|
to_delete.append(name)
|
|
|
|
for name in to_delete:
|
|
|
|
del self._times[name]
|
|
|
|
|
2012-10-23 22:00:54 +00:00
|
|
|
try:
|
2019-11-11 10:40:22 +00:00
|
|
|
with open(self._path, 'w') as f:
|
2014-05-06 14:57:48 +00:00
|
|
|
json.dump(self._times, f, indent=2)
|
|
|
|
except (IOError, TypeError):
|
|
|
|
try:
|
2016-11-11 22:25:29 +00:00
|
|
|
platform_utils.remove(self._path)
|
2014-05-06 14:57:48 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
2015-08-17 20:41:45 +00:00
|
|
|
|
|
|
|
# This is a replacement for xmlrpc.client.Transport using urllib2
|
|
|
|
# and supporting persistent-http[s]. It cannot change hosts from
|
|
|
|
# request to request like the normal transport, the real url
|
|
|
|
# is passed during initialization.
|
2020-02-12 06:20:19 +00:00
|
|
|
|
|
|
|
|
2015-08-17 20:41:45 +00:00
|
|
|
class PersistentTransport(xmlrpc.client.Transport):
|
|
|
|
def __init__(self, orig_host):
|
|
|
|
self.orig_host = orig_host
|
|
|
|
|
|
|
|
def request(self, host, handler, request_body, verbose=False):
|
|
|
|
with GetUrlCookieFile(self.orig_host, not verbose) as (cookiefile, proxy):
|
|
|
|
# Python doesn't understand cookies with the #HttpOnly_ prefix
|
|
|
|
# Since we're only using them for HTTP, copy the file temporarily,
|
|
|
|
# stripping those prefixes away.
|
2015-08-20 17:09:20 +00:00
|
|
|
if cookiefile:
|
2020-02-18 18:57:32 +00:00
|
|
|
tmpcookiefile = tempfile.NamedTemporaryFile(mode='w')
|
2015-10-02 02:10:10 +00:00
|
|
|
tmpcookiefile.write("# HTTP Cookie File")
|
2015-08-20 17:09:20 +00:00
|
|
|
try:
|
|
|
|
with open(cookiefile) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith("#HttpOnly_"):
|
|
|
|
line = line[len("#HttpOnly_"):]
|
|
|
|
tmpcookiefile.write(line)
|
|
|
|
tmpcookiefile.flush()
|
|
|
|
|
|
|
|
cookiejar = cookielib.MozillaCookieJar(tmpcookiefile.name)
|
2015-09-30 01:35:43 +00:00
|
|
|
try:
|
|
|
|
cookiejar.load()
|
|
|
|
except cookielib.LoadError:
|
|
|
|
cookiejar = cookielib.CookieJar()
|
2015-08-20 17:09:20 +00:00
|
|
|
finally:
|
|
|
|
tmpcookiefile.close()
|
|
|
|
else:
|
|
|
|
cookiejar = cookielib.CookieJar()
|
2015-08-17 20:41:45 +00:00
|
|
|
|
|
|
|
proxyhandler = urllib.request.ProxyHandler
|
|
|
|
if proxy:
|
|
|
|
proxyhandler = urllib.request.ProxyHandler({
|
|
|
|
"http": proxy,
|
2020-02-12 05:31:05 +00:00
|
|
|
"https": proxy})
|
2015-08-17 20:41:45 +00:00
|
|
|
|
|
|
|
opener = urllib.request.build_opener(
|
|
|
|
urllib.request.HTTPCookieProcessor(cookiejar),
|
|
|
|
proxyhandler)
|
|
|
|
|
|
|
|
url = urllib.parse.urljoin(self.orig_host, handler)
|
|
|
|
parse_results = urllib.parse.urlparse(url)
|
|
|
|
|
|
|
|
scheme = parse_results.scheme
|
|
|
|
if scheme == 'persistent-http':
|
|
|
|
scheme = 'http'
|
|
|
|
if scheme == 'persistent-https':
|
|
|
|
# If we're proxying through persistent-https, use http. The
|
|
|
|
# proxy itself will do the https.
|
|
|
|
if proxy:
|
|
|
|
scheme = 'http'
|
|
|
|
else:
|
|
|
|
scheme = 'https'
|
|
|
|
|
|
|
|
# Parse out any authentication information using the base class
|
|
|
|
host, extra_headers, _ = self.get_host_info(parse_results.netloc)
|
|
|
|
|
|
|
|
url = urllib.parse.urlunparse((
|
|
|
|
scheme,
|
|
|
|
host,
|
|
|
|
parse_results.path,
|
|
|
|
parse_results.params,
|
|
|
|
parse_results.query,
|
|
|
|
parse_results.fragment))
|
|
|
|
|
|
|
|
request = urllib.request.Request(url, request_body)
|
|
|
|
if extra_headers is not None:
|
|
|
|
for (name, header) in extra_headers:
|
|
|
|
request.add_header(name, header)
|
|
|
|
request.add_header('Content-Type', 'text/xml')
|
|
|
|
try:
|
|
|
|
response = opener.open(request)
|
|
|
|
except urllib.error.HTTPError as e:
|
|
|
|
if e.code == 501:
|
|
|
|
# We may have been redirected through a login process
|
|
|
|
# but our POST turned into a GET. Retry.
|
|
|
|
response = opener.open(request)
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
p, u = xmlrpc.client.getparser()
|
|
|
|
while 1:
|
|
|
|
data = response.read(1024)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
p.feed(data)
|
|
|
|
p.close()
|
|
|
|
return u.close()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
pass
|