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 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
6 | 6 |
7 import cStringIO | 7 import cStringIO |
8 import glob | 8 import glob |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if val.isdigit(): | 90 if val.isdigit(): |
91 return int(val) | 91 return int(val) |
92 else: | 92 else: |
93 return 0 | 93 return 0 |
94 | 94 |
95 | 95 |
96 class GIT(object): | 96 class GIT(object): |
97 current_version = None | 97 current_version = None |
98 | 98 |
99 @staticmethod | 99 @staticmethod |
| 100 def ApplyEnvVars(kwargs): |
| 101 env = kwargs.pop('env', None) or os.environ.copy() |
| 102 # Don't prompt for passwords; just fail quickly and noisily. |
| 103 # By default, git will use an interactive terminal prompt when a username/ |
| 104 # password is needed. That shouldn't happen in the chromium workflow, |
| 105 # and if it does, then gclient may hide the prompt in the midst of a flood |
| 106 # of terminal spew. The only indication that something has gone wrong |
| 107 # will be when gclient hangs unresponsively. Instead, we disable the |
| 108 # password prompt and simply allow git to fail noisily. The error |
| 109 # message produced by git will be copied to gclient's output. |
| 110 env.setdefault('GIT_ASKPASS', 'true') |
| 111 env.setdefault('SSH_ASKPASS', 'true') |
| 112 # 'cat' is a magical git string that disables pagers on all platforms. |
| 113 env.setdefault('GIT_PAGER', 'cat') |
| 114 return env |
| 115 |
| 116 @staticmethod |
100 def Capture(args, cwd, strip_out=True, **kwargs): | 117 def Capture(args, cwd, strip_out=True, **kwargs): |
101 env = os.environ.copy() | 118 env = GIT.ApplyEnvVars(kwargs) |
102 # 'cat' is a magical git string that disables pagers on all platforms. | |
103 env['GIT_PAGER'] = 'cat' | |
104 output = subprocess2.check_output( | 119 output = subprocess2.check_output( |
105 ['git'] + args, | 120 ['git'] + args, |
106 cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs) | 121 cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs) |
107 return output.strip() if strip_out else output | 122 return output.strip() if strip_out else output |
108 | 123 |
109 @staticmethod | 124 @staticmethod |
110 def CaptureStatus(files, cwd, upstream_branch): | 125 def CaptureStatus(files, cwd, upstream_branch): |
111 """Returns git status. | 126 """Returns git status. |
112 | 127 |
113 @files can be a string (one file) or a list of files. | 128 @files can be a string (one file) or a list of files. |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 # revert, like for properties. | 1137 # revert, like for properties. |
1123 if not os.path.isdir(cwd): | 1138 if not os.path.isdir(cwd): |
1124 # '.' was deleted. It's not worth continuing. | 1139 # '.' was deleted. It's not worth continuing. |
1125 return | 1140 return |
1126 try: | 1141 try: |
1127 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1142 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
1128 except subprocess2.CalledProcessError: | 1143 except subprocess2.CalledProcessError: |
1129 if not os.path.exists(file_path): | 1144 if not os.path.exists(file_path): |
1130 continue | 1145 continue |
1131 raise | 1146 raise |
OLD | NEW |