diff options
-rw-r--r-- | git_config.py | 11 | ||||
-rwxr-xr-x | repo | 133 | ||||
-rw-r--r-- | subcmds/sync.py | 5 |
3 files changed, 78 insertions, 71 deletions
diff --git a/git_config.py b/git_config.py index 2270200c..a294a0b6 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -596,14 +596,11 @@ class Remote(object): | |||
596 | try: | 596 | try: |
597 | info_url = u + 'ssh_info' | 597 | info_url = u + 'ssh_info' |
598 | info = urllib.request.urlopen(info_url).read() | 598 | info = urllib.request.urlopen(info_url).read() |
599 | if '<' in info: | 599 | if info == 'NOT_AVAILABLE' or '<' in info: |
600 | # Assume the server gave us some sort of HTML | 600 | # If `info` contains '<', we assume the server gave us some sort |
601 | # response back, like maybe a login page. | 601 | # of HTML response back, like maybe a login page. |
602 | # | 602 | # |
603 | raise UploadError('%s: Cannot parse response' % info_url) | 603 | # Assume HTTP if SSH is not enabled or ssh_info doesn't look right. |
604 | |||
605 | if info == 'NOT_AVAILABLE': | ||
606 | # Assume HTTP if SSH is not enabled. | ||
607 | self._review_url = http_url + 'p/' | 604 | self._review_url = http_url + 'p/' |
608 | else: | 605 | else: |
609 | host, port = info.split() | 606 | host, port = info.split() |
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | ## repo default configuration | 3 | ## repo default configuration |
4 | ## | 4 | ## |
5 | from __future__ import print_function | ||
6 | REPO_URL = 'https://gerrit.googlesource.com/git-repo' | 5 | REPO_URL = 'https://gerrit.googlesource.com/git-repo' |
7 | REPO_REV = 'stable' | 6 | REPO_REV = 'stable' |
8 | 7 | ||
@@ -128,17 +127,25 @@ else: | |||
128 | urllib.request = urllib2 | 127 | urllib.request = urllib2 |
129 | urllib.error = urllib2 | 128 | urllib.error = urllib2 |
130 | 129 | ||
130 | |||
131 | def _print(*objects, **kwargs): | ||
132 | sep = kwargs.get('sep', ' ') | ||
133 | end = kwargs.get('end', '\n') | ||
134 | out = kwargs.get('file', sys.stdout) | ||
135 | out.write(sep.join(objects) + end) | ||
136 | |||
137 | |||
131 | # Python version check | 138 | # Python version check |
132 | ver = sys.version_info | 139 | ver = sys.version_info |
133 | if ver[0] == 3: | 140 | if ver[0] == 3: |
134 | print('error: Python 3 support is not fully implemented in repo yet.\n' | 141 | _print('error: Python 3 support is not fully implemented in repo yet.\n' |
135 | 'Please use Python 2.6 - 2.7 instead.', | 142 | 'Please use Python 2.6 - 2.7 instead.', |
136 | file=sys.stderr) | 143 | file=sys.stderr) |
137 | sys.exit(1) | 144 | sys.exit(1) |
138 | if (ver[0], ver[1]) < MIN_PYTHON_VERSION: | 145 | if (ver[0], ver[1]) < MIN_PYTHON_VERSION: |
139 | print('error: Python version %s unsupported.\n' | 146 | _print('error: Python version %s unsupported.\n' |
140 | 'Please use Python 2.6 - 2.7 instead.' | 147 | 'Please use Python 2.6 - 2.7 instead.' |
141 | % sys.version.split(' ')[0], file=sys.stderr) | 148 | % sys.version.split(' ')[0], file=sys.stderr) |
142 | sys.exit(1) | 149 | sys.exit(1) |
143 | 150 | ||
144 | home_dot_repo = os.path.expanduser('~/.repoconfig') | 151 | home_dot_repo = os.path.expanduser('~/.repoconfig') |
@@ -230,15 +237,15 @@ def _Init(args): | |||
230 | if branch.startswith('refs/heads/'): | 237 | if branch.startswith('refs/heads/'): |
231 | branch = branch[len('refs/heads/'):] | 238 | branch = branch[len('refs/heads/'):] |
232 | if branch.startswith('refs/'): | 239 | if branch.startswith('refs/'): |
233 | print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) | 240 | _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) |
234 | raise CloneFailure() | 241 | raise CloneFailure() |
235 | 242 | ||
236 | if not os.path.isdir(repodir): | 243 | if not os.path.isdir(repodir): |
237 | try: | 244 | try: |
238 | os.mkdir(repodir) | 245 | os.mkdir(repodir) |
239 | except OSError as e: | 246 | except OSError as e: |
240 | print('fatal: cannot make %s directory: %s' | 247 | _print('fatal: cannot make %s directory: %s' |
241 | % (repodir, e.strerror), file=sys.stderr) | 248 | % (repodir, e.strerror), file=sys.stderr) |
242 | # Don't raise CloneFailure; that would delete the | 249 | # Don't raise CloneFailure; that would delete the |
243 | # name. Instead exit immediately. | 250 | # name. Instead exit immediately. |
244 | # | 251 | # |
@@ -262,8 +269,8 @@ def _Init(args): | |||
262 | _Checkout(dst, branch, rev, opt.quiet) | 269 | _Checkout(dst, branch, rev, opt.quiet) |
263 | except CloneFailure: | 270 | except CloneFailure: |
264 | if opt.quiet: | 271 | if opt.quiet: |
265 | print('fatal: repo init failed; run without --quiet to see why', | 272 | _print('fatal: repo init failed; run without --quiet to see why', |
266 | file=sys.stderr) | 273 | file=sys.stderr) |
267 | raise | 274 | raise |
268 | 275 | ||
269 | 276 | ||
@@ -272,12 +279,12 @@ def _CheckGitVersion(): | |||
272 | try: | 279 | try: |
273 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 280 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
274 | except OSError as e: | 281 | except OSError as e: |
275 | print(file=sys.stderr) | 282 | _print(file=sys.stderr) |
276 | print("fatal: '%s' is not available" % GIT, file=sys.stderr) | 283 | _print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
277 | print('fatal: %s' % e, file=sys.stderr) | 284 | _print('fatal: %s' % e, file=sys.stderr) |
278 | print(file=sys.stderr) | 285 | _print(file=sys.stderr) |
279 | print('Please make sure %s is installed and in your path.' % GIT, | 286 | _print('Please make sure %s is installed and in your path.' % GIT, |
280 | file=sys.stderr) | 287 | file=sys.stderr) |
281 | raise CloneFailure() | 288 | raise CloneFailure() |
282 | 289 | ||
283 | ver_str = proc.stdout.read().strip() | 290 | ver_str = proc.stdout.read().strip() |
@@ -285,14 +292,14 @@ def _CheckGitVersion(): | |||
285 | proc.wait() | 292 | proc.wait() |
286 | 293 | ||
287 | if not ver_str.startswith('git version '): | 294 | if not ver_str.startswith('git version '): |
288 | print('error: "%s" unsupported' % ver_str, file=sys.stderr) | 295 | _print('error: "%s" unsupported' % ver_str, file=sys.stderr) |
289 | raise CloneFailure() | 296 | raise CloneFailure() |
290 | 297 | ||
291 | ver_str = ver_str[len('git version '):].strip() | 298 | ver_str = ver_str[len('git version '):].strip() |
292 | ver_act = tuple(map(int, ver_str.split('.')[0:3])) | 299 | ver_act = tuple(map(int, ver_str.split('.')[0:3])) |
293 | if ver_act < MIN_GIT_VERSION: | 300 | if ver_act < MIN_GIT_VERSION: |
294 | need = '.'.join(map(str, MIN_GIT_VERSION)) | 301 | need = '.'.join(map(str, MIN_GIT_VERSION)) |
295 | print('fatal: git %s or later required' % need, file=sys.stderr) | 302 | _print('fatal: git %s or later required' % need, file=sys.stderr) |
296 | raise CloneFailure() | 303 | raise CloneFailure() |
297 | 304 | ||
298 | 305 | ||
@@ -319,16 +326,16 @@ def SetupGnuPG(quiet): | |||
319 | try: | 326 | try: |
320 | os.mkdir(home_dot_repo) | 327 | os.mkdir(home_dot_repo) |
321 | except OSError as e: | 328 | except OSError as e: |
322 | print('fatal: cannot make %s directory: %s' | 329 | _print('fatal: cannot make %s directory: %s' |
323 | % (home_dot_repo, e.strerror), file=sys.stderr) | 330 | % (home_dot_repo, e.strerror), file=sys.stderr) |
324 | sys.exit(1) | 331 | sys.exit(1) |
325 | 332 | ||
326 | if not os.path.isdir(gpg_dir): | 333 | if not os.path.isdir(gpg_dir): |
327 | try: | 334 | try: |
328 | os.mkdir(gpg_dir, stat.S_IRWXU) | 335 | os.mkdir(gpg_dir, stat.S_IRWXU) |
329 | except OSError as e: | 336 | except OSError as e: |
330 | print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), | 337 | _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), |
331 | file=sys.stderr) | 338 | file=sys.stderr) |
332 | sys.exit(1) | 339 | sys.exit(1) |
333 | 340 | ||
334 | env = os.environ.copy() | 341 | env = os.environ.copy() |
@@ -341,18 +348,18 @@ def SetupGnuPG(quiet): | |||
341 | stdin = subprocess.PIPE) | 348 | stdin = subprocess.PIPE) |
342 | except OSError as e: | 349 | except OSError as e: |
343 | if not quiet: | 350 | if not quiet: |
344 | print('warning: gpg (GnuPG) is not available.', file=sys.stderr) | 351 | _print('warning: gpg (GnuPG) is not available.', file=sys.stderr) |
345 | print('warning: Installing it is strongly encouraged.', file=sys.stderr) | 352 | _print('warning: Installing it is strongly encouraged.', file=sys.stderr) |
346 | print(file=sys.stderr) | 353 | _print(file=sys.stderr) |
347 | return False | 354 | return False |
348 | 355 | ||
349 | proc.stdin.write(MAINTAINER_KEYS) | 356 | proc.stdin.write(MAINTAINER_KEYS) |
350 | proc.stdin.close() | 357 | proc.stdin.close() |
351 | 358 | ||
352 | if proc.wait() != 0: | 359 | if proc.wait() != 0: |
353 | print('fatal: registering repo maintainer keys failed', file=sys.stderr) | 360 | _print('fatal: registering repo maintainer keys failed', file=sys.stderr) |
354 | sys.exit(1) | 361 | sys.exit(1) |
355 | print() | 362 | _print() |
356 | 363 | ||
357 | fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w') | 364 | fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w') |
358 | fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n') | 365 | fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n') |
@@ -394,7 +401,7 @@ def _InitHttp(): | |||
394 | 401 | ||
395 | def _Fetch(url, local, src, quiet): | 402 | def _Fetch(url, local, src, quiet): |
396 | if not quiet: | 403 | if not quiet: |
397 | print('Get %s' % url, file=sys.stderr) | 404 | _print('Get %s' % url, file=sys.stderr) |
398 | 405 | ||
399 | cmd = [GIT, 'fetch'] | 406 | cmd = [GIT, 'fetch'] |
400 | if quiet: | 407 | if quiet: |
@@ -443,16 +450,16 @@ def _DownloadBundle(url, local, quiet): | |||
443 | except urllib.error.HTTPError as e: | 450 | except urllib.error.HTTPError as e: |
444 | if e.code in [403, 404]: | 451 | if e.code in [403, 404]: |
445 | return False | 452 | return False |
446 | print('fatal: Cannot get %s' % url, file=sys.stderr) | 453 | _print('fatal: Cannot get %s' % url, file=sys.stderr) |
447 | print('fatal: HTTP error %s' % e.code, file=sys.stderr) | 454 | _print('fatal: HTTP error %s' % e.code, file=sys.stderr) |
448 | raise CloneFailure() | 455 | raise CloneFailure() |
449 | except urllib.error.URLError as e: | 456 | except urllib.error.URLError as e: |
450 | print('fatal: Cannot get %s' % url, file=sys.stderr) | 457 | _print('fatal: Cannot get %s' % url, file=sys.stderr) |
451 | print('fatal: error %s' % e.reason, file=sys.stderr) | 458 | _print('fatal: error %s' % e.reason, file=sys.stderr) |
452 | raise CloneFailure() | 459 | raise CloneFailure() |
453 | try: | 460 | try: |
454 | if not quiet: | 461 | if not quiet: |
455 | print('Get %s' % url, file=sys.stderr) | 462 | _print('Get %s' % url, file=sys.stderr) |
456 | while True: | 463 | while True: |
457 | buf = r.read(8192) | 464 | buf = r.read(8192) |
458 | if buf == '': | 465 | if buf == '': |
@@ -476,23 +483,23 @@ def _Clone(url, local, quiet): | |||
476 | try: | 483 | try: |
477 | os.mkdir(local) | 484 | os.mkdir(local) |
478 | except OSError as e: | 485 | except OSError as e: |
479 | print('fatal: cannot make %s directory: %s' % (local, e.strerror), | 486 | _print('fatal: cannot make %s directory: %s' % (local, e.strerror), |
480 | file=sys.stderr) | 487 | file=sys.stderr) |
481 | raise CloneFailure() | 488 | raise CloneFailure() |
482 | 489 | ||
483 | cmd = [GIT, 'init', '--quiet'] | 490 | cmd = [GIT, 'init', '--quiet'] |
484 | try: | 491 | try: |
485 | proc = subprocess.Popen(cmd, cwd = local) | 492 | proc = subprocess.Popen(cmd, cwd = local) |
486 | except OSError as e: | 493 | except OSError as e: |
487 | print(file=sys.stderr) | 494 | _print(file=sys.stderr) |
488 | print("fatal: '%s' is not available" % GIT, file=sys.stderr) | 495 | _print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
489 | print('fatal: %s' % e, file=sys.stderr) | 496 | _print('fatal: %s' % e, file=sys.stderr) |
490 | print(file=sys.stderr) | 497 | _print(file=sys.stderr) |
491 | print('Please make sure %s is installed and in your path.' % GIT, | 498 | _print('Please make sure %s is installed and in your path.' % GIT, |
492 | file=sys.stderr) | 499 | file=sys.stderr) |
493 | raise CloneFailure() | 500 | raise CloneFailure() |
494 | if proc.wait() != 0: | 501 | if proc.wait() != 0: |
495 | print('fatal: could not create %s' % local, file=sys.stderr) | 502 | _print('fatal: could not create %s' % local, file=sys.stderr) |
496 | raise CloneFailure() | 503 | raise CloneFailure() |
497 | 504 | ||
498 | _InitHttp() | 505 | _InitHttp() |
@@ -520,18 +527,18 @@ def _Verify(cwd, branch, quiet): | |||
520 | proc.stderr.close() | 527 | proc.stderr.close() |
521 | 528 | ||
522 | if proc.wait() != 0 or not cur: | 529 | if proc.wait() != 0 or not cur: |
523 | print(file=sys.stderr) | 530 | _print(file=sys.stderr) |
524 | print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) | 531 | _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) |
525 | raise CloneFailure() | 532 | raise CloneFailure() |
526 | 533 | ||
527 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) | 534 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) |
528 | if m: | 535 | if m: |
529 | cur = m.group(1) | 536 | cur = m.group(1) |
530 | if not quiet: | 537 | if not quiet: |
531 | print(file=sys.stderr) | 538 | _print(file=sys.stderr) |
532 | print("info: Ignoring branch '%s'; using tagged release '%s'" | 539 | _print("info: Ignoring branch '%s'; using tagged release '%s'" |
533 | % (branch, cur), file=sys.stderr) | 540 | % (branch, cur), file=sys.stderr) |
534 | print(file=sys.stderr) | 541 | _print(file=sys.stderr) |
535 | 542 | ||
536 | env = os.environ.copy() | 543 | env = os.environ.copy() |
537 | env['GNUPGHOME'] = gpg_dir.encode() | 544 | env['GNUPGHOME'] = gpg_dir.encode() |
@@ -549,10 +556,10 @@ def _Verify(cwd, branch, quiet): | |||
549 | proc.stderr.close() | 556 | proc.stderr.close() |
550 | 557 | ||
551 | if proc.wait() != 0: | 558 | if proc.wait() != 0: |
552 | print(file=sys.stderr) | 559 | _print(file=sys.stderr) |
553 | print(out, file=sys.stderr) | 560 | _print(out, file=sys.stderr) |
554 | print(err, file=sys.stderr) | 561 | _print(err, file=sys.stderr) |
555 | print(file=sys.stderr) | 562 | _print(file=sys.stderr) |
556 | raise CloneFailure() | 563 | raise CloneFailure() |
557 | return '%s^0' % cur | 564 | return '%s^0' % cur |
558 | 565 | ||
@@ -619,7 +626,7 @@ def _ParseArguments(args): | |||
619 | 626 | ||
620 | 627 | ||
621 | def _Usage(): | 628 | def _Usage(): |
622 | print( | 629 | _print( |
623 | """usage: repo COMMAND [ARGS] | 630 | """usage: repo COMMAND [ARGS] |
624 | 631 | ||
625 | repo is not yet installed. Use "repo init" to install it here. | 632 | repo is not yet installed. Use "repo init" to install it here. |
@@ -640,23 +647,23 @@ def _Help(args): | |||
640 | init_optparse.print_help() | 647 | init_optparse.print_help() |
641 | sys.exit(0) | 648 | sys.exit(0) |
642 | else: | 649 | else: |
643 | print("error: '%s' is not a bootstrap command.\n" | 650 | _print("error: '%s' is not a bootstrap command.\n" |
644 | ' For access to online help, install repo ("repo init").' | 651 | ' For access to online help, install repo ("repo init").' |
645 | % args[0], file=sys.stderr) | 652 | % args[0], file=sys.stderr) |
646 | else: | 653 | else: |
647 | _Usage() | 654 | _Usage() |
648 | sys.exit(1) | 655 | sys.exit(1) |
649 | 656 | ||
650 | 657 | ||
651 | def _NotInstalled(): | 658 | def _NotInstalled(): |
652 | print('error: repo is not installed. Use "repo init" to install it here.', | 659 | _print('error: repo is not installed. Use "repo init" to install it here.', |
653 | file=sys.stderr) | 660 | file=sys.stderr) |
654 | sys.exit(1) | 661 | sys.exit(1) |
655 | 662 | ||
656 | 663 | ||
657 | def _NoCommands(cmd): | 664 | def _NoCommands(cmd): |
658 | print("""error: command '%s' requires repo to be installed first. | 665 | _print("""error: command '%s' requires repo to be installed first. |
659 | Use "repo init" to install it here.""" % cmd, file=sys.stderr) | 666 | Use "repo init" to install it here.""" % cmd, file=sys.stderr) |
660 | sys.exit(1) | 667 | sys.exit(1) |
661 | 668 | ||
662 | 669 | ||
@@ -693,7 +700,7 @@ def _SetDefaultsTo(gitdir): | |||
693 | proc.stderr.close() | 700 | proc.stderr.close() |
694 | 701 | ||
695 | if proc.wait() != 0: | 702 | if proc.wait() != 0: |
696 | print('fatal: %s has no current branch' % gitdir, file=sys.stderr) | 703 | _print('fatal: %s has no current branch' % gitdir, file=sys.stderr) |
697 | sys.exit(1) | 704 | sys.exit(1) |
698 | 705 | ||
699 | 706 | ||
@@ -742,8 +749,8 @@ def main(orig_args): | |||
742 | try: | 749 | try: |
743 | os.execv(repo_main, me) | 750 | os.execv(repo_main, me) |
744 | except OSError as e: | 751 | except OSError as e: |
745 | print("fatal: unable to start %s" % repo_main, file=sys.stderr) | 752 | _print("fatal: unable to start %s" % repo_main, file=sys.stderr) |
746 | print("fatal: %s" % e, file=sys.stderr) | 753 | _print("fatal: %s" % e, file=sys.stderr) |
747 | sys.exit(148) | 754 | sys.exit(148) |
748 | 755 | ||
749 | 756 | ||
diff --git a/subcmds/sync.py b/subcmds/sync.py index 002d05f0..e9d52b7b 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -496,6 +496,8 @@ later is required to fix a server side protocol bug. | |||
496 | sys.exit(1) | 496 | sys.exit(1) |
497 | 497 | ||
498 | manifest_server = self.manifest.manifest_server | 498 | manifest_server = self.manifest.manifest_server |
499 | if not opt.quiet: | ||
500 | print('Using manifest server %s' % manifest_server) | ||
499 | 501 | ||
500 | if not '@' in manifest_server: | 502 | if not '@' in manifest_server: |
501 | username = None | 503 | username = None |
@@ -564,7 +566,8 @@ later is required to fix a server side protocol bug. | |||
564 | sys.exit(1) | 566 | sys.exit(1) |
565 | self._ReloadManifest(manifest_name) | 567 | self._ReloadManifest(manifest_name) |
566 | else: | 568 | else: |
567 | print('error: %s' % manifest_str, file=sys.stderr) | 569 | print('error: manifest server RPC call failed: %s' % |
570 | manifest_str, file=sys.stderr) | ||
568 | sys.exit(1) | 571 | sys.exit(1) |
569 | except (socket.error, IOError, xmlrpc.client.Fault) as e: | 572 | except (socket.error, IOError, xmlrpc.client.Fault) as e: |
570 | print('error: cannot connect to manifest server %s:\n%s' | 573 | print('error: cannot connect to manifest server %s:\n%s' |