OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. | 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. |
6 # Derived from https://gist.github.com/aljungberg/626518 | 6 # Derived from https://gist.github.com/aljungberg/626518 |
7 import multiprocessing.pool | 7 import multiprocessing.pool |
8 from multiprocessing.pool import IMapIterator | 8 from multiprocessing.pool import IMapIterator |
9 def wrapper(func): | 9 def wrapper(func): |
10 def wrap(self, timeout=None): | 10 def wrap(self, timeout=None): |
11 return func(self, timeout=timeout or 1e100) | 11 return func(self, timeout=timeout or 1e100) |
12 return wrap | 12 return wrap |
13 IMapIterator.next = wrapper(IMapIterator.next) | 13 IMapIterator.next = wrapper(IMapIterator.next) |
14 IMapIterator.__next__ = IMapIterator.next | 14 IMapIterator.__next__ = IMapIterator.next |
15 # TODO(iannucci): Monkeypatch all other 'wait' methods too. | 15 # TODO(iannucci): Monkeypatch all other 'wait' methods too. |
16 | 16 |
17 | 17 |
18 import binascii | 18 import binascii |
19 import collections | 19 import collections |
20 import contextlib | 20 import contextlib |
21 import functools | 21 import functools |
22 import logging | 22 import logging |
23 import os | 23 import os |
24 import re | 24 import re |
25 import signal | 25 import signal |
26 import sys | 26 import sys |
27 import tempfile | 27 import tempfile |
| 28 import textwrap |
28 import threading | 29 import threading |
29 | 30 |
30 import subprocess2 | 31 import subprocess2 |
31 | 32 |
32 | 33 |
33 GIT_EXE = 'git.bat' if sys.platform.startswith('win') else 'git' | 34 GIT_EXE = 'git.bat' if sys.platform.startswith('win') else 'git' |
34 TEST_MODE = False | 35 TEST_MODE = False |
35 | 36 |
36 FREEZE = 'FREEZE' | 37 FREEZE = 'FREEZE' |
37 FREEZE_SECTIONS = { | 38 FREEZE_SECTIONS = { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 try: | 233 try: |
233 reg = re.compile(r'^branch\.(.*)\.%s$' % option) | 234 reg = re.compile(r'^branch\.(.*)\.%s$' % option) |
234 lines = run('config', '--get-regexp', reg.pattern).splitlines() | 235 lines = run('config', '--get-regexp', reg.pattern).splitlines() |
235 return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)} | 236 return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)} |
236 except subprocess2.CalledProcessError: | 237 except subprocess2.CalledProcessError: |
237 return {} | 238 return {} |
238 | 239 |
239 | 240 |
240 def branches(*args): | 241 def branches(*args): |
241 NO_BRANCH = ('* (no branch', '* (detached from ') | 242 NO_BRANCH = ('* (no branch', '* (detached from ') |
242 for line in run('branch', *args).splitlines(): | 243 |
| 244 key = 'depot-tools.branch-limit' |
| 245 limit = 20 |
| 246 try: |
| 247 limit = int(config(key, limit)) |
| 248 except ValueError: |
| 249 pass |
| 250 |
| 251 raw_branches = run('branch', *args).splitlines() |
| 252 |
| 253 num = len(raw_branches) |
| 254 if num > limit: |
| 255 print >> sys.stderr, textwrap.dedent("""\ |
| 256 Your git repo has too many branches (%d/%d) for this tool to work well. |
| 257 |
| 258 You may adjust this limit by running: |
| 259 git config %s <new_limit> |
| 260 """ % (num, limit, key)) |
| 261 sys.exit(1) |
| 262 |
| 263 for line in raw_branches: |
243 if line.startswith(NO_BRANCH): | 264 if line.startswith(NO_BRANCH): |
244 continue | 265 continue |
245 yield line.split()[-1] | 266 yield line.split()[-1] |
246 | 267 |
247 | 268 |
248 def run_with_retcode(*cmd, **kwargs): | 269 def run_with_retcode(*cmd, **kwargs): |
249 """Run a command but only return the status code.""" | 270 """Run a command but only return the status code.""" |
250 try: | 271 try: |
251 run(*cmd, **kwargs) | 272 run(*cmd, **kwargs) |
252 return 0 | 273 return 0 |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return None | 650 return None |
630 return ret | 651 return ret |
631 | 652 |
632 | 653 |
633 def upstream(branch): | 654 def upstream(branch): |
634 try: | 655 try: |
635 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', | 656 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', |
636 branch+'@{upstream}') | 657 branch+'@{upstream}') |
637 except subprocess2.CalledProcessError: | 658 except subprocess2.CalledProcessError: |
638 return None | 659 return None |
OLD | NEW |