Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: repo

Issue 2340073002: repo: update to v1.12.17-cr1 (Closed)
Patch Set: repo: update to v1.12.34-cr2 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 ## repo default configuration 3 # repo default configuration
4 ## 4 #
5 REPO_URL='https://chromium.googlesource.com/external/repo' 5 import os
6 REPO_REV='stable' 6 REPO_URL = os.environ.get('REPO_URL', None)
7 if not REPO_URL:
8 REPO_URL = 'https://chromium.googlesource.com/external/repo'
9 REPO_REV = 'stable'
7 10
8 # Copyright (C) 2008 Google Inc. 11 # Copyright (C) 2008 Google Inc.
9 # 12 #
10 # Licensed under the Apache License, Version 2.0 (the "License"); 13 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License. 14 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at 15 # You may obtain a copy of the License at
13 # 16 #
14 # http://www.apache.org/licenses/LICENSE-2.0 17 # http://www.apache.org/licenses/LICENSE-2.0
15 # 18 #
16 # Unless required by applicable law or agreed to in writing, software 19 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS, 20 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and 22 # See the License for the specific language governing permissions and
20 # limitations under the License. 23 # limitations under the License.
21 24
22 # increment this whenever we make important changes to this script 25 # increment this whenever we make important changes to this script
23 VERSION = (1, 21) 26 VERSION = (1, 23)
24 27
25 # increment this if the MAINTAINER_KEYS block is modified 28 # increment this if the MAINTAINER_KEYS block is modified
26 KEYRING_VERSION = (1, 5) 29 KEYRING_VERSION = (1, 5)
27 MAINTAINER_KEYS = """ 30 MAINTAINER_KEYS = """
28 31
29 Repo Maintainer <repo@android.kernel.org> 32 Repo Maintainer <repo@android.kernel.org>
30 -----BEGIN PGP PUBLIC KEY BLOCK----- 33 -----BEGIN PGP PUBLIC KEY BLOCK-----
31 Version: GnuPG v1.4.2.2 (GNU/Linux) 34 Version: GnuPG v1.4.2.2 (GNU/Linux)
32 35
33 mQGiBEj3ugERBACrLJh/ZPyVSKeClMuznFIrsQ+hpNnmJGw1a9GXKYKk8qHPhAZf 36 mQGiBEj3ugERBACrLJh/ZPyVSKeClMuznFIrsQ+hpNnmJGw1a9GXKYKk8qHPhAZf
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 pwBTNUTf9u1wyfm5VUXpW541oVmqAWWHTZh2HVeBW6F1YtsqItZXcNjt6HTL1Qou 224 pwBTNUTf9u1wyfm5VUXpW541oVmqAWWHTZh2HVeBW6F1YtsqItZXcNjt6HTL1Qou
222 Dn+mK+tV0egPsus0tnfmps6ONhvxfZtkRWsJkQ0EDh8SbIEnBd8zolXXJnDSTpjL 225 Dn+mK+tV0egPsus0tnfmps6ONhvxfZtkRWsJkQ0EDh8SbIEnBd8zolXXJnDSTpjL
223 n9Sf5d2wH3L2SI53vhMouSB1UmhPhwNq7sFeTvYJ1juqmVdN+eQj5OxSvhOceAE8 226 n9Sf5d2wH3L2SI53vhMouSB1UmhPhwNq7sFeTvYJ1juqmVdN+eQj5OxSvhOceAE8
224 cT2GjBrfkP6Gcw8fPESLqJLx6jpyPrHS/TK1GNCnGZihDsZRNIcfpS9T1LoFKuHn 227 cT2GjBrfkP6Gcw8fPESLqJLx6jpyPrHS/TK1GNCnGZihDsZRNIcfpS9T1LoFKuHn
225 eRZoYnWnFIZVjD9OLmRq3I2RcktWHFpAjWE3naSybXhfL++mp04PQyV2CUFVF6zY 228 eRZoYnWnFIZVjD9OLmRq3I2RcktWHFpAjWE3naSybXhfL++mp04PQyV2CUFVF6zY
226 2nPL/TtwSF0WmReP2qO7gsuEhR0BuPaXEC3dihTpMZ4hkbe3F+aJ7VEEU9dKDUM= 229 2nPL/TtwSF0WmReP2qO7gsuEhR0BuPaXEC3dihTpMZ4hkbe3F+aJ7VEEU9dKDUM=
227 =i88c 230 =i88c
228 -----END PGP PUBLIC KEY BLOCK----- 231 -----END PGP PUBLIC KEY BLOCK-----
229 """ 232 """
230 233
231 GIT = 'git' # our git command 234 GIT = 'git' # our git command
232 MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version 235 MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version
233 repodir = '.repo' # name of repo's private directory 236 repodir = '.repo' # name of repo's private directory
234 S_repo = 'repo' # special repo repository 237 S_repo = 'repo' # special repo repository
235 S_manifests = 'manifests' # special manifest repository 238 S_manifests = 'manifests' # special manifest repository
236 REPO_MAIN = S_repo + '/main.py' # main script 239 REPO_MAIN = S_repo + '/main.py' # main script
237 MIN_PYTHON_VERSION = (2, 6) # minimum supported python version 240 MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
241 GITC_CONFIG_FILE = '/gitc/.config'
242 GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
238 243
239 244
240 import errno 245 import errno
241 import optparse 246 import optparse
242 import os
243 import re 247 import re
244 import shutil 248 import shutil
245 import stat 249 import stat
246 import subprocess 250 import subprocess
247 import sys 251 import sys
248 252
249 if sys.version_info[0] == 3: 253 if sys.version_info[0] == 3:
250 import urllib.request 254 import urllib.request
251 import urllib.error 255 import urllib.error
252 else: 256 else:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 group.add_option('-g', '--groups', 316 group.add_option('-g', '--groups',
313 dest='groups', default='default', 317 dest='groups', default='default',
314 help='restrict manifest projects to ones with specified ' 318 help='restrict manifest projects to ones with specified '
315 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]', 319 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
316 metavar='GROUP') 320 metavar='GROUP')
317 group.add_option('-p', '--platform', 321 group.add_option('-p', '--platform',
318 dest='platform', default="auto", 322 dest='platform', default="auto",
319 help='restrict manifest projects to ones with a specified ' 323 help='restrict manifest projects to ones with a specified '
320 'platform group [auto|all|none|linux|darwin|...]', 324 'platform group [auto|all|none|linux|darwin|...]',
321 metavar='PLATFORM') 325 metavar='PLATFORM')
326 group.add_option('--no-clone-bundle',
327 dest='no_clone_bundle', action='store_true',
328 help='disable use of /clone.bundle on HTTP/HTTPS')
322 329
323 330
324 # Tool 331 # Tool
325 group = init_optparse.add_option_group('repo Version options') 332 group = init_optparse.add_option_group('repo Version options')
326 group.add_option('--repo-url', 333 group.add_option('--repo-url',
327 dest='repo_url', 334 dest='repo_url',
328 help='repo repository location', metavar='URL') 335 help='repo repository location', metavar='URL')
329 group.add_option('--repo-branch', 336 group.add_option('--repo-branch',
330 dest='repo_branch', 337 dest='repo_branch',
331 help='repo branch or revision', metavar='REVISION') 338 help='repo branch or revision', metavar='REVISION')
332 group.add_option('--no-repo-verify', 339 group.add_option('--no-repo-verify',
333 dest='no_repo_verify', action='store_true', 340 dest='no_repo_verify', action='store_true',
334 help='do not verify repo source code') 341 help='do not verify repo source code')
335 342
336 # Other 343 # Other
337 group = init_optparse.add_option_group('Other options') 344 group = init_optparse.add_option_group('Other options')
338 group.add_option('--config-name', 345 group.add_option('--config-name',
339 dest='config_name', action="store_true", default=False, 346 dest='config_name', action="store_true", default=False,
340 help='Always prompt for name/e-mail') 347 help='Always prompt for name/e-mail')
341 348
349
350 def _GitcInitOptions(init_optparse_arg):
351 init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]")
352 g = init_optparse_arg.add_option_group('GITC options')
353 g.add_option('-f', '--manifest-file',
354 dest='manifest_file',
355 help='Optional manifest file to use for this GITC client.')
356 g.add_option('-c', '--gitc-client',
357 dest='gitc_client',
358 help='The name of the gitc_client instance to create or modify.')
359
360 _gitc_manifest_dir = None
361
362
363 def get_gitc_manifest_dir():
364 global _gitc_manifest_dir
365 if _gitc_manifest_dir is None:
366 _gitc_manifest_dir = ''
367 try:
368 with open(GITC_CONFIG_FILE, 'r') as gitc_config:
369 for line in gitc_config:
370 match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
371 if match:
372 _gitc_manifest_dir = match.group('gitc_manifest_dir')
373 except IOError:
374 pass
375 return _gitc_manifest_dir
376
377
378 def gitc_parse_clientdir(gitc_fs_path):
379 """Parse a path in the GITC FS and return its client name.
380
381 @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
382
383 @returns: The GITC client name
384 """
385 if gitc_fs_path == GITC_FS_ROOT_DIR:
386 return None
387 if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR):
388 manifest_dir = get_gitc_manifest_dir()
389 if manifest_dir == '':
390 return None
391 if manifest_dir[-1] != '/':
392 manifest_dir += '/'
393 if gitc_fs_path == manifest_dir:
394 return None
395 if not gitc_fs_path.startswith(manifest_dir):
396 return None
397 return gitc_fs_path.split(manifest_dir)[1].split('/')[0]
398 return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0]
399
400
342 class CloneFailure(Exception): 401 class CloneFailure(Exception):
402
343 """Indicate the remote clone of repo itself failed. 403 """Indicate the remote clone of repo itself failed.
344 """ 404 """
345 405
346 406
347 def _Init(args): 407 def _Init(args, gitc_init=False):
348 """Installs repo by cloning it over the network. 408 """Installs repo by cloning it over the network.
349 """ 409 """
410 if gitc_init:
411 _GitcInitOptions(init_optparse)
350 opt, args = init_optparse.parse_args(args) 412 opt, args = init_optparse.parse_args(args)
351 if args: 413 if args:
352 init_optparse.print_usage() 414 init_optparse.print_usage()
353 sys.exit(1) 415 sys.exit(1)
354 416
355 url = opt.repo_url 417 url = opt.repo_url
356 if not url: 418 if not url:
357 url = REPO_URL 419 url = REPO_URL
358 extra_args.append('--repo-url=%s' % url) 420 extra_args.append('--repo-url=%s' % url)
359 421
360 branch = opt.repo_branch 422 branch = opt.repo_branch
361 if not branch: 423 if not branch:
362 branch = REPO_REV 424 branch = REPO_REV
363 extra_args.append('--repo-branch=%s' % branch) 425 extra_args.append('--repo-branch=%s' % branch)
364 426
365 if branch.startswith('refs/heads/'): 427 if branch.startswith('refs/heads/'):
366 branch = branch[len('refs/heads/'):] 428 branch = branch[len('refs/heads/'):]
367 if branch.startswith('refs/'): 429 if branch.startswith('refs/'):
368 _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) 430 _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
369 raise CloneFailure() 431 raise CloneFailure()
370 432
371 try: 433 try:
434 if gitc_init:
435 gitc_manifest_dir = get_gitc_manifest_dir()
436 if not gitc_manifest_dir:
437 _print('fatal: GITC filesystem is not available. Exiting...',
438 file=sys.stderr)
439 sys.exit(1)
440 gitc_client = opt.gitc_client
441 if not gitc_client:
442 gitc_client = gitc_parse_clientdir(os.getcwd())
443 if not gitc_client:
444 _print('fatal: GITC client (-c) is required.', file=sys.stderr)
445 sys.exit(1)
446 client_dir = os.path.join(gitc_manifest_dir, gitc_client)
447 if not os.path.exists(client_dir):
448 os.makedirs(client_dir)
449 os.chdir(client_dir)
450 if os.path.exists(repodir):
451 # This GITC Client has already initialized repo so continue.
452 return
453
372 os.mkdir(repodir) 454 os.mkdir(repodir)
373 except OSError as e: 455 except OSError as e:
374 if e.errno != errno.EEXIST: 456 if e.errno != errno.EEXIST:
375 _print('fatal: cannot make %s directory: %s' 457 _print('fatal: cannot make %s directory: %s'
376 % (repodir, e.strerror), file=sys.stderr) 458 % (repodir, e.strerror), file=sys.stderr)
377 # Don't raise CloneFailure; that would delete the 459 # Don't raise CloneFailure; that would delete the
378 # name. Instead exit immediately. 460 # name. Instead exit immediately.
379 # 461 #
380 sys.exit(1) 462 sys.exit(1)
381 463
382 _CheckGitVersion() 464 _CheckGitVersion()
383 try: 465 try:
384 if NeedSetupGnuPG(): 466 if NeedSetupGnuPG():
385 can_verify = SetupGnuPG(opt.quiet) 467 can_verify = SetupGnuPG(opt.quiet)
386 else: 468 else:
387 can_verify = True 469 can_verify = True
388 470
389 dst = os.path.abspath(os.path.join(repodir, S_repo)) 471 dst = os.path.abspath(os.path.join(repodir, S_repo))
390 _Clone(url, dst, opt.quiet) 472 _Clone(url, dst, opt.quiet, not opt.no_clone_bundle)
391 473
392 if can_verify and not opt.no_repo_verify: 474 if can_verify and not opt.no_repo_verify:
393 rev = _Verify(dst, branch, opt.quiet) 475 rev = _Verify(dst, branch, opt.quiet)
394 else: 476 else:
395 rev = 'refs/remotes/origin/%s^0' % branch 477 rev = 'refs/remotes/origin/%s^0' % branch
396 478
397 _Checkout(dst, branch, rev, opt.quiet) 479 _Checkout(dst, branch, rev, opt.quiet)
398 except CloneFailure: 480 except CloneFailure:
399 if opt.quiet: 481 if opt.quiet:
400 _print('fatal: repo init failed; run without --quiet to see why', 482 _print('fatal: repo init failed; run without --quiet to see why',
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 555
474 try: 556 try:
475 os.mkdir(gpg_dir, stat.S_IRWXU) 557 os.mkdir(gpg_dir, stat.S_IRWXU)
476 except OSError as e: 558 except OSError as e:
477 if e.errno != errno.EEXIST: 559 if e.errno != errno.EEXIST:
478 _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), 560 _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
479 file=sys.stderr) 561 file=sys.stderr)
480 sys.exit(1) 562 sys.exit(1)
481 563
482 env = os.environ.copy() 564 env = os.environ.copy()
483 env['GNUPGHOME'] = gpg_dir.encode() 565 try:
566 env['GNUPGHOME'] = gpg_dir
567 except UnicodeEncodeError:
568 env['GNUPGHOME'] = gpg_dir.encode()
484 569
485 cmd = ['gpg', '--import'] 570 cmd = ['gpg', '--import']
486 try: 571 try:
487 proc = subprocess.Popen(cmd, 572 proc = subprocess.Popen(cmd,
488 env = env, 573 env=env,
489 stdin = subprocess.PIPE) 574 stdin=subprocess.PIPE)
490 except OSError as e: 575 except OSError as e:
491 if not quiet: 576 if not quiet:
492 _print('warning: gpg (GnuPG) is not available.', file=sys.stderr) 577 _print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
493 _print('warning: Installing it is strongly encouraged.', file=sys.stderr) 578 _print('warning: Installing it is strongly encouraged.', file=sys.stderr)
494 _print(file=sys.stderr) 579 _print(file=sys.stderr)
495 return False 580 return False
496 581
497 proc.stdin.write(MAINTAINER_KEYS) 582 proc.stdin.write(MAINTAINER_KEYS)
498 proc.stdin.close() 583 proc.stdin.close()
499 584
500 if proc.wait() != 0: 585 if proc.wait() != 0:
501 _print('fatal: registering repo maintainer keys failed', file=sys.stderr) 586 _print('fatal: registering repo maintainer keys failed', file=sys.stderr)
502 sys.exit(1) 587 sys.exit(1)
503 _print() 588 _print()
504 589
505 fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w') 590 fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
506 fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n') 591 fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
507 fd.close() 592 fd.close()
508 return True 593 return True
509 594
510 595
511 def _SetConfig(local, name, value): 596 def _SetConfig(local, name, value):
512 """Set a git configuration option to the specified value. 597 """Set a git configuration option to the specified value.
513 """ 598 """
514 cmd = [GIT, 'config', name, value] 599 cmd = [GIT, 'config', name, value]
515 if subprocess.Popen(cmd, cwd = local).wait() != 0: 600 if subprocess.Popen(cmd, cwd=local).wait() != 0:
516 raise CloneFailure() 601 raise CloneFailure()
517 602
518 603
519 def _InitHttp(): 604 def _InitHttp():
520 handlers = [] 605 handlers = []
521 606
522 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() 607 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
523 try: 608 try:
524 import netrc 609 import netrc
525 n = netrc.netrc() 610 n = netrc.netrc()
526 for host in n.hosts: 611 for host in n.hosts:
527 p = n.hosts[host] 612 p = n.hosts[host]
528 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2]) 613 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
529 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) 614 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
530 except: 615 except: # pylint: disable=bare-except
531 pass 616 pass
532 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr)) 617 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
533 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr)) 618 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
534 619
535 if 'http_proxy' in os.environ: 620 if 'http_proxy' in os.environ:
536 url = os.environ['http_proxy'] 621 url = os.environ['http_proxy']
537 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url})) 622 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
538 if 'REPO_CURL_VERBOSE' in os.environ: 623 if 'REPO_CURL_VERBOSE' in os.environ:
539 handlers.append(urllib.request.HTTPHandler(debuglevel=1)) 624 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
540 handlers.append(urllib.request.HTTPSHandler(debuglevel=1)) 625 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
541 urllib.request.install_opener(urllib.request.build_opener(*handlers)) 626 urllib.request.install_opener(urllib.request.build_opener(*handlers))
542 627
628
543 def _Fetch(url, local, src, quiet): 629 def _Fetch(url, local, src, quiet):
544 if not quiet: 630 if not quiet:
545 _print('Get %s' % url, file=sys.stderr) 631 _print('Get %s' % url, file=sys.stderr)
546 632
547 cmd = [GIT, 'fetch'] 633 cmd = [GIT, 'fetch']
548 if quiet: 634 if quiet:
549 cmd.append('--quiet') 635 cmd.append('--quiet')
550 err = subprocess.PIPE 636 err = subprocess.PIPE
551 else: 637 else:
552 err = None 638 err = None
553 cmd.append(src) 639 cmd.append(src)
554 cmd.append('+refs/heads/*:refs/remotes/origin/*') 640 cmd.append('+refs/heads/*:refs/remotes/origin/*')
555 cmd.append('refs/tags/*:refs/tags/*') 641 cmd.append('refs/tags/*:refs/tags/*')
556 642
557 proc = subprocess.Popen(cmd, cwd = local, stderr = err) 643 proc = subprocess.Popen(cmd, cwd=local, stderr=err)
558 if err: 644 if err:
559 proc.stderr.read() 645 proc.stderr.read()
560 proc.stderr.close() 646 proc.stderr.close()
561 if proc.wait() != 0: 647 if proc.wait() != 0:
562 raise CloneFailure() 648 raise CloneFailure()
563 649
650
564 def _DownloadBundle(url, local, quiet): 651 def _DownloadBundle(url, local, quiet):
565 if not url.endswith('/'): 652 if not url.endswith('/'):
566 url += '/' 653 url += '/'
567 url += 'clone.bundle' 654 url += 'clone.bundle'
568 655
569 proc = subprocess.Popen( 656 proc = subprocess.Popen(
570 [GIT, 'config', '--get-regexp', 'url.*.insteadof'], 657 [GIT, 'config', '--get-regexp', 'url.*.insteadof'],
571 cwd = local, 658 cwd=local,
572 stdout = subprocess.PIPE) 659 stdout=subprocess.PIPE)
573 for line in proc.stdout: 660 for line in proc.stdout:
574 m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line) 661 m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
575 if m: 662 if m:
576 new_url = m.group(1) 663 new_url = m.group(1)
577 old_url = m.group(2) 664 old_url = m.group(2)
578 if url.startswith(old_url): 665 if url.startswith(old_url):
579 url = new_url + url[len(old_url):] 666 url = new_url + url[len(old_url):]
580 break 667 break
581 proc.stdout.close() 668 proc.stdout.close()
582 proc.wait() 669 proc.wait()
583 670
584 if not url.startswith('http:') and not url.startswith('https:'): 671 if not url.startswith('http:') and not url.startswith('https:'):
585 return False 672 return False
586 673
587 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') 674 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
588 try: 675 try:
589 try: 676 try:
590 r = urllib.request.urlopen(url) 677 r = urllib.request.urlopen(url)
591 except urllib.error.HTTPError as e: 678 except urllib.error.HTTPError as e:
592 if e.code in [403, 404]: 679 if e.code in [401, 403, 404, 501]:
593 return False 680 return False
594 _print('fatal: Cannot get %s' % url, file=sys.stderr) 681 _print('fatal: Cannot get %s' % url, file=sys.stderr)
595 _print('fatal: HTTP error %s' % e.code, file=sys.stderr) 682 _print('fatal: HTTP error %s' % e.code, file=sys.stderr)
596 raise CloneFailure() 683 raise CloneFailure()
597 except urllib.error.URLError as e: 684 except urllib.error.URLError as e:
598 _print('fatal: Cannot get %s' % url, file=sys.stderr) 685 _print('fatal: Cannot get %s' % url, file=sys.stderr)
599 _print('fatal: error %s' % e.reason, file=sys.stderr) 686 _print('fatal: error %s' % e.reason, file=sys.stderr)
600 raise CloneFailure() 687 raise CloneFailure()
601 try: 688 try:
602 if not quiet: 689 if not quiet:
603 _print('Get %s' % url, file=sys.stderr) 690 _print('Get %s' % url, file=sys.stderr)
604 while True: 691 while True:
605 buf = r.read(8192) 692 buf = r.read(8192)
606 if buf == '': 693 if buf == '':
607 return True 694 return True
608 dest.write(buf) 695 dest.write(buf)
609 finally: 696 finally:
610 r.close() 697 r.close()
611 finally: 698 finally:
612 dest.close() 699 dest.close()
613 700
701
614 def _ImportBundle(local): 702 def _ImportBundle(local):
615 path = os.path.join(local, '.git', 'clone.bundle') 703 path = os.path.join(local, '.git', 'clone.bundle')
616 try: 704 try:
617 _Fetch(local, local, path, True) 705 _Fetch(local, local, path, True)
618 finally: 706 finally:
619 os.remove(path) 707 os.remove(path)
620 708
621 def _Clone(url, local, quiet): 709
710 def _Clone(url, local, quiet, clone_bundle):
622 """Clones a git repository to a new subdirectory of repodir 711 """Clones a git repository to a new subdirectory of repodir
623 """ 712 """
624 try: 713 try:
625 os.mkdir(local) 714 os.mkdir(local)
626 except OSError as e: 715 except OSError as e:
627 _print('fatal: cannot make %s directory: %s' % (local, e.strerror), 716 _print('fatal: cannot make %s directory: %s' % (local, e.strerror),
628 file=sys.stderr) 717 file=sys.stderr)
629 raise CloneFailure() 718 raise CloneFailure()
630 719
631 cmd = [GIT, 'init', '--quiet'] 720 cmd = [GIT, 'init', '--quiet']
632 try: 721 try:
633 proc = subprocess.Popen(cmd, cwd = local) 722 proc = subprocess.Popen(cmd, cwd=local)
634 except OSError as e: 723 except OSError as e:
635 _print(file=sys.stderr) 724 _print(file=sys.stderr)
636 _print("fatal: '%s' is not available" % GIT, file=sys.stderr) 725 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
637 _print('fatal: %s' % e, file=sys.stderr) 726 _print('fatal: %s' % e, file=sys.stderr)
638 _print(file=sys.stderr) 727 _print(file=sys.stderr)
639 _print('Please make sure %s is installed and in your path.' % GIT, 728 _print('Please make sure %s is installed and in your path.' % GIT,
640 file=sys.stderr) 729 file=sys.stderr)
641 raise CloneFailure() 730 raise CloneFailure()
642 if proc.wait() != 0: 731 if proc.wait() != 0:
643 _print('fatal: could not create %s' % local, file=sys.stderr) 732 _print('fatal: could not create %s' % local, file=sys.stderr)
644 raise CloneFailure() 733 raise CloneFailure()
645 734
646 _InitHttp() 735 _InitHttp()
647 _SetConfig(local, 'remote.origin.url', url) 736 _SetConfig(local, 'remote.origin.url', url)
648 _SetConfig(local, 'remote.origin.fetch', 737 _SetConfig(local,
649 '+refs/heads/*:refs/remotes/origin/*') 738 'remote.origin.fetch',
650 if _DownloadBundle(url, local, quiet): 739 '+refs/heads/*:refs/remotes/origin/*')
740 if clone_bundle and _DownloadBundle(url, local, quiet):
651 _ImportBundle(local) 741 _ImportBundle(local)
652 else: 742 _Fetch(url, local, 'origin', quiet)
653 _Fetch(url, local, 'origin', quiet)
654 743
655 744
656 def _Verify(cwd, branch, quiet): 745 def _Verify(cwd, branch, quiet):
657 """Verify the branch has been signed by a tag. 746 """Verify the branch has been signed by a tag.
658 """ 747 """
659 cmd = [GIT, 'describe', 'origin/%s' % branch] 748 cmd = [GIT, 'describe', 'origin/%s' % branch]
660 proc = subprocess.Popen(cmd, 749 proc = subprocess.Popen(cmd,
661 stdout=subprocess.PIPE, 750 stdout=subprocess.PIPE,
662 stderr=subprocess.PIPE, 751 stderr=subprocess.PIPE,
663 cwd = cwd) 752 cwd=cwd)
664 cur = proc.stdout.read().strip() 753 cur = proc.stdout.read().strip()
665 proc.stdout.close() 754 proc.stdout.close()
666 755
667 proc.stderr.read() 756 proc.stderr.read()
668 proc.stderr.close() 757 proc.stderr.close()
669 758
670 if proc.wait() != 0 or not cur: 759 if proc.wait() != 0 or not cur:
671 _print(file=sys.stderr) 760 _print(file=sys.stderr)
672 _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) 761 _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
673 raise CloneFailure() 762 raise CloneFailure()
674 763
675 m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) 764 m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
676 if m: 765 if m:
677 cur = m.group(1) 766 cur = m.group(1)
678 if not quiet: 767 if not quiet:
679 _print(file=sys.stderr) 768 _print(file=sys.stderr)
680 _print("info: Ignoring branch '%s'; using tagged release '%s'" 769 _print("info: Ignoring branch '%s'; using tagged release '%s'"
681 % (branch, cur), file=sys.stderr) 770 % (branch, cur), file=sys.stderr)
682 _print(file=sys.stderr) 771 _print(file=sys.stderr)
683 772
684 env = os.environ.copy() 773 env = os.environ.copy()
685 env['GNUPGHOME'] = gpg_dir.encode() 774 try:
775 env['GNUPGHOME'] = gpg_dir
776 except UnicodeEncodeError:
777 env['GNUPGHOME'] = gpg_dir.encode()
686 778
687 cmd = [GIT, 'tag', '-v', cur] 779 cmd = [GIT, 'tag', '-v', cur]
688 proc = subprocess.Popen(cmd, 780 proc = subprocess.Popen(cmd,
689 stdout = subprocess.PIPE, 781 stdout=subprocess.PIPE,
690 stderr = subprocess.PIPE, 782 stderr=subprocess.PIPE,
691 cwd = cwd, 783 cwd=cwd,
692 env = env) 784 env=env)
693 out = proc.stdout.read() 785 out = proc.stdout.read()
694 proc.stdout.close() 786 proc.stdout.close()
695 787
696 err = proc.stderr.read() 788 err = proc.stderr.read()
697 proc.stderr.close() 789 proc.stderr.close()
698 790
699 if proc.wait() != 0: 791 if proc.wait() != 0:
700 _print(file=sys.stderr) 792 _print(file=sys.stderr)
701 _print(out, file=sys.stderr) 793 _print(out, file=sys.stderr)
702 _print(err, file=sys.stderr) 794 _print(err, file=sys.stderr)
703 _print(file=sys.stderr) 795 _print(file=sys.stderr)
704 raise CloneFailure() 796 raise CloneFailure()
705 return '%s^0' % cur 797 return '%s^0' % cur
706 798
707 799
708 def _Checkout(cwd, branch, rev, quiet): 800 def _Checkout(cwd, branch, rev, quiet):
709 """Checkout an upstream branch into the repository and track it. 801 """Checkout an upstream branch into the repository and track it.
710 """ 802 """
711 cmd = [GIT, 'update-ref', 'refs/heads/default', rev] 803 cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
712 if subprocess.Popen(cmd, cwd = cwd).wait() != 0: 804 if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
713 raise CloneFailure() 805 raise CloneFailure()
714 806
715 _SetConfig(cwd, 'branch.default.remote', 'origin') 807 _SetConfig(cwd, 'branch.default.remote', 'origin')
716 _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch) 808 _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
717 809
718 cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default'] 810 cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
719 if subprocess.Popen(cmd, cwd = cwd).wait() != 0: 811 if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
720 raise CloneFailure() 812 raise CloneFailure()
721 813
722 cmd = [GIT, 'read-tree', '--reset', '-u'] 814 cmd = [GIT, 'read-tree', '--reset', '-u']
723 if not quiet: 815 if not quiet:
724 cmd.append('-v') 816 cmd.append('-v')
725 cmd.append('HEAD') 817 cmd.append('HEAD')
726 if subprocess.Popen(cmd, cwd = cwd).wait() != 0: 818 if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
727 raise CloneFailure() 819 raise CloneFailure()
728 820
729 821
730 def _FindRepo(): 822 def _FindRepo():
731 """Look for a repo installation, starting at the current directory. 823 """Look for a repo installation, starting at the current directory.
732 """ 824 """
733 curdir = os.getcwd() 825 curdir = os.getcwd()
734 repo = None 826 repo = None
735 827
736 olddir = None 828 olddir = None
737 while curdir != '/' \ 829 while curdir != '/' \
738 and curdir != olddir \ 830 and curdir != olddir \
739 and not repo: 831 and not repo:
740 repo = os.path.join(curdir, repodir, REPO_MAIN) 832 repo = os.path.join(curdir, repodir, REPO_MAIN)
741 if not os.path.isfile(repo): 833 if not os.path.isfile(repo):
742 repo = None 834 repo = None
743 olddir = curdir 835 olddir = curdir
744 curdir = os.path.dirname(curdir) 836 curdir = os.path.dirname(curdir)
745 return (repo, os.path.join(curdir, repodir)) 837 return (repo, os.path.join(curdir, repodir))
746 838
747 839
748 class _Options: 840 class _Options(object):
749 help = False 841 help = False
750 842
751 843
752 def _ParseArguments(args): 844 def _ParseArguments(args):
753 cmd = None 845 cmd = None
754 opt = _Options() 846 opt = _Options()
755 arg = [] 847 arg = []
756 848
757 for i in range(len(args)): 849 for i in range(len(args)):
758 a = args[i] 850 a = args[i]
759 if a == '-h' or a == '--help': 851 if a == '-h' or a == '--help':
760 opt.help = True 852 opt.help = True
761 853
762 elif not a.startswith('-'): 854 elif not a.startswith('-'):
763 cmd = a 855 cmd = a
764 arg = args[i + 1:] 856 arg = args[i + 1:]
765 break 857 break
766 return cmd, opt, arg 858 return cmd, opt, arg
767 859
768 860
769 def _Usage(): 861 def _Usage():
862 gitc_usage = ""
863 if get_gitc_manifest_dir():
864 gitc_usage = " gitc-init Initialize a GITC Client.\n"
865
770 _print( 866 _print(
771 """usage: repo COMMAND [ARGS] 867 """usage: repo COMMAND [ARGS]
772 868
773 repo is not yet installed. Use "repo init" to install it here. 869 repo is not yet installed. Use "repo init" to install it here.
774 870
775 The most commonly used repo commands are: 871 The most commonly used repo commands are:
776 872
777 init Install repo in the current working directory 873 init Install repo in the current working directory
778 help Display detailed help on a command 874 """ + gitc_usage +
875 """ help Display detailed help on a command
779 876
780 For access to the full online help, install repo ("repo init"). 877 For access to the full online help, install repo ("repo init").
781 """, file=sys.stderr) 878 """, file=sys.stderr)
782 sys.exit(1) 879 sys.exit(1)
783 880
784 881
785 def _Help(args): 882 def _Help(args):
786 if args: 883 if args:
787 if args[0] == 'init': 884 if args[0] == 'init':
788 init_optparse.print_help() 885 init_optparse.print_help()
789 sys.exit(0) 886 sys.exit(0)
887 elif args[0] == 'gitc-init':
888 _GitcInitOptions(init_optparse)
889 init_optparse.print_help()
890 sys.exit(0)
790 else: 891 else:
791 _print("error: '%s' is not a bootstrap command.\n" 892 _print("error: '%s' is not a bootstrap command.\n"
792 ' For access to online help, install repo ("repo init").' 893 ' For access to online help, install repo ("repo init").'
793 % args[0], file=sys.stderr) 894 % args[0], file=sys.stderr)
794 else: 895 else:
795 _Usage() 896 _Usage()
796 sys.exit(1) 897 sys.exit(1)
797 898
798 899
799 def _NotInstalled(): 900 def _NotInstalled():
(...skipping 25 matching lines...) Expand all
825 926
826 def _SetDefaultsTo(gitdir): 927 def _SetDefaultsTo(gitdir):
827 global REPO_URL 928 global REPO_URL
828 global REPO_REV 929 global REPO_REV
829 930
830 REPO_URL = gitdir 931 REPO_URL = gitdir
831 proc = subprocess.Popen([GIT, 932 proc = subprocess.Popen([GIT,
832 '--git-dir=%s' % gitdir, 933 '--git-dir=%s' % gitdir,
833 'symbolic-ref', 934 'symbolic-ref',
834 'HEAD'], 935 'HEAD'],
835 stdout = subprocess.PIPE, 936 stdout=subprocess.PIPE,
836 stderr = subprocess.PIPE) 937 stderr=subprocess.PIPE)
837 REPO_REV = proc.stdout.read().strip() 938 REPO_REV = proc.stdout.read().strip()
838 proc.stdout.close() 939 proc.stdout.close()
839 940
840 proc.stderr.read() 941 proc.stderr.read()
841 proc.stderr.close() 942 proc.stderr.close()
842 943
843 if proc.wait() != 0: 944 if proc.wait() != 0:
844 _print('fatal: %s has no current branch' % gitdir, file=sys.stderr) 945 _print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
845 sys.exit(1) 946 sys.exit(1)
846 947
847 948
848 def main(orig_args): 949 def main(orig_args):
849 repo_main, rel_repo_dir = _FindRepo()
850 cmd, opt, args = _ParseArguments(orig_args) 950 cmd, opt, args = _ParseArguments(orig_args)
851 951
952 repo_main, rel_repo_dir = None, None
953 # Don't use the local repo copy, make sure to switch to the gitc client first.
954 if cmd != 'gitc-init':
955 repo_main, rel_repo_dir = _FindRepo()
956
852 wrapper_path = os.path.abspath(__file__) 957 wrapper_path = os.path.abspath(__file__)
853 my_main, my_git = _RunSelf(wrapper_path) 958 my_main, my_git = _RunSelf(wrapper_path)
854 959
960 cwd = os.getcwd()
961 if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
962 _print('error: repo cannot be used in the GITC local manifest directory.'
963 '\nIf you want to work on this GITC client please rerun this '
964 'command from the corresponding client under /gitc/',
965 file=sys.stderr)
966 sys.exit(1)
855 if not repo_main: 967 if not repo_main:
856 if opt.help: 968 if opt.help:
857 _Usage() 969 _Usage()
858 if cmd == 'help': 970 if cmd == 'help':
859 _Help(args) 971 _Help(args)
860 if not cmd: 972 if not cmd:
861 _NotInstalled() 973 _NotInstalled()
862 if cmd == 'init': 974 if cmd == 'init' or cmd == 'gitc-init':
863 if my_git: 975 if my_git:
864 _SetDefaultsTo(my_git) 976 _SetDefaultsTo(my_git)
865 try: 977 try:
866 _Init(args) 978 _Init(args, gitc_init=(cmd == 'gitc-init'))
867 except CloneFailure: 979 except CloneFailure:
868 shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True) 980 shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
869 sys.exit(1) 981 sys.exit(1)
870 repo_main, rel_repo_dir = _FindRepo() 982 repo_main, rel_repo_dir = _FindRepo()
871 else: 983 else:
872 _NoCommands(cmd) 984 _NoCommands(cmd)
873 985
874 if cmd == 'sync' and NeedSetupGnuPG():
875 SetupGnuPG(False)
876
877 if my_main: 986 if my_main:
878 repo_main = my_main 987 repo_main = my_main
879 988
880 ver_str = '.'.join(map(str, VERSION)) 989 ver_str = '.'.join(map(str, VERSION))
881 me = [sys.executable, repo_main, 990 me = [sys.executable, repo_main,
882 '--repo-dir=%s' % rel_repo_dir, 991 '--repo-dir=%s' % rel_repo_dir,
883 '--wrapper-version=%s' % ver_str, 992 '--wrapper-version=%s' % ver_str,
884 '--wrapper-path=%s' % wrapper_path, 993 '--wrapper-path=%s' % wrapper_path,
885 '--'] 994 '--']
886 me.extend(orig_args) 995 me.extend(orig_args)
887 me.extend(extra_args) 996 me.extend(extra_args)
888 try: 997 try:
889 os.execv(sys.executable, me) 998 os.execv(sys.executable, me)
890 except OSError as e: 999 except OSError as e:
891 _print("fatal: unable to start %s" % repo_main, file=sys.stderr) 1000 _print("fatal: unable to start %s" % repo_main, file=sys.stderr)
892 _print("fatal: %s" % e, file=sys.stderr) 1001 _print("fatal: %s" % e, file=sys.stderr)
893 sys.exit(148) 1002 sys.exit(148)
894 1003
895 1004
896 if __name__ == '__main__': 1005 if __name__ == '__main__':
897 if ver[0] == 3: 1006 if ver[0] == 3:
898 _print('warning: Python 3 support is currently experimental. YMMV.\n' 1007 _print('warning: Python 3 support is currently experimental. YMMV.\n'
899 'Please use Python 2.6 - 2.7 instead.', 1008 'Please use Python 2.6 - 2.7 instead.',
900 file=sys.stderr) 1009 file=sys.stderr)
901 main(sys.argv[1:]) 1010 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698