2008-10-21 14:00:00 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2008 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
from __future__ import print_function
|
2014-05-06 14:57:48 +00:00
|
|
|
import json
|
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
|
|
|
|
import re
|
2009-06-02 04:10:33 +00:00
|
|
|
import shutil
|
2010-04-06 17:40:01 +00:00
|
|
|
import socket
|
2008-10-21 14:00:00 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2015-08-17 20:41:45 +00:00
|
|
|
import tempfile
|
2009-04-18 17:49:00 +00:00
|
|
|
import time
|
2013-05-17 01:49:33 +00:00
|
|
|
|
|
|
|
from pyversion import is_python3
|
|
|
|
if is_python3():
|
2015-08-17 20:41:45 +00:00
|
|
|
import http.cookiejar as cookielib
|
|
|
|
import urllib.error
|
2013-03-01 13:44:38 +00:00
|
|
|
import urllib.parse
|
2015-08-17 20:41:45 +00:00
|
|
|
import urllib.request
|
2013-05-17 01:49:33 +00:00
|
|
|
import xmlrpc.client
|
|
|
|
else:
|
2015-08-17 20:41:45 +00:00
|
|
|
import cookielib
|
2013-03-01 13:44:38 +00:00
|
|
|
import imp
|
2015-08-17 20:41:45 +00:00
|
|
|
import urllib2
|
2013-03-01 13:44:38 +00:00
|
|
|
import urlparse
|
2013-05-17 01:49:33 +00:00
|
|
|
import xmlrpclib
|
2013-03-01 13:44:38 +00:00
|
|
|
urllib = imp.new_module('urllib')
|
2015-08-17 20:41:45 +00:00
|
|
|
urllib.error = urllib2
|
2013-06-11 08:12:25 +00:00
|
|
|
urllib.parse = urlparse
|
2015-08-17 20:41:45 +00:00
|
|
|
urllib.request = urllib2
|
2013-03-01 13:44:38 +00:00
|
|
|
xmlrpc = imp.new_module('xmlrpc')
|
|
|
|
xmlrpc.client = xmlrpclib
|
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
|
|
|
|
def _rlimit_nofile():
|
|
|
|
return resource.getrlimit(resource.RLIMIT_NOFILE)
|
|
|
|
except ImportError:
|
|
|
|
def _rlimit_nofile():
|
|
|
|
return (256, 256)
|
|
|
|
|
2012-10-24 00:02:59 +00:00
|
|
|
try:
|
|
|
|
import multiprocessing
|
|
|
|
except ImportError:
|
|
|
|
multiprocessing = None
|
|
|
|
|
2012-10-31 19:24:38 +00:00
|
|
|
from git_command import GIT, 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
|
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
|
2009-03-04 01:47:06 +00:00
|
|
|
from command import Command, MirrorSafeCommand
|
2012-12-05 10:58:06 +00:00
|
|
|
from error import RepoChangedException, GitError, ManifestParseError
|
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
|
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
|
|
|
|
|
2011-03-16 22:49:18 +00:00
|
|
|
class _FetchError(Exception):
|
|
|
|
"""Internal error thrown in _FetchHelper() when we don't want stack trace."""
|
|
|
|
pass
|
|
|
|
|
2009-03-04 01:47:06 +00:00
|
|
|
class Sync(Command, MirrorSafeCommand):
|
2010-05-08 20:32:08 +00:00
|
|
|
jobs = 1
|
2008-10-21 14:00:00 +00:00
|
|
|
common = True
|
|
|
|
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.
|
|
|
|
|
2010-07-02 22:58:31 +00:00
|
|
|
The -f/--force-broken option can be used to proceed with syncing
|
|
|
|
other projects if a project sync fails.
|
|
|
|
|
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
|
|
|
|
object direcotry. WARNING: This may cause data to be lost since
|
|
|
|
refs may be removed when overwriting.
|
|
|
|
|
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.
|
|
|
|
|
2009-04-21 15:02:04 +00:00
|
|
|
SSH Connections
|
|
|
|
---------------
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Compatibility
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
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
|
|
|
"""
|
|
|
|
|
2010-05-11 19:57:01 +00:00
|
|
|
def _Options(self, p, show_smart=True):
|
2012-12-05 10:58:06 +00:00
|
|
|
try:
|
|
|
|
self.jobs = self.manifest.default.sync_j
|
|
|
|
except ManifestParseError:
|
|
|
|
self.jobs = 1
|
2011-09-23 00:44:31 +00:00
|
|
|
|
2010-07-02 22:58:31 +00:00
|
|
|
p.add_option('-f', '--force-broken',
|
|
|
|
dest='force_broken', action='store_true',
|
|
|
|
help="continue sync even if a project fails to sync")
|
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")
|
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")
|
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')
|
2012-11-14 03:09:38 +00:00
|
|
|
p.add_option('-q', '--quiet',
|
2010-10-29 19:05:43 +00:00
|
|
|
dest='quiet', action='store_true',
|
|
|
|
help='be more quiet')
|
2012-11-14 03:09:38 +00:00
|
|
|
p.add_option('-j', '--jobs',
|
2010-05-08 20:32:08 +00:00
|
|
|
dest='jobs', action='store', type='int',
|
2011-09-23 00:44:31 +00:00
|
|
|
help="projects to fetch simultaneously (default %d)" % self.jobs)
|
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')
|
2012-03-14 22:36:59 +00:00
|
|
|
p.add_option('--no-clone-bundle',
|
|
|
|
dest='no_clone_bundle', action='store_true',
|
|
|
|
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')
|
2012-10-29 17:18:34 +00:00
|
|
|
p.add_option('--no-tags',
|
|
|
|
dest='no_tags', action='store_true',
|
|
|
|
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')
|
2010-05-11 19:57:01 +00:00
|
|
|
if show_smart:
|
|
|
|
p.add_option('-s', '--smart-sync',
|
|
|
|
dest='smart_sync', action='store_true',
|
|
|
|
help='smart sync using manifest from a 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',
|
2008-10-21 14:00:00 +00:00
|
|
|
dest='no_repo_verify', action='store_true',
|
|
|
|
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
|
|
|
|
2014-01-10 02:51:58 +00:00
|
|
|
def _FetchProjectList(self, opt, projects, *args, **kwargs):
|
2012-11-14 02:36:51 +00:00
|
|
|
"""Main function of the fetch threads when jobs are > 1.
|
|
|
|
|
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.
|
2014-01-10 02:51:58 +00:00
|
|
|
*args, **kwargs: Remaining arguments to pass to _FetchHelper. See the
|
2013-10-12 00:03:19 +00:00
|
|
|
_FetchHelper docstring for details.
|
|
|
|
"""
|
|
|
|
for project in projects:
|
2014-01-10 02:51:58 +00:00
|
|
|
success = self._FetchHelper(opt, project, *args, **kwargs)
|
2013-10-12 00:03:19 +00:00
|
|
|
if not success and not opt.force_broken:
|
|
|
|
break
|
|
|
|
|
|
|
|
def _FetchHelper(self, opt, project, lock, fetched, pm, sem, err_event):
|
|
|
|
"""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.
|
|
|
|
lock: Lock for accessing objects that are shared amongst multiple
|
|
|
|
_FetchHelper() threads.
|
|
|
|
fetched: set object that we will add project.gitdir to when we're done
|
|
|
|
(with our lock held).
|
|
|
|
pm: Instance of a Project object. We will call pm.update() (with our
|
|
|
|
lock held).
|
|
|
|
sem: We'll release() this semaphore when we exit so that another thread
|
|
|
|
can be started up.
|
|
|
|
err_event: We'll set this event in the case of an error (after printing
|
|
|
|
out info about the error).
|
2013-10-12 00:03:19 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Whether the fetch was successful.
|
2012-11-14 02:36:51 +00:00
|
|
|
"""
|
|
|
|
# We'll set to true once we've locked the lock.
|
|
|
|
did_lock = False
|
|
|
|
|
2013-04-12 09:24:32 +00:00
|
|
|
if not opt.quiet:
|
|
|
|
print('Fetching project %s' % project.name)
|
|
|
|
|
2012-11-14 02:36:51 +00:00
|
|
|
# Encapsulate everything in a try/except/finally so that:
|
|
|
|
# - We always set err_event in the case of an exception.
|
|
|
|
# - We always make sure we call sem.release().
|
|
|
|
# - We always make sure we unlock the lock if we locked it.
|
|
|
|
try:
|
2011-03-16 22:49:18 +00:00
|
|
|
try:
|
2012-11-14 02:36:51 +00:00
|
|
|
start = time.time()
|
|
|
|
success = project.Sync_NetworkHalf(
|
|
|
|
quiet=opt.quiet,
|
|
|
|
current_branch_only=opt.current_branch_only,
|
2014-11-12 18:27:45 +00:00
|
|
|
force_sync=opt.force_sync,
|
2012-10-29 17:18:34 +00:00
|
|
|
clone_bundle=not opt.no_clone_bundle,
|
2014-09-04 12:28:09 +00:00
|
|
|
no_tags=opt.no_tags, archive=self.manifest.IsArchive,
|
|
|
|
optimized_fetch=opt.optimized_fetch)
|
2012-11-14 02:36:51 +00:00
|
|
|
self._fetch_times.Set(project, time.time() - start)
|
|
|
|
|
|
|
|
# Lock around all the rest of the code, since printing, updating a set
|
|
|
|
# and Progress.update() are not thread safe.
|
|
|
|
lock.acquire()
|
|
|
|
did_lock = True
|
|
|
|
|
|
|
|
if not success:
|
|
|
|
print('error: Cannot fetch %s' % project.name, file=sys.stderr)
|
|
|
|
if opt.force_broken:
|
|
|
|
print('warn: --force-broken, continuing to sync',
|
|
|
|
file=sys.stderr)
|
|
|
|
else:
|
|
|
|
raise _FetchError()
|
2011-03-16 22:49:18 +00:00
|
|
|
|
2012-11-14 02:36:51 +00:00
|
|
|
fetched.add(project.gitdir)
|
|
|
|
pm.update()
|
|
|
|
except _FetchError:
|
|
|
|
err_event.set()
|
2015-07-31 13:37:53 +00:00
|
|
|
except Exception as e:
|
|
|
|
print('error: Cannot fetch %s (%s: %s)' \
|
|
|
|
% (project.name, type(e).__name__, str(e)), file=sys.stderr)
|
2012-11-14 02:36:51 +00:00
|
|
|
err_event.set()
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
if did_lock:
|
|
|
|
lock.release()
|
|
|
|
sem.release()
|
2010-05-08 20:32:08 +00:00
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
return success
|
|
|
|
|
2010-10-29 19:05:43 +00:00
|
|
|
def _Fetch(self, projects, opt):
|
2008-10-21 14:00:00 +00:00
|
|
|
fetched = set()
|
2014-01-10 02:51:58 +00:00
|
|
|
lock = _threading.Lock()
|
2009-04-10 23:48:52 +00:00
|
|
|
pm = Progress('Fetching projects', len(projects))
|
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)
|
|
|
|
|
|
|
|
threads = set()
|
|
|
|
sem = _threading.Semaphore(self.jobs)
|
|
|
|
err_event = _threading.Event()
|
|
|
|
for project_list in objdir_project_map.values():
|
|
|
|
# Check for any errors before running any more tasks.
|
|
|
|
# ...we'll let existing threads finish, though.
|
|
|
|
if err_event.isSet() and not opt.force_broken:
|
|
|
|
break
|
|
|
|
|
|
|
|
sem.acquire()
|
|
|
|
kwargs = dict(opt=opt,
|
|
|
|
projects=project_list,
|
|
|
|
lock=lock,
|
|
|
|
fetched=fetched,
|
|
|
|
pm=pm,
|
|
|
|
sem=sem,
|
|
|
|
err_event=err_event)
|
|
|
|
if self.jobs > 1:
|
2013-10-12 00:03:19 +00:00
|
|
|
t = _threading.Thread(target = self._FetchProjectList,
|
2014-01-10 02:51:58 +00:00
|
|
|
kwargs = kwargs)
|
2012-09-05 08:35:06 +00:00
|
|
|
# Ensure that Ctrl-C will not freeze the repo process.
|
|
|
|
t.daemon = True
|
2010-05-08 20:32:08 +00:00
|
|
|
threads.add(t)
|
|
|
|
t.start()
|
2014-01-10 02:51:58 +00:00
|
|
|
else:
|
|
|
|
self._FetchProjectList(**kwargs)
|
2010-05-08 20:32:08 +00:00
|
|
|
|
2014-01-10 02:51:58 +00:00
|
|
|
for t in threads:
|
|
|
|
t.join()
|
2010-05-08 20:32:08 +00:00
|
|
|
|
2014-01-10 02:51:58 +00:00
|
|
|
# If we saw an error, exit with code 1 so that other scripts can check.
|
|
|
|
if err_event.isSet():
|
|
|
|
print('\nerror: Exited sync due to fetch errors', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2011-03-16 22:49:18 +00:00
|
|
|
|
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:
|
|
|
|
self._GCProjects(projects)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
return fetched
|
|
|
|
|
2012-10-24 00:02:59 +00:00
|
|
|
def _GCProjects(self, projects):
|
2013-10-12 00:03:19 +00:00
|
|
|
gitdirs = {}
|
|
|
|
for project in projects:
|
|
|
|
gitdirs[project.gitdir] = project.bare_git
|
|
|
|
|
2012-10-31 19:24:38 +00:00
|
|
|
has_dash_c = git_require((1, 7, 2))
|
|
|
|
if multiprocessing and has_dash_c:
|
2012-10-24 00:02:59 +00:00
|
|
|
cpu_count = multiprocessing.cpu_count()
|
|
|
|
else:
|
|
|
|
cpu_count = 1
|
|
|
|
jobs = min(self.jobs, cpu_count)
|
|
|
|
|
|
|
|
if jobs < 2:
|
2013-10-12 00:03:19 +00:00
|
|
|
for bare_git in gitdirs.values():
|
|
|
|
bare_git.gc('--auto')
|
2012-10-24 00:02:59 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
config = {'pack.threads': cpu_count / jobs if cpu_count > jobs else 1}
|
|
|
|
|
|
|
|
threads = set()
|
|
|
|
sem = _threading.Semaphore(jobs)
|
|
|
|
err_event = _threading.Event()
|
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
def GC(bare_git):
|
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()
|
|
|
|
except:
|
|
|
|
err_event.set()
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
sem.release()
|
|
|
|
|
2013-10-12 00:03:19 +00:00
|
|
|
for bare_git in gitdirs.values():
|
2012-10-24 00:02:59 +00:00
|
|
|
if err_event.isSet():
|
|
|
|
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()
|
|
|
|
|
|
|
|
if err_event.isSet():
|
2012-11-02 05:59:27 +00:00
|
|
|
print('\nerror: Exited sync due to gc errors', file=sys.stderr)
|
2012-10-24 00:02:59 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2013-03-08 23:02:49 +00:00
|
|
|
def _ReloadManifest(self, manifest_name=None):
|
|
|
|
if manifest_name:
|
|
|
|
# Override calls _Unload already
|
|
|
|
self.manifest.Override(manifest_name)
|
|
|
|
else:
|
|
|
|
self.manifest._Unload()
|
|
|
|
|
2009-06-02 04:10:33 +00:00
|
|
|
def UpdateProjectList(self):
|
|
|
|
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'
|
|
|
|
file_path = os.path.join(self.manifest.repodir, file_name)
|
|
|
|
old_project_paths = []
|
|
|
|
|
|
|
|
if os.path.exists(file_path):
|
|
|
|
fd = open(file_path, 'r')
|
|
|
|
try:
|
|
|
|
old_project_paths = fd.read().split('\n')
|
|
|
|
finally:
|
|
|
|
fd.close()
|
|
|
|
for path in old_project_paths:
|
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
|
2009-09-26 17:38:52 +00:00
|
|
|
if os.path.exists(self.manifest.topdir + '/' + path):
|
2013-10-12 00:03:19 +00:00
|
|
|
gitdir = os.path.join(self.manifest.topdir, path, '.git')
|
2012-11-14 02:36:51 +00:00
|
|
|
project = Project(
|
|
|
|
manifest = self.manifest,
|
|
|
|
name = path,
|
|
|
|
remote = RemoteSpec('origin'),
|
2013-10-12 00:03:19 +00:00
|
|
|
gitdir = gitdir,
|
|
|
|
objdir = gitdir,
|
2012-11-14 02:36:51 +00:00
|
|
|
worktree = os.path.join(self.manifest.topdir, path),
|
|
|
|
relpath = path,
|
|
|
|
revisionExpr = 'HEAD',
|
|
|
|
revisionId = None,
|
|
|
|
groups = None)
|
|
|
|
|
|
|
|
if project.IsDirty():
|
2013-03-05 08:26:46 +00:00
|
|
|
print('error: Cannot remove project "%s": uncommitted changes '
|
2012-11-14 02:36:51 +00:00
|
|
|
'are present' % project.relpath, file=sys.stderr)
|
|
|
|
print(' commit changes, then run sync again',
|
|
|
|
file=sys.stderr)
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
print('Deleting obsolete path %s' % project.worktree,
|
|
|
|
file=sys.stderr)
|
|
|
|
shutil.rmtree(project.worktree)
|
|
|
|
# Try deleting parent subdirs if they are empty
|
|
|
|
project_dir = os.path.dirname(project.worktree)
|
|
|
|
while project_dir != self.manifest.topdir:
|
|
|
|
try:
|
|
|
|
os.rmdir(project_dir)
|
|
|
|
except OSError:
|
|
|
|
break
|
|
|
|
project_dir = os.path.dirname(project_dir)
|
2009-06-02 04:10:33 +00:00
|
|
|
|
2009-06-05 03:41:02 +00:00
|
|
|
new_project_paths.sort()
|
2009-06-02 04:10:33 +00:00
|
|
|
fd = open(file_path, 'w')
|
|
|
|
try:
|
|
|
|
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
|
|
|
finally:
|
|
|
|
fd.close()
|
|
|
|
return 0
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def Execute(self, opt, args):
|
2010-05-08 20:32:08 +00:00
|
|
|
if opt.jobs:
|
|
|
|
self.jobs = opt.jobs
|
2011-09-23 00:23:41 +00:00
|
|
|
if self.jobs > 1:
|
|
|
|
soft_limit, _ = _rlimit_nofile()
|
|
|
|
self.jobs = min(self.jobs, (soft_limit - 5) / 3)
|
|
|
|
|
2009-04-10 23:59:36 +00:00
|
|
|
if opt.network_only and opt.detach_head:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: cannot combine -n and -d', file=sys.stderr)
|
2009-04-10 23:59:36 +00:00
|
|
|
sys.exit(1)
|
2009-04-11 00:04:08 +00:00
|
|
|
if opt.network_only and opt.local_only:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: cannot combine -n and -l', file=sys.stderr)
|
2009-04-11 00:04:08 +00:00
|
|
|
sys.exit(1)
|
2012-01-26 16:36:18 +00:00
|
|
|
if opt.manifest_name and opt.smart_sync:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: cannot combine -m and -s', file=sys.stderr)
|
2012-01-26 16:36:18 +00:00
|
|
|
sys.exit(1)
|
|
|
|
if opt.manifest_name and opt.smart_tag:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: cannot combine -m and -t', file=sys.stderr)
|
2012-01-26 16:36:18 +00:00
|
|
|
sys.exit(1)
|
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):
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: -u and -p may only be combined with -s or -t',
|
|
|
|
file=sys.stderr)
|
2012-09-14 01:31:42 +00:00
|
|
|
sys.exit(1)
|
|
|
|
if None in [opt.manifest_server_username, opt.manifest_server_password]:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: both -u and -p must be given', file=sys.stderr)
|
2012-09-14 01:31:42 +00:00
|
|
|
sys.exit(1)
|
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_name = "smart_sync_override.xml"
|
|
|
|
smart_sync_manifest_path = os.path.join(
|
|
|
|
self.manifest.manifestProject.worktree, smart_sync_manifest_name)
|
2013-06-11 08:48:46 +00:00
|
|
|
|
2011-04-19 08:32:52 +00:00
|
|
|
if opt.smart_sync or opt.smart_tag:
|
2010-04-06 17:40:01 +00:00
|
|
|
if not self.manifest.manifest_server:
|
2013-03-05 08:26:46 +00:00
|
|
|
print('error: cannot smart sync: no manifest server defined in '
|
2012-11-02 05:59:27 +00:00
|
|
|
'manifest', file=sys.stderr)
|
2010-04-06 17:40:01 +00:00
|
|
|
sys.exit(1)
|
2012-08-24 01:21:02 +00:00
|
|
|
|
|
|
|
manifest_server = self.manifest.manifest_server
|
2013-09-25 02:09:34 +00:00
|
|
|
if not opt.quiet:
|
|
|
|
print('Using manifest server %s' % manifest_server)
|
2012-09-14 01:31:42 +00:00
|
|
|
|
2012-08-24 01:21:02 +00:00
|
|
|
if not '@' in manifest_server:
|
2012-09-14 01:31:42 +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
|
2012-08-24 01:21:02 +00:00
|
|
|
else:
|
|
|
|
try:
|
2012-09-14 01:31:42 +00:00
|
|
|
info = netrc.netrc()
|
|
|
|
except IOError:
|
2015-08-20 07:55:42 +00:00
|
|
|
# .netrc file does not exist or could not be opened
|
|
|
|
pass
|
2012-08-24 01:21:02 +00:00
|
|
|
else:
|
2012-09-14 01:31:42 +00:00
|
|
|
try:
|
2013-06-11 08:12:25 +00:00
|
|
|
parse_result = urllib.parse.urlparse(manifest_server)
|
2012-09-14 01:31:42 +00:00
|
|
|
if parse_result.hostname:
|
2015-08-20 07:55:42 +00:00
|
|
|
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)
|
2012-09-09 22:37:57 +00:00
|
|
|
except netrc.NetrcParseError as e:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('Error parsing .netrc file: %s' % e, file=sys.stderr)
|
2012-09-14 01:31:42 +00:00
|
|
|
|
|
|
|
if (username and password):
|
|
|
|
manifest_server = manifest_server.replace('://', '://%s:%s@' %
|
|
|
|
(username, password),
|
|
|
|
1)
|
2012-08-24 01:21:02 +00:00
|
|
|
|
2015-08-17 20:41:45 +00:00
|
|
|
transport = PersistentTransport(manifest_server)
|
|
|
|
if manifest_server.startswith('persistent-'):
|
|
|
|
manifest_server = manifest_server[len('persistent-'):]
|
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
try:
|
2015-08-17 20:41:45 +00:00
|
|
|
server = xmlrpc.client.Server(manifest_server, transport=transport)
|
2011-04-19 08:32:52 +00:00
|
|
|
if opt.smart_sync:
|
|
|
|
p = self.manifest.manifestProject
|
|
|
|
b = p.GetBranch(p.CurrentBranch)
|
|
|
|
branch = b.merge
|
|
|
|
if branch.startswith(R_HEADS):
|
|
|
|
branch = branch[len(R_HEADS):]
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
2014-10-02 17:13:38 +00:00
|
|
|
if 'SYNC_TARGET' in env:
|
|
|
|
target = env['SYNC_TARGET']
|
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
|
|
|
elif 'TARGET_PRODUCT' in env and 'TARGET_BUILD_VARIANT' in env:
|
2011-04-19 08:32:52 +00:00
|
|
|
target = '%s-%s' % (env['TARGET_PRODUCT'],
|
|
|
|
env['TARGET_BUILD_VARIANT'])
|
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
|
|
|
else:
|
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch)
|
2010-04-06 17:40:01 +00:00
|
|
|
else:
|
2011-04-19 08:32:52 +00:00
|
|
|
assert(opt.smart_tag)
|
|
|
|
[success, manifest_str] = server.GetManifest(opt.smart_tag)
|
2010-04-06 17:40:01 +00:00
|
|
|
|
|
|
|
if success:
|
2015-05-07 05:36:09 +00:00
|
|
|
manifest_name = smart_sync_manifest_name
|
2010-04-06 17:40:01 +00:00
|
|
|
try:
|
2015-05-07 05:36:09 +00:00
|
|
|
f = open(smart_sync_manifest_path, 'w')
|
2010-04-06 17:40:01 +00:00
|
|
|
try:
|
|
|
|
f.write(manifest_str)
|
|
|
|
finally:
|
|
|
|
f.close()
|
2015-05-07 05:16:49 +00:00
|
|
|
except IOError as e:
|
|
|
|
print('error: cannot write manifest to %s:\n%s'
|
2015-05-07 05:36:09 +00:00
|
|
|
% (smart_sync_manifest_path, e),
|
2012-11-02 05:59:27 +00:00
|
|
|
file=sys.stderr)
|
2010-04-06 17:40:01 +00:00
|
|
|
sys.exit(1)
|
2013-03-19 11:20:52 +00:00
|
|
|
self._ReloadManifest(manifest_name)
|
2010-04-06 17:40:01 +00:00
|
|
|
else:
|
2013-09-25 08:54:26 +00:00
|
|
|
print('error: manifest server RPC call failed: %s' %
|
|
|
|
manifest_str, file=sys.stderr)
|
2010-04-06 17:40:01 +00:00
|
|
|
sys.exit(1)
|
2013-03-01 13:44:38 +00:00
|
|
|
except (socket.error, IOError, xmlrpc.client.Fault) as e:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: cannot connect to manifest server %s:\n%s'
|
|
|
|
% (self.manifest.manifest_server, e), file=sys.stderr)
|
2012-08-23 01:21:26 +00:00
|
|
|
sys.exit(1)
|
2013-03-01 13:44:38 +00:00
|
|
|
except xmlrpc.client.ProtocolError as e:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('error: cannot connect to manifest server %s:\n%d %s'
|
|
|
|
% (self.manifest.manifest_server, e.errcode, e.errmsg),
|
|
|
|
file=sys.stderr)
|
2010-04-06 17:40:01 +00:00
|
|
|
sys.exit(1)
|
2015-05-07 05:36:09 +00:00
|
|
|
else: # Not smart sync or smart tag mode
|
|
|
|
if os.path.isfile(smart_sync_manifest_path):
|
|
|
|
try:
|
|
|
|
os.remove(smart_sync_manifest_path)
|
|
|
|
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
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
rp = self.manifest.repoProject
|
|
|
|
rp.PreSync()
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-12-07 23:38:01 +00:00
|
|
|
if not opt.local_only:
|
2011-08-26 00:21:47 +00:00
|
|
|
mp.Sync_NetworkHalf(quiet=opt.quiet,
|
2012-10-29 17:18:34 +00:00
|
|
|
current_branch_only=opt.current_branch_only,
|
2014-09-04 12:28:09 +00:00
|
|
|
no_tags=opt.no_tags,
|
|
|
|
optimized_fetch=opt.optimized_fetch)
|
2009-12-07 23:38:01 +00:00
|
|
|
|
|
|
|
if mp.HasChanges:
|
|
|
|
syncbuf = SyncBuffer(mp.config)
|
|
|
|
mp.Sync_LocalHalf(syncbuf)
|
|
|
|
if not syncbuf.Finish():
|
|
|
|
sys.exit(1)
|
2013-03-19 11:20:52 +00:00
|
|
|
self._ReloadManifest(manifest_name)
|
2011-09-26 16:08:01 +00:00
|
|
|
if opt.jobs is None:
|
|
|
|
self.jobs = self.manifest.default.sync_j
|
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.
|
|
|
|
args = [os.path.relpath(self.manifest.paths[p].worktree, os.getcwd())
|
|
|
|
for p 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
|
|
|
|
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:
|
2009-04-18 17:49:00 +00:00
|
|
|
to_fetch = []
|
|
|
|
now = time.time()
|
2012-10-23 22:00:54 +00:00
|
|
|
if _ONE_DAY_S <= (now - rp.LastFetch):
|
2009-04-18 17:49:00 +00:00
|
|
|
to_fetch.append(rp)
|
2012-09-24 03:15:13 +00:00
|
|
|
to_fetch.extend(all_projects)
|
2012-10-23 22:00:54 +00:00
|
|
|
to_fetch.sort(key=self._fetch_times.Get, reverse=True)
|
2009-04-18 17:49:00 +00:00
|
|
|
|
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
|
|
|
fetched = self._Fetch(to_fetch, opt)
|
2009-04-13 18:51:15 +00:00
|
|
|
_PostRepoFetch(rp, opt.no_repo_verify)
|
2009-04-11 00:04:08 +00:00
|
|
|
if opt.network_only:
|
|
|
|
# bail out now; the rest touches the working tree
|
|
|
|
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
|
|
|
# Iteratively fetch missing and/or nested unregistered submodules
|
|
|
|
previously_missing_set = set()
|
|
|
|
while True:
|
2013-03-19 11:20:52 +00:00
|
|
|
self._ReloadManifest(manifest_name)
|
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)
|
|
|
|
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
|
|
|
|
fetched.update(self._Fetch(missing, opt))
|
|
|
|
|
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
|
|
|
|
|
2009-06-02 04:10:33 +00:00
|
|
|
if self.UpdateProjectList():
|
|
|
|
sys.exit(1)
|
|
|
|
|
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
|
|
|
syncbuf = SyncBuffer(mp.config,
|
|
|
|
detach_head = opt.detach_head)
|
2012-09-24 03:15:13 +00:00
|
|
|
pm = Progress('Syncing work tree', len(all_projects))
|
|
|
|
for project in all_projects:
|
2009-04-10 23:48:52 +00:00
|
|
|
pm.update()
|
2008-11-04 15:37:10 +00:00
|
|
|
if project.worktree:
|
2014-11-12 18:27:45 +00:00
|
|
|
project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
|
2009-04-10 23:48:52 +00:00
|
|
|
pm.end()
|
2012-11-02 05:59:27 +00:00
|
|
|
print(file=sys.stderr)
|
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
|
|
|
if not syncbuf.Finish():
|
|
|
|
sys.exit(1)
|
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
|
|
|
|
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()
|
|
|
|
|
|
|
|
def _PostRepoFetch(rp, no_repo_verify=False, verbose=False):
|
|
|
|
if rp.HasChanges:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('info: A new version of repo is available', file=sys.stderr)
|
|
|
|
print(file=sys.stderr)
|
2009-04-13 18:51:15 +00:00
|
|
|
if no_repo_verify or _VerifyTag(rp):
|
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
|
|
|
syncbuf = SyncBuffer(rp.config)
|
|
|
|
rp.Sync_LocalHalf(syncbuf)
|
|
|
|
if not syncbuf.Finish():
|
2009-04-13 18:51:15 +00:00
|
|
|
sys.exit(1)
|
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
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _VerifyTag(project):
|
|
|
|
gpg_dir = os.path.expanduser('~/.repoconfig/gnupg')
|
|
|
|
if not os.path.exists(gpg_dir):
|
2012-11-02 05:59:27 +00:00
|
|
|
print('warning: GnuPG was not available during last "repo init"\n'
|
|
|
|
'warning: Cannot automatically authenticate repo."""',
|
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
try:
|
2009-05-30 01:38:17 +00:00
|
|
|
cur = project.bare_git.describe(project.GetRevisionId())
|
2008-10-21 14:00:00 +00:00
|
|
|
except GitError:
|
|
|
|
cur = None
|
|
|
|
|
|
|
|
if not cur \
|
|
|
|
or re.compile(r'^.*-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur):
|
2009-05-30 01:38:17 +00:00
|
|
|
rev = project.revisionExpr
|
2008-10-21 14:00:00 +00:00
|
|
|
if rev.startswith(R_HEADS):
|
|
|
|
rev = rev[len(R_HEADS):]
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
print(file=sys.stderr)
|
|
|
|
print("warning: project '%s' branch '%s' is not signed"
|
|
|
|
% (project.name, rev), file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
return False
|
|
|
|
|
2010-12-07 19:41:05 +00:00
|
|
|
env = os.environ.copy()
|
|
|
|
env['GIT_DIR'] = project.gitdir.encode()
|
|
|
|
env['GNUPGHOME'] = gpg_dir.encode()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
cmd = [GIT, 'tag', '-v', cur]
|
|
|
|
proc = subprocess.Popen(cmd,
|
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE,
|
|
|
|
env = env)
|
|
|
|
out = proc.stdout.read()
|
|
|
|
proc.stdout.close()
|
|
|
|
|
|
|
|
err = proc.stderr.read()
|
|
|
|
proc.stderr.close()
|
|
|
|
|
|
|
|
if proc.wait() != 0:
|
2012-11-02 05:59:27 +00:00
|
|
|
print(file=sys.stderr)
|
|
|
|
print(out, file=sys.stderr)
|
|
|
|
print(err, file=sys.stderr)
|
|
|
|
print(file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
return False
|
|
|
|
return True
|
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
|
|
|
|
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:
|
2014-05-06 14:57:48 +00:00
|
|
|
f = open(self._path)
|
2012-10-23 22:00:54 +00:00
|
|
|
try:
|
2014-05-06 14:57:48 +00:00
|
|
|
self._times = json.load(f)
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
except (IOError, ValueError):
|
|
|
|
try:
|
|
|
|
os.remove(self._path)
|
|
|
|
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:
|
2014-05-06 14:57:48 +00:00
|
|
|
f = open(self._path, 'w')
|
2012-10-23 22:00:54 +00:00
|
|
|
try:
|
2014-05-06 14:57:48 +00:00
|
|
|
json.dump(self._times, f, indent=2)
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
except (IOError, TypeError):
|
|
|
|
try:
|
|
|
|
os.remove(self._path)
|
|
|
|
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.
|
|
|
|
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:
|
|
|
|
tmpcookiefile = tempfile.NamedTemporaryFile()
|
|
|
|
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,
|
|
|
|
"https": proxy })
|
|
|
|
|
|
|
|
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
|
|
|
|
|