OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Generic utils.""" | 5 """Generic utils.""" |
6 | 6 |
7 import codecs | 7 import codecs |
8 import cStringIO | 8 import cStringIO |
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import pipes | 11 import pipes |
12 import platform | 12 import platform |
13 import Queue | 13 import Queue |
14 import re | 14 import re |
15 import stat | 15 import stat |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 import tempfile | 18 import tempfile |
19 import threading | 19 import threading |
20 import time | 20 import time |
21 import urlparse | 21 import urlparse |
22 | 22 |
23 import subprocess2 | 23 import subprocess2 |
24 | 24 |
25 | 25 |
26 RETRY_MAX = 3 | 26 RETRY_MAX = 3 |
27 RETRY_INITIAL_SLEEP = 0.5 | 27 RETRY_INITIAL_SLEEP = 0.5 |
28 | 28 |
29 | 29 |
| 30 _WARNINGS = [] |
| 31 |
| 32 |
30 class Error(Exception): | 33 class Error(Exception): |
31 """gclient exception class.""" | 34 """gclient exception class.""" |
32 def __init__(self, msg, *args, **kwargs): | 35 def __init__(self, msg, *args, **kwargs): |
33 index = getattr(threading.currentThread(), 'index', 0) | 36 index = getattr(threading.currentThread(), 'index', 0) |
34 if index: | 37 if index: |
35 msg = '\n'.join('%d> %s' % (index, l) for l in msg.splitlines()) | 38 msg = '\n'.join('%d> %s' % (index, l) for l in msg.splitlines()) |
36 super(Error, self).__init__(msg, *args, **kwargs) | 39 super(Error, self).__init__(msg, *args, **kwargs) |
37 | 40 |
38 | 41 |
| 42 def PrintWarnings(): |
| 43 """Prints any accumulated warnings.""" |
| 44 if _WARNINGS: |
| 45 print >> sys.stderr, '\n\nWarnings:' |
| 46 for warning in _WARNINGS: |
| 47 print >> sys.stderr, warning |
| 48 |
| 49 |
| 50 def AddWarning(msg): |
| 51 """Adds the given warning message to the list of accumulated warnings.""" |
| 52 _WARNINGS.append(msg) |
| 53 |
| 54 |
39 def SplitUrlRevision(url): | 55 def SplitUrlRevision(url): |
40 """Splits url and returns a two-tuple: url, rev""" | 56 """Splits url and returns a two-tuple: url, rev""" |
41 if url.startswith('ssh:'): | 57 if url.startswith('ssh:'): |
42 # Make sure ssh://user-name@example.com/~/test.git@stable works | 58 # Make sure ssh://user-name@example.com/~/test.git@stable works |
43 regex = r'(ssh://(?:[-.\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' | 59 regex = r'(ssh://(?:[-.\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' |
44 components = re.search(regex, url).groups() | 60 components = re.search(regex, url).groups() |
45 else: | 61 else: |
46 components = url.split('@', 1) | 62 components = url.split('@', 1) |
47 if len(components) == 1: | 63 if len(components) == 1: |
48 components += [None] | 64 components += [None] |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 else: | 990 else: |
975 return '512m' | 991 return '512m' |
976 | 992 |
977 def DefaultIndexPackConfig(): | 993 def DefaultIndexPackConfig(): |
978 """Return reasonable default values for configuring git-index-pack. | 994 """Return reasonable default values for configuring git-index-pack. |
979 | 995 |
980 Experiments suggest that higher values for pack.threads don't improve | 996 Experiments suggest that higher values for pack.threads don't improve |
981 performance.""" | 997 performance.""" |
982 return ['-c', 'pack.threads=5', '-c', | 998 return ['-c', 'pack.threads=5', '-c', |
983 'core.deltaBaseCacheLimit=%s' % DefaultDeltaBaseCacheLimit()] | 999 'core.deltaBaseCacheLimit=%s' % DefaultDeltaBaseCacheLimit()] |
OLD | NEW |