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.
|
|
|
|
|
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
|
2009-04-18 17:49:00 +00:00
|
|
|
import time
|
2010-04-06 17:40:01 +00:00
|
|
|
import 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
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
from git_command import GIT
|
2010-04-26 18:17:29 +00:00
|
|
|
from git_refs import R_HEADS
|
2009-04-13 18:51:15 +00:00
|
|
|
from project import HEAD
|
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
|
2008-10-21 14:00:00 +00:00
|
|
|
from error import RepoChangedException, GitError
|
|
|
|
from project import R_HEADS
|
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
|
2008-10-21 14:00:00 +00:00
|
|
|
|
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
|
|
|
|
manifest.
|
|
|
|
|
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.
|
|
|
|
|
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):
|
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")
|
2009-04-11 00:04:08 +00:00
|
|
|
p.add_option('-l','--local-only',
|
|
|
|
dest='local_only', action='store_true',
|
|
|
|
help="only update working tree, don't fetch")
|
2009-04-10 23:29:20 +00:00
|
|
|
p.add_option('-n','--network-only',
|
|
|
|
dest='network_only', action='store_true',
|
|
|
|
help="fetch only, don't update working tree")
|
2009-04-10 23:59:36 +00:00
|
|
|
p.add_option('-d','--detach',
|
|
|
|
dest='detach_head', action='store_true',
|
|
|
|
help='detach projects back to manifest revision')
|
2010-10-29 19:05:43 +00:00
|
|
|
p.add_option('-q','--quiet',
|
|
|
|
dest='quiet', action='store_true',
|
|
|
|
help='be more quiet')
|
2010-05-08 20:32:08 +00:00
|
|
|
p.add_option('-j','--jobs',
|
|
|
|
dest='jobs', action='store', type='int',
|
|
|
|
help="number of projects to fetch simultaneously")
|
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')
|
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
|
|
|
|
2010-10-29 19:05:43 +00:00
|
|
|
def _FetchHelper(self, opt, project, lock, fetched, pm, sem):
|
|
|
|
if not project.Sync_NetworkHalf(quiet=opt.quiet):
|
2010-05-08 20:32:08 +00:00
|
|
|
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
2010-07-02 22:58:31 +00:00
|
|
|
if opt.force_broken:
|
|
|
|
print >>sys.stderr, 'warn: --force-broken, continuing to sync'
|
|
|
|
else:
|
|
|
|
sem.release()
|
|
|
|
sys.exit(1)
|
2010-05-08 20:32:08 +00:00
|
|
|
|
|
|
|
lock.acquire()
|
|
|
|
fetched.add(project.gitdir)
|
|
|
|
pm.update()
|
|
|
|
lock.release()
|
|
|
|
sem.release()
|
|
|
|
|
2010-10-29 19:05:43 +00:00
|
|
|
def _Fetch(self, projects, opt):
|
2008-10-21 14:00:00 +00:00
|
|
|
fetched = set()
|
2009-04-10 23:48:52 +00:00
|
|
|
pm = Progress('Fetching projects', len(projects))
|
2010-05-08 20:32:08 +00:00
|
|
|
|
|
|
|
if self.jobs == 1:
|
|
|
|
for project in projects:
|
|
|
|
pm.update()
|
2010-10-29 19:05:43 +00:00
|
|
|
if project.Sync_NetworkHalf(quiet=opt.quiet):
|
2010-05-08 20:32:08 +00:00
|
|
|
fetched.add(project.gitdir)
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
2010-07-02 22:58:31 +00:00
|
|
|
if opt.force_broken:
|
|
|
|
print >>sys.stderr, 'warn: --force-broken, continuing to sync'
|
|
|
|
else:
|
|
|
|
sys.exit(1)
|
2010-05-08 20:32:08 +00:00
|
|
|
else:
|
|
|
|
threads = set()
|
|
|
|
lock = _threading.Lock()
|
|
|
|
sem = _threading.Semaphore(self.jobs)
|
|
|
|
for project in projects:
|
|
|
|
sem.acquire()
|
|
|
|
t = _threading.Thread(target = self._FetchHelper,
|
2010-10-29 19:05:43 +00:00
|
|
|
args = (opt,
|
|
|
|
project,
|
|
|
|
lock,
|
|
|
|
fetched,
|
|
|
|
pm,
|
|
|
|
sem))
|
2010-05-08 20:32:08 +00:00
|
|
|
threads.add(t)
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
|
|
|
|
2009-04-10 23:48:52 +00:00
|
|
|
pm.end()
|
2009-07-03 22:22:49 +00:00
|
|
|
for project in projects:
|
|
|
|
project.bare_git.gc('--auto')
|
2008-10-21 14:00:00 +00:00
|
|
|
return fetched
|
|
|
|
|
2009-06-02 04:10:33 +00:00
|
|
|
def UpdateProjectList(self):
|
|
|
|
new_project_paths = []
|
|
|
|
for project in self.manifest.projects.values():
|
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:
|
2009-09-26 17:38:52 +00:00
|
|
|
"""If the path has already been deleted, we don't need to do it
|
|
|
|
"""
|
|
|
|
if os.path.exists(self.manifest.topdir + '/' + path):
|
|
|
|
project = Project(
|
|
|
|
manifest = self.manifest,
|
|
|
|
name = path,
|
|
|
|
remote = RemoteSpec('origin'),
|
|
|
|
gitdir = os.path.join(self.manifest.topdir,
|
|
|
|
path, '.git'),
|
|
|
|
worktree = os.path.join(self.manifest.topdir, path),
|
|
|
|
relpath = path,
|
|
|
|
revisionExpr = 'HEAD',
|
|
|
|
revisionId = None)
|
|
|
|
|
|
|
|
if project.IsDirty():
|
|
|
|
print >>sys.stderr, 'error: Cannot remove project "%s": \
|
2009-06-02 04:10:33 +00:00
|
|
|
uncommitted changes are present' % project.relpath
|
2009-09-26 17:38:52 +00:00
|
|
|
print >>sys.stderr, ' commit changes, then run sync again'
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree
|
|
|
|
shutil.rmtree(project.worktree)
|
|
|
|
# Try deleting parent subdirs if they are empty
|
|
|
|
dir = os.path.dirname(project.worktree)
|
|
|
|
while dir != self.manifest.topdir:
|
|
|
|
try:
|
|
|
|
os.rmdir(dir)
|
|
|
|
except OSError:
|
|
|
|
break
|
|
|
|
dir = os.path.dirname(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
|
2009-04-10 23:59:36 +00:00
|
|
|
if opt.network_only and opt.detach_head:
|
|
|
|
print >>sys.stderr, 'error: cannot combine -n and -d'
|
|
|
|
sys.exit(1)
|
2009-04-11 00:04:08 +00:00
|
|
|
if opt.network_only and opt.local_only:
|
|
|
|
print >>sys.stderr, 'error: cannot combine -n and -l'
|
|
|
|
sys.exit(1)
|
2009-04-10 23:59:36 +00:00
|
|
|
|
2010-04-06 17:40:01 +00:00
|
|
|
if opt.smart_sync:
|
|
|
|
if not self.manifest.manifest_server:
|
|
|
|
print >>sys.stderr, \
|
|
|
|
'error: cannot smart sync: no manifest server defined in manifest'
|
|
|
|
sys.exit(1)
|
|
|
|
try:
|
|
|
|
server = xmlrpclib.Server(self.manifest.manifest_server)
|
|
|
|
p = self.manifest.manifestProject
|
|
|
|
b = p.GetBranch(p.CurrentBranch)
|
|
|
|
branch = b.merge
|
2010-04-26 18:17:29 +00:00
|
|
|
if branch.startswith(R_HEADS):
|
|
|
|
branch = branch[len(R_HEADS):]
|
2010-04-06 17:40:01 +00:00
|
|
|
|
2010-12-07 19:41:05 +00:00
|
|
|
env = os.environ.copy()
|
2010-04-06 17:40:01 +00:00
|
|
|
if (env.has_key('TARGET_PRODUCT') and
|
|
|
|
env.has_key('TARGET_BUILD_VARIANT')):
|
|
|
|
target = '%s-%s' % (env['TARGET_PRODUCT'],
|
|
|
|
env['TARGET_BUILD_VARIANT'])
|
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
|
|
|
else:
|
|
|
|
[success, manifest_str] = server.GetApprovedManifest(branch)
|
|
|
|
|
|
|
|
if success:
|
|
|
|
manifest_name = "smart_sync_override.xml"
|
|
|
|
manifest_path = os.path.join(self.manifest.manifestProject.worktree,
|
|
|
|
manifest_name)
|
|
|
|
try:
|
|
|
|
f = open(manifest_path, 'w')
|
|
|
|
try:
|
|
|
|
f.write(manifest_str)
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
except IOError:
|
|
|
|
print >>sys.stderr, 'error: cannot write manifest to %s' % \
|
|
|
|
manifest_path
|
|
|
|
sys.exit(1)
|
2010-04-20 22:28:19 +00:00
|
|
|
self.manifest.Override(manifest_name)
|
2010-04-06 17:40:01 +00:00
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'error: %s' % manifest_str
|
|
|
|
sys.exit(1)
|
|
|
|
except socket.error:
|
|
|
|
print >>sys.stderr, 'error: cannot connect to manifest server %s' % (
|
|
|
|
self.manifest.manifest_server)
|
|
|
|
sys.exit(1)
|
|
|
|
|
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:
|
2009-04-13 18:51:15 +00:00
|
|
|
_PostRepoUpgrade(self.manifest)
|
2008-11-03 18:32:09 +00:00
|
|
|
|
2009-12-07 23:38:01 +00:00
|
|
|
if not opt.local_only:
|
2010-10-29 19:05:43 +00:00
|
|
|
mp.Sync_NetworkHalf(quiet=opt.quiet)
|
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)
|
|
|
|
self.manifest._Unload()
|
2008-10-21 14:00:00 +00:00
|
|
|
all = self.GetProjects(args, missing_ok=True)
|
|
|
|
|
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()
|
|
|
|
if (24 * 60 * 60) <= (now - rp.LastFetch):
|
|
|
|
to_fetch.append(rp)
|
|
|
|
to_fetch.extend(all)
|
|
|
|
|
2010-10-29 19:05:43 +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
|
|
|
|
|
|
|
|
if mp.HasChanges:
|
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)
|
|
|
|
mp.Sync_LocalHalf(syncbuf)
|
|
|
|
if not syncbuf.Finish():
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
2009-07-03 23:37:30 +00:00
|
|
|
_ReloadManifest(self)
|
|
|
|
mp = self.manifest.manifestProject
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-04-11 00:04:08 +00:00
|
|
|
all = self.GetProjects(args, missing_ok=True)
|
|
|
|
missing = []
|
|
|
|
for project in all:
|
|
|
|
if project.gitdir not in fetched:
|
|
|
|
missing.append(project)
|
2010-10-29 19:05:43 +00:00
|
|
|
self._Fetch(missing, opt)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-06-04 23:15:53 +00:00
|
|
|
if self.manifest.IsMirror:
|
|
|
|
# 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)
|
2009-04-10 23:48:52 +00:00
|
|
|
pm = Progress('Syncing work tree', len(all))
|
2008-10-21 14:00:00 +00:00
|
|
|
for project in all:
|
2009-04-10 23:48:52 +00:00
|
|
|
pm.update()
|
2008-11-04 15:37:10 +00:00
|
|
|
if project.worktree:
|
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
|
|
|
project.Sync_LocalHalf(syncbuf)
|
2009-04-10 23:48:52 +00:00
|
|
|
pm.end()
|
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
|
|
|
print >>sys.stderr
|
|
|
|
if not syncbuf.Finish():
|
|
|
|
sys.exit(1)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-07-03 23:37:30 +00:00
|
|
|
def _ReloadManifest(cmd):
|
|
|
|
old = cmd.manifest
|
|
|
|
new = cmd.GetManifest(reparse=True)
|
|
|
|
|
|
|
|
if old.__class__ != new.__class__:
|
|
|
|
print >>sys.stderr, 'NOTICE: manifest format has changed ***'
|
|
|
|
new.Upgrade_Local(old)
|
2010-12-07 18:31:19 +00:00
|
|
|
else:
|
|
|
|
if new.notice:
|
|
|
|
print new.notice
|
2009-04-13 18:51:15 +00:00
|
|
|
|
|
|
|
def _PostRepoUpgrade(manifest):
|
|
|
|
for project in manifest.projects.values():
|
|
|
|
if project.Exists:
|
|
|
|
project.PostRepoUpgrade()
|
|
|
|
|
|
|
|
def _PostRepoFetch(rp, no_repo_verify=False, verbose=False):
|
|
|
|
if rp.HasChanges:
|
|
|
|
print >>sys.stderr, 'info: A new version of repo is available'
|
|
|
|
print >>sys.stderr, ''
|
|
|
|
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)
|
|
|
|
print >>sys.stderr, 'info: Restarting repo with latest version'
|
|
|
|
raise RepoChangedException(['--repo-upgraded'])
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'warning: Skipped upgrade to unverified version'
|
|
|
|
else:
|
|
|
|
if verbose:
|
|
|
|
print >>sys.stderr, 'repo version %s is current' % rp.work_git.describe(HEAD)
|
|
|
|
|
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):
|
|
|
|
print >>sys.stderr,\
|
|
|
|
"""warning: GnuPG was not available during last "repo init"
|
|
|
|
warning: Cannot automatically authenticate repo."""
|
|
|
|
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):]
|
|
|
|
|
|
|
|
print >>sys.stderr
|
|
|
|
print >>sys.stderr,\
|
|
|
|
"warning: project '%s' branch '%s' is not signed" \
|
|
|
|
% (project.name, rev)
|
|
|
|
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:
|
|
|
|
print >>sys.stderr
|
|
|
|
print >>sys.stderr, out
|
|
|
|
print >>sys.stderr, err
|
|
|
|
print >>sys.stderr
|
|
|
|
return False
|
|
|
|
return True
|