The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Shawn O. Pearce | 2a1ccb2 | 2009-04-10 16:51:53 -0700 | [diff] [blame] | 16 | from optparse import SUPPRESS_HELP |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 17 | import os |
| 18 | import re |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 19 | import shutil |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 20 | import socket |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 21 | import subprocess |
| 22 | import sys |
Shawn O. Pearce | f690687 | 2009-04-18 10:49:00 -0700 | [diff] [blame] | 23 | import time |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 24 | import xmlrpclib |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 25 | |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 26 | try: |
| 27 | import threading as _threading |
| 28 | except ImportError: |
| 29 | import dummy_threading as _threading |
| 30 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 31 | from git_command import GIT |
Nico Sallembien | 5732e47 | 2010-04-26 11:17:29 -0700 | [diff] [blame] | 32 | from git_refs import R_HEADS |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 33 | from project import HEAD |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 34 | from project import Project |
| 35 | from project import RemoteSpec |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 36 | from command import Command, MirrorSafeCommand |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | from error import RepoChangedException, GitError |
| 38 | from project import R_HEADS |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 39 | from project import SyncBuffer |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 40 | from progress import Progress |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 41 | |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 42 | class Sync(Command, MirrorSafeCommand): |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 43 | jobs = 1 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | common = True |
| 45 | helpSummary = "Update working tree to the latest revision" |
| 46 | helpUsage = """ |
| 47 | %prog [<project>...] |
| 48 | """ |
| 49 | helpDescription = """ |
| 50 | The '%prog' command synchronizes local project directories |
| 51 | with the remote repositories specified in the manifest. If a local |
| 52 | project does not yet exist, it will clone a new local directory from |
| 53 | the remote repository and set up tracking branches as specified in |
| 54 | the manifest. If the local project already exists, '%prog' |
| 55 | will update the remote branches and rebase any new local changes |
| 56 | on top of the new remote changes. |
| 57 | |
| 58 | '%prog' will synchronize all projects listed at the command |
| 59 | line. Projects can be specified either by name, or by a relative |
| 60 | or absolute path to the project's local directory. If no projects |
| 61 | are specified, '%prog' will synchronize all projects listed in |
| 62 | the manifest. |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 63 | |
| 64 | The -d/--detach option can be used to switch specified projects |
| 65 | back to the manifest revision. This option is especially helpful |
| 66 | if the project is currently on a topic branch, but the manifest |
| 67 | revision is temporarily needed. |
Shawn O. Pearce | eb7af87 | 2009-04-21 08:02:04 -0700 | [diff] [blame] | 68 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 69 | The -s/--smart-sync option can be used to sync to a known good |
| 70 | build as specified by the manifest-server element in the current |
| 71 | manifest. |
| 72 | |
Andrei Warkentin | 5df6de0 | 2010-07-02 17:58:31 -0500 | [diff] [blame] | 73 | The -f/--force-broken option can be used to proceed with syncing |
| 74 | other projects if a project sync fails. |
| 75 | |
Shawn O. Pearce | eb7af87 | 2009-04-21 08:02:04 -0700 | [diff] [blame] | 76 | SSH Connections |
| 77 | --------------- |
| 78 | |
| 79 | If at least one project remote URL uses an SSH connection (ssh://, |
| 80 | git+ssh://, or user@host:path syntax) repo will automatically |
| 81 | enable the SSH ControlMaster option when connecting to that host. |
| 82 | This feature permits other projects in the same '%prog' session to |
| 83 | reuse the same SSH tunnel, saving connection setup overheads. |
| 84 | |
| 85 | To disable this behavior on UNIX platforms, set the GIT_SSH |
| 86 | environment variable to 'ssh'. For example: |
| 87 | |
| 88 | export GIT_SSH=ssh |
| 89 | %prog |
| 90 | |
| 91 | Compatibility |
| 92 | ~~~~~~~~~~~~~ |
| 93 | |
| 94 | This feature is automatically disabled on Windows, due to the lack |
| 95 | of UNIX domain socket support. |
| 96 | |
| 97 | This feature is not compatible with url.insteadof rewrites in the |
| 98 | user's ~/.gitconfig. '%prog' is currently not able to perform the |
| 99 | rewrite early enough to establish the ControlMaster tunnel. |
| 100 | |
| 101 | If the remote SSH daemon is Gerrit Code Review, version 2.0.10 or |
| 102 | later is required to fix a server side protocol bug. |
| 103 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | """ |
| 105 | |
Nico Sallembien | 6623b21 | 2010-05-11 12:57:01 -0700 | [diff] [blame] | 106 | def _Options(self, p, show_smart=True): |
Andrei Warkentin | 5df6de0 | 2010-07-02 17:58:31 -0500 | [diff] [blame] | 107 | p.add_option('-f', '--force-broken', |
| 108 | dest='force_broken', action='store_true', |
| 109 | help="continue sync even if a project fails to sync") |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 110 | p.add_option('-l','--local-only', |
| 111 | dest='local_only', action='store_true', |
| 112 | help="only update working tree, don't fetch") |
Shawn O. Pearce | 96fdcef | 2009-04-10 16:29:20 -0700 | [diff] [blame] | 113 | p.add_option('-n','--network-only', |
| 114 | dest='network_only', action='store_true', |
| 115 | help="fetch only, don't update working tree") |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 116 | p.add_option('-d','--detach', |
| 117 | dest='detach_head', action='store_true', |
| 118 | help='detach projects back to manifest revision') |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 119 | p.add_option('-q','--quiet', |
| 120 | dest='quiet', action='store_true', |
| 121 | help='be more quiet') |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 122 | p.add_option('-j','--jobs', |
| 123 | dest='jobs', action='store', type='int', |
| 124 | help="number of projects to fetch simultaneously") |
Nico Sallembien | 6623b21 | 2010-05-11 12:57:01 -0700 | [diff] [blame] | 125 | if show_smart: |
| 126 | p.add_option('-s', '--smart-sync', |
| 127 | dest='smart_sync', action='store_true', |
| 128 | help='smart sync using manifest from a known good build') |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 129 | |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 130 | g = p.add_option_group('repo Version options') |
| 131 | g.add_option('--no-repo-verify', |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 132 | dest='no_repo_verify', action='store_true', |
| 133 | help='do not verify repo source code') |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 134 | g.add_option('--repo-upgraded', |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 135 | dest='repo_upgraded', action='store_true', |
Shawn O. Pearce | 2a1ccb2 | 2009-04-10 16:51:53 -0700 | [diff] [blame] | 136 | help=SUPPRESS_HELP) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 137 | |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 138 | def _FetchHelper(self, opt, project, lock, fetched, pm, sem): |
| 139 | if not project.Sync_NetworkHalf(quiet=opt.quiet): |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 140 | print >>sys.stderr, 'error: Cannot fetch %s' % project.name |
Andrei Warkentin | 5df6de0 | 2010-07-02 17:58:31 -0500 | [diff] [blame] | 141 | if opt.force_broken: |
| 142 | print >>sys.stderr, 'warn: --force-broken, continuing to sync' |
| 143 | else: |
| 144 | sem.release() |
| 145 | sys.exit(1) |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 146 | |
| 147 | lock.acquire() |
| 148 | fetched.add(project.gitdir) |
| 149 | pm.update() |
| 150 | lock.release() |
| 151 | sem.release() |
| 152 | |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 153 | def _Fetch(self, projects, opt): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | fetched = set() |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 155 | pm = Progress('Fetching projects', len(projects)) |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 156 | |
| 157 | if self.jobs == 1: |
| 158 | for project in projects: |
| 159 | pm.update() |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 160 | if project.Sync_NetworkHalf(quiet=opt.quiet): |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 161 | fetched.add(project.gitdir) |
| 162 | else: |
| 163 | print >>sys.stderr, 'error: Cannot fetch %s' % project.name |
Andrei Warkentin | 5df6de0 | 2010-07-02 17:58:31 -0500 | [diff] [blame] | 164 | if opt.force_broken: |
| 165 | print >>sys.stderr, 'warn: --force-broken, continuing to sync' |
| 166 | else: |
| 167 | sys.exit(1) |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 168 | else: |
| 169 | threads = set() |
| 170 | lock = _threading.Lock() |
| 171 | sem = _threading.Semaphore(self.jobs) |
| 172 | for project in projects: |
| 173 | sem.acquire() |
| 174 | t = _threading.Thread(target = self._FetchHelper, |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 175 | args = (opt, |
| 176 | project, |
| 177 | lock, |
| 178 | fetched, |
| 179 | pm, |
| 180 | sem)) |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 181 | threads.add(t) |
| 182 | t.start() |
| 183 | |
| 184 | for t in threads: |
| 185 | t.join() |
| 186 | |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 187 | pm.end() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 188 | return fetched |
| 189 | |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 190 | def UpdateProjectList(self): |
| 191 | new_project_paths = [] |
| 192 | for project in self.manifest.projects.values(): |
Shawn O. Pearce | 3a68bb4 | 2009-06-04 16:18:09 -0700 | [diff] [blame] | 193 | if project.relpath: |
| 194 | new_project_paths.append(project.relpath) |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 195 | file_name = 'project.list' |
| 196 | file_path = os.path.join(self.manifest.repodir, file_name) |
| 197 | old_project_paths = [] |
| 198 | |
| 199 | if os.path.exists(file_path): |
| 200 | fd = open(file_path, 'r') |
| 201 | try: |
| 202 | old_project_paths = fd.read().split('\n') |
| 203 | finally: |
| 204 | fd.close() |
| 205 | for path in old_project_paths: |
Shawn O. Pearce | 3a68bb4 | 2009-06-04 16:18:09 -0700 | [diff] [blame] | 206 | if not path: |
| 207 | continue |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 208 | if path not in new_project_paths: |
Anthony | f3fdf82 | 2009-09-26 13:38:52 -0400 | [diff] [blame] | 209 | """If the path has already been deleted, we don't need to do it |
| 210 | """ |
| 211 | if os.path.exists(self.manifest.topdir + '/' + path): |
| 212 | project = Project( |
| 213 | manifest = self.manifest, |
| 214 | name = path, |
| 215 | remote = RemoteSpec('origin'), |
| 216 | gitdir = os.path.join(self.manifest.topdir, |
| 217 | path, '.git'), |
| 218 | worktree = os.path.join(self.manifest.topdir, path), |
| 219 | relpath = path, |
| 220 | revisionExpr = 'HEAD', |
| 221 | revisionId = None) |
| 222 | |
| 223 | if project.IsDirty(): |
| 224 | print >>sys.stderr, 'error: Cannot remove project "%s": \ |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 225 | uncommitted changes are present' % project.relpath |
Anthony | f3fdf82 | 2009-09-26 13:38:52 -0400 | [diff] [blame] | 226 | print >>sys.stderr, ' commit changes, then run sync again' |
| 227 | return -1 |
| 228 | else: |
| 229 | print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree |
| 230 | shutil.rmtree(project.worktree) |
| 231 | # Try deleting parent subdirs if they are empty |
| 232 | dir = os.path.dirname(project.worktree) |
| 233 | while dir != self.manifest.topdir: |
| 234 | try: |
| 235 | os.rmdir(dir) |
| 236 | except OSError: |
| 237 | break |
| 238 | dir = os.path.dirname(dir) |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 239 | |
Shawn O. Pearce | 9fb29ce | 2009-06-04 20:41:02 -0700 | [diff] [blame] | 240 | new_project_paths.sort() |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 241 | fd = open(file_path, 'w') |
| 242 | try: |
| 243 | fd.write('\n'.join(new_project_paths)) |
Shawn O. Pearce | 3a68bb4 | 2009-06-04 16:18:09 -0700 | [diff] [blame] | 244 | fd.write('\n') |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 245 | finally: |
| 246 | fd.close() |
| 247 | return 0 |
| 248 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 249 | def Execute(self, opt, args): |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 250 | if opt.jobs: |
| 251 | self.jobs = opt.jobs |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 252 | if opt.network_only and opt.detach_head: |
| 253 | print >>sys.stderr, 'error: cannot combine -n and -d' |
| 254 | sys.exit(1) |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 255 | if opt.network_only and opt.local_only: |
| 256 | print >>sys.stderr, 'error: cannot combine -n and -l' |
| 257 | sys.exit(1) |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 258 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 259 | if opt.smart_sync: |
| 260 | if not self.manifest.manifest_server: |
| 261 | print >>sys.stderr, \ |
| 262 | 'error: cannot smart sync: no manifest server defined in manifest' |
| 263 | sys.exit(1) |
| 264 | try: |
| 265 | server = xmlrpclib.Server(self.manifest.manifest_server) |
| 266 | p = self.manifest.manifestProject |
| 267 | b = p.GetBranch(p.CurrentBranch) |
| 268 | branch = b.merge |
Nico Sallembien | 5732e47 | 2010-04-26 11:17:29 -0700 | [diff] [blame] | 269 | if branch.startswith(R_HEADS): |
| 270 | branch = branch[len(R_HEADS):] |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 271 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame^] | 272 | env = os.environ.copy() |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 273 | if (env.has_key('TARGET_PRODUCT') and |
| 274 | env.has_key('TARGET_BUILD_VARIANT')): |
| 275 | target = '%s-%s' % (env['TARGET_PRODUCT'], |
| 276 | env['TARGET_BUILD_VARIANT']) |
| 277 | [success, manifest_str] = server.GetApprovedManifest(branch, target) |
| 278 | else: |
| 279 | [success, manifest_str] = server.GetApprovedManifest(branch) |
| 280 | |
| 281 | if success: |
| 282 | manifest_name = "smart_sync_override.xml" |
| 283 | manifest_path = os.path.join(self.manifest.manifestProject.worktree, |
| 284 | manifest_name) |
| 285 | try: |
| 286 | f = open(manifest_path, 'w') |
| 287 | try: |
| 288 | f.write(manifest_str) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 289 | finally: |
| 290 | f.close() |
| 291 | except IOError: |
| 292 | print >>sys.stderr, 'error: cannot write manifest to %s' % \ |
| 293 | manifest_path |
| 294 | sys.exit(1) |
Nico Sallembien | 719965a | 2010-04-20 15:28:19 -0700 | [diff] [blame] | 295 | self.manifest.Override(manifest_name) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 296 | else: |
| 297 | print >>sys.stderr, 'error: %s' % manifest_str |
| 298 | sys.exit(1) |
| 299 | except socket.error: |
| 300 | print >>sys.stderr, 'error: cannot connect to manifest server %s' % ( |
| 301 | self.manifest.manifest_server) |
| 302 | sys.exit(1) |
| 303 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 304 | rp = self.manifest.repoProject |
| 305 | rp.PreSync() |
| 306 | |
| 307 | mp = self.manifest.manifestProject |
| 308 | mp.PreSync() |
| 309 | |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 310 | if opt.repo_upgraded: |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 311 | _PostRepoUpgrade(self.manifest) |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 312 | |
Nico Sallembien | 9bb1816 | 2009-12-07 15:38:01 -0800 | [diff] [blame] | 313 | if not opt.local_only: |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 314 | mp.Sync_NetworkHalf(quiet=opt.quiet) |
Nico Sallembien | 9bb1816 | 2009-12-07 15:38:01 -0800 | [diff] [blame] | 315 | |
| 316 | if mp.HasChanges: |
| 317 | syncbuf = SyncBuffer(mp.config) |
| 318 | mp.Sync_LocalHalf(syncbuf) |
| 319 | if not syncbuf.Finish(): |
| 320 | sys.exit(1) |
| 321 | self.manifest._Unload() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 322 | all = self.GetProjects(args, missing_ok=True) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 323 | |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 324 | if not opt.local_only: |
Shawn O. Pearce | f690687 | 2009-04-18 10:49:00 -0700 | [diff] [blame] | 325 | to_fetch = [] |
| 326 | now = time.time() |
| 327 | if (24 * 60 * 60) <= (now - rp.LastFetch): |
| 328 | to_fetch.append(rp) |
Shawn O. Pearce | f690687 | 2009-04-18 10:49:00 -0700 | [diff] [blame] | 329 | to_fetch.extend(all) |
| 330 | |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 331 | fetched = self._Fetch(to_fetch, opt) |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 332 | _PostRepoFetch(rp, opt.no_repo_verify) |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 333 | if opt.network_only: |
| 334 | # bail out now; the rest touches the working tree |
| 335 | return |
| 336 | |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 337 | self.manifest._Unload() |
| 338 | all = self.GetProjects(args, missing_ok=True) |
| 339 | missing = [] |
| 340 | for project in all: |
| 341 | if project.gitdir not in fetched: |
| 342 | missing.append(project) |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 343 | self._Fetch(missing, opt) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 344 | |
Shawn O. Pearce | cd1d7ff | 2009-06-04 16:15:53 -0700 | [diff] [blame] | 345 | if self.manifest.IsMirror: |
| 346 | # bail out now, we have no working tree |
| 347 | return |
| 348 | |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 349 | if self.UpdateProjectList(): |
| 350 | sys.exit(1) |
| 351 | |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 352 | syncbuf = SyncBuffer(mp.config, |
| 353 | detach_head = opt.detach_head) |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 354 | pm = Progress('Syncing work tree', len(all)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 355 | for project in all: |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 356 | pm.update() |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 357 | if project.worktree: |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 358 | project.Sync_LocalHalf(syncbuf) |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 359 | pm.end() |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 360 | print >>sys.stderr |
| 361 | if not syncbuf.Finish(): |
| 362 | sys.exit(1) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 363 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 364 | # If there's a notice that's supposed to print at the end of the sync, print |
| 365 | # it now... |
| 366 | if self.manifest.notice: |
| 367 | print self.manifest.notice |
| 368 | |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 369 | def _PostRepoUpgrade(manifest): |
| 370 | for project in manifest.projects.values(): |
| 371 | if project.Exists: |
| 372 | project.PostRepoUpgrade() |
| 373 | |
| 374 | def _PostRepoFetch(rp, no_repo_verify=False, verbose=False): |
| 375 | if rp.HasChanges: |
| 376 | print >>sys.stderr, 'info: A new version of repo is available' |
| 377 | print >>sys.stderr, '' |
| 378 | if no_repo_verify or _VerifyTag(rp): |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 379 | syncbuf = SyncBuffer(rp.config) |
| 380 | rp.Sync_LocalHalf(syncbuf) |
| 381 | if not syncbuf.Finish(): |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 382 | sys.exit(1) |
| 383 | print >>sys.stderr, 'info: Restarting repo with latest version' |
| 384 | raise RepoChangedException(['--repo-upgraded']) |
| 385 | else: |
| 386 | print >>sys.stderr, 'warning: Skipped upgrade to unverified version' |
| 387 | else: |
| 388 | if verbose: |
| 389 | print >>sys.stderr, 'repo version %s is current' % rp.work_git.describe(HEAD) |
| 390 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 391 | def _VerifyTag(project): |
| 392 | gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') |
| 393 | if not os.path.exists(gpg_dir): |
| 394 | print >>sys.stderr,\ |
| 395 | """warning: GnuPG was not available during last "repo init" |
| 396 | warning: Cannot automatically authenticate repo.""" |
| 397 | return True |
| 398 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 399 | try: |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 400 | cur = project.bare_git.describe(project.GetRevisionId()) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | except GitError: |
| 402 | cur = None |
| 403 | |
| 404 | if not cur \ |
| 405 | or re.compile(r'^.*-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur): |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 406 | rev = project.revisionExpr |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 407 | if rev.startswith(R_HEADS): |
| 408 | rev = rev[len(R_HEADS):] |
| 409 | |
| 410 | print >>sys.stderr |
| 411 | print >>sys.stderr,\ |
| 412 | "warning: project '%s' branch '%s' is not signed" \ |
| 413 | % (project.name, rev) |
| 414 | return False |
| 415 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame^] | 416 | env = os.environ.copy() |
| 417 | env['GIT_DIR'] = project.gitdir.encode() |
| 418 | env['GNUPGHOME'] = gpg_dir.encode() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 419 | |
| 420 | cmd = [GIT, 'tag', '-v', cur] |
| 421 | proc = subprocess.Popen(cmd, |
| 422 | stdout = subprocess.PIPE, |
| 423 | stderr = subprocess.PIPE, |
| 424 | env = env) |
| 425 | out = proc.stdout.read() |
| 426 | proc.stdout.close() |
| 427 | |
| 428 | err = proc.stderr.read() |
| 429 | proc.stderr.close() |
| 430 | |
| 431 | if proc.wait() != 0: |
| 432 | print >>sys.stderr |
| 433 | print >>sys.stderr, out |
| 434 | print >>sys.stderr, err |
| 435 | print >>sys.stderr |
| 436 | return False |
| 437 | return True |