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() |
Shawn O. Pearce | 0d2b61f | 2009-07-03 15:22:49 -0700 | [diff] [blame] | 188 | for project in projects: |
| 189 | project.bare_git.gc('--auto') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 190 | return fetched |
| 191 | |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 192 | def UpdateProjectList(self): |
| 193 | new_project_paths = [] |
| 194 | for project in self.manifest.projects.values(): |
Shawn O. Pearce | 3a68bb4 | 2009-06-04 16:18:09 -0700 | [diff] [blame] | 195 | if project.relpath: |
| 196 | new_project_paths.append(project.relpath) |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 197 | file_name = 'project.list' |
| 198 | file_path = os.path.join(self.manifest.repodir, file_name) |
| 199 | old_project_paths = [] |
| 200 | |
| 201 | if os.path.exists(file_path): |
| 202 | fd = open(file_path, 'r') |
| 203 | try: |
| 204 | old_project_paths = fd.read().split('\n') |
| 205 | finally: |
| 206 | fd.close() |
| 207 | for path in old_project_paths: |
Shawn O. Pearce | 3a68bb4 | 2009-06-04 16:18:09 -0700 | [diff] [blame] | 208 | if not path: |
| 209 | continue |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 210 | if path not in new_project_paths: |
Anthony | f3fdf82 | 2009-09-26 13:38:52 -0400 | [diff] [blame] | 211 | """If the path has already been deleted, we don't need to do it |
| 212 | """ |
| 213 | if os.path.exists(self.manifest.topdir + '/' + path): |
| 214 | project = Project( |
| 215 | manifest = self.manifest, |
| 216 | name = path, |
| 217 | remote = RemoteSpec('origin'), |
| 218 | gitdir = os.path.join(self.manifest.topdir, |
| 219 | path, '.git'), |
| 220 | worktree = os.path.join(self.manifest.topdir, path), |
| 221 | relpath = path, |
| 222 | revisionExpr = 'HEAD', |
| 223 | revisionId = None) |
| 224 | |
| 225 | if project.IsDirty(): |
| 226 | print >>sys.stderr, 'error: Cannot remove project "%s": \ |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 227 | uncommitted changes are present' % project.relpath |
Anthony | f3fdf82 | 2009-09-26 13:38:52 -0400 | [diff] [blame] | 228 | print >>sys.stderr, ' commit changes, then run sync again' |
| 229 | return -1 |
| 230 | else: |
| 231 | print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree |
| 232 | shutil.rmtree(project.worktree) |
| 233 | # Try deleting parent subdirs if they are empty |
| 234 | dir = os.path.dirname(project.worktree) |
| 235 | while dir != self.manifest.topdir: |
| 236 | try: |
| 237 | os.rmdir(dir) |
| 238 | except OSError: |
| 239 | break |
| 240 | dir = os.path.dirname(dir) |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 241 | |
Shawn O. Pearce | 9fb29ce | 2009-06-04 20:41:02 -0700 | [diff] [blame] | 242 | new_project_paths.sort() |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 243 | fd = open(file_path, 'w') |
| 244 | try: |
| 245 | fd.write('\n'.join(new_project_paths)) |
Shawn O. Pearce | 3a68bb4 | 2009-06-04 16:18:09 -0700 | [diff] [blame] | 246 | fd.write('\n') |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 247 | finally: |
| 248 | fd.close() |
| 249 | return 0 |
| 250 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 251 | def Execute(self, opt, args): |
Roy Lee | 18afd7f | 2010-05-09 04:32:08 +0800 | [diff] [blame] | 252 | if opt.jobs: |
| 253 | self.jobs = opt.jobs |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 254 | if opt.network_only and opt.detach_head: |
| 255 | print >>sys.stderr, 'error: cannot combine -n and -d' |
| 256 | sys.exit(1) |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 257 | if opt.network_only and opt.local_only: |
| 258 | print >>sys.stderr, 'error: cannot combine -n and -l' |
| 259 | sys.exit(1) |
Shawn O. Pearce | 3e768c9 | 2009-04-10 16:59:36 -0700 | [diff] [blame] | 260 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 261 | if opt.smart_sync: |
| 262 | if not self.manifest.manifest_server: |
| 263 | print >>sys.stderr, \ |
| 264 | 'error: cannot smart sync: no manifest server defined in manifest' |
| 265 | sys.exit(1) |
| 266 | try: |
| 267 | server = xmlrpclib.Server(self.manifest.manifest_server) |
| 268 | p = self.manifest.manifestProject |
| 269 | b = p.GetBranch(p.CurrentBranch) |
| 270 | branch = b.merge |
Nico Sallembien | 5732e47 | 2010-04-26 11:17:29 -0700 | [diff] [blame] | 271 | if branch.startswith(R_HEADS): |
| 272 | branch = branch[len(R_HEADS):] |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 273 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame] | 274 | env = os.environ.copy() |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 275 | if (env.has_key('TARGET_PRODUCT') and |
| 276 | env.has_key('TARGET_BUILD_VARIANT')): |
| 277 | target = '%s-%s' % (env['TARGET_PRODUCT'], |
| 278 | env['TARGET_BUILD_VARIANT']) |
| 279 | [success, manifest_str] = server.GetApprovedManifest(branch, target) |
| 280 | else: |
| 281 | [success, manifest_str] = server.GetApprovedManifest(branch) |
| 282 | |
| 283 | if success: |
| 284 | manifest_name = "smart_sync_override.xml" |
| 285 | manifest_path = os.path.join(self.manifest.manifestProject.worktree, |
| 286 | manifest_name) |
| 287 | try: |
| 288 | f = open(manifest_path, 'w') |
| 289 | try: |
| 290 | f.write(manifest_str) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 291 | finally: |
| 292 | f.close() |
| 293 | except IOError: |
| 294 | print >>sys.stderr, 'error: cannot write manifest to %s' % \ |
| 295 | manifest_path |
| 296 | sys.exit(1) |
Nico Sallembien | 719965a | 2010-04-20 15:28:19 -0700 | [diff] [blame] | 297 | self.manifest.Override(manifest_name) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 298 | else: |
| 299 | print >>sys.stderr, 'error: %s' % manifest_str |
| 300 | sys.exit(1) |
| 301 | except socket.error: |
| 302 | print >>sys.stderr, 'error: cannot connect to manifest server %s' % ( |
| 303 | self.manifest.manifest_server) |
| 304 | sys.exit(1) |
| 305 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 306 | rp = self.manifest.repoProject |
| 307 | rp.PreSync() |
| 308 | |
| 309 | mp = self.manifest.manifestProject |
| 310 | mp.PreSync() |
| 311 | |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 312 | if opt.repo_upgraded: |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 313 | _PostRepoUpgrade(self.manifest) |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 314 | |
Nico Sallembien | 9bb1816 | 2009-12-07 15:38:01 -0800 | [diff] [blame] | 315 | if not opt.local_only: |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 316 | mp.Sync_NetworkHalf(quiet=opt.quiet) |
Nico Sallembien | 9bb1816 | 2009-12-07 15:38:01 -0800 | [diff] [blame] | 317 | |
| 318 | if mp.HasChanges: |
| 319 | syncbuf = SyncBuffer(mp.config) |
| 320 | mp.Sync_LocalHalf(syncbuf) |
| 321 | if not syncbuf.Finish(): |
| 322 | sys.exit(1) |
| 323 | self.manifest._Unload() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | all = self.GetProjects(args, missing_ok=True) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 325 | |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 326 | if not opt.local_only: |
Shawn O. Pearce | f690687 | 2009-04-18 10:49:00 -0700 | [diff] [blame] | 327 | to_fetch = [] |
| 328 | now = time.time() |
| 329 | if (24 * 60 * 60) <= (now - rp.LastFetch): |
| 330 | to_fetch.append(rp) |
Shawn O. Pearce | f690687 | 2009-04-18 10:49:00 -0700 | [diff] [blame] | 331 | to_fetch.extend(all) |
| 332 | |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 333 | fetched = self._Fetch(to_fetch, opt) |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 334 | _PostRepoFetch(rp, opt.no_repo_verify) |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 335 | if opt.network_only: |
| 336 | # bail out now; the rest touches the working tree |
| 337 | return |
| 338 | |
Shawn O. Pearce | b1562fa | 2009-04-10 17:04:08 -0700 | [diff] [blame] | 339 | self.manifest._Unload() |
| 340 | all = self.GetProjects(args, missing_ok=True) |
| 341 | missing = [] |
| 342 | for project in all: |
| 343 | if project.gitdir not in fetched: |
| 344 | missing.append(project) |
Shawn O. Pearce | 16614f8 | 2010-10-29 12:05:43 -0700 | [diff] [blame] | 345 | self._Fetch(missing, opt) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 346 | |
Shawn O. Pearce | cd1d7ff | 2009-06-04 16:15:53 -0700 | [diff] [blame] | 347 | if self.manifest.IsMirror: |
| 348 | # bail out now, we have no working tree |
| 349 | return |
| 350 | |
Jaikumar Ganesh | 4f2517f | 2009-06-01 21:10:33 -0700 | [diff] [blame] | 351 | if self.UpdateProjectList(): |
| 352 | sys.exit(1) |
| 353 | |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 354 | syncbuf = SyncBuffer(mp.config, |
| 355 | detach_head = opt.detach_head) |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 356 | pm = Progress('Syncing work tree', len(all)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 357 | for project in all: |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 358 | pm.update() |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 359 | if project.worktree: |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 360 | project.Sync_LocalHalf(syncbuf) |
Shawn O. Pearce | 68194f4 | 2009-04-10 16:48:52 -0700 | [diff] [blame] | 361 | pm.end() |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 362 | print >>sys.stderr |
| 363 | if not syncbuf.Finish(): |
| 364 | sys.exit(1) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 365 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 366 | # If there's a notice that's supposed to print at the end of the sync, print |
| 367 | # it now... |
| 368 | if self.manifest.notice: |
| 369 | print self.manifest.notice |
| 370 | |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 371 | def _PostRepoUpgrade(manifest): |
| 372 | for project in manifest.projects.values(): |
| 373 | if project.Exists: |
| 374 | project.PostRepoUpgrade() |
| 375 | |
| 376 | def _PostRepoFetch(rp, no_repo_verify=False, verbose=False): |
| 377 | if rp.HasChanges: |
| 378 | print >>sys.stderr, 'info: A new version of repo is available' |
| 379 | print >>sys.stderr, '' |
| 380 | if no_repo_verify or _VerifyTag(rp): |
Shawn O. Pearce | 350cde4 | 2009-04-16 11:21:18 -0700 | [diff] [blame] | 381 | syncbuf = SyncBuffer(rp.config) |
| 382 | rp.Sync_LocalHalf(syncbuf) |
| 383 | if not syncbuf.Finish(): |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 384 | sys.exit(1) |
| 385 | print >>sys.stderr, 'info: Restarting repo with latest version' |
| 386 | raise RepoChangedException(['--repo-upgraded']) |
| 387 | else: |
| 388 | print >>sys.stderr, 'warning: Skipped upgrade to unverified version' |
| 389 | else: |
| 390 | if verbose: |
| 391 | print >>sys.stderr, 'repo version %s is current' % rp.work_git.describe(HEAD) |
| 392 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 393 | def _VerifyTag(project): |
| 394 | gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') |
| 395 | if not os.path.exists(gpg_dir): |
| 396 | print >>sys.stderr,\ |
| 397 | """warning: GnuPG was not available during last "repo init" |
| 398 | warning: Cannot automatically authenticate repo.""" |
| 399 | return True |
| 400 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | try: |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 402 | cur = project.bare_git.describe(project.GetRevisionId()) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 403 | except GitError: |
| 404 | cur = None |
| 405 | |
| 406 | if not cur \ |
| 407 | 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] | 408 | rev = project.revisionExpr |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 409 | if rev.startswith(R_HEADS): |
| 410 | rev = rev[len(R_HEADS):] |
| 411 | |
| 412 | print >>sys.stderr |
| 413 | print >>sys.stderr,\ |
| 414 | "warning: project '%s' branch '%s' is not signed" \ |
| 415 | % (project.name, rev) |
| 416 | return False |
| 417 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame] | 418 | env = os.environ.copy() |
| 419 | env['GIT_DIR'] = project.gitdir.encode() |
| 420 | env['GNUPGHOME'] = gpg_dir.encode() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 421 | |
| 422 | cmd = [GIT, 'tag', '-v', cur] |
| 423 | proc = subprocess.Popen(cmd, |
| 424 | stdout = subprocess.PIPE, |
| 425 | stderr = subprocess.PIPE, |
| 426 | env = env) |
| 427 | out = proc.stdout.read() |
| 428 | proc.stdout.close() |
| 429 | |
| 430 | err = proc.stderr.read() |
| 431 | proc.stderr.close() |
| 432 | |
| 433 | if proc.wait() != 0: |
| 434 | print >>sys.stderr |
| 435 | print >>sys.stderr, out |
| 436 | print >>sys.stderr, err |
| 437 | print >>sys.stderr |
| 438 | return False |
| 439 | return True |