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 Capture(args, cwd, **kwargs): | 100 def Capture(args, cwd, strip_out=True, **kwargs): |
101 env = os.environ.copy() | 101 env = os.environ.copy() |
102 # 'cat' is a magical git string that disables pagers on all platforms. | 102 # 'cat' is a magical git string that disables pagers on all platforms. |
103 env['GIT_PAGER'] = 'cat' | 103 env['GIT_PAGER'] = 'cat' |
104 return subprocess2.check_output( | 104 output = subprocess2.check_output( |
105 ['git'] + args, | 105 ['git'] + args, |
106 cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs).strip() | 106 cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs) |
| 107 return output.strip() if strip_out else output |
107 | 108 |
108 @staticmethod | 109 @staticmethod |
109 def CaptureStatus(files, cwd, upstream_branch): | 110 def CaptureStatus(files, cwd, upstream_branch): |
110 """Returns git status. | 111 """Returns git status. |
111 | 112 |
112 @files can be a string (one file) or a list of files. | 113 @files can be a string (one file) or a list of files. |
113 | 114 |
114 Returns an array of (status, file) tuples.""" | 115 Returns an array of (status, file) tuples.""" |
115 if upstream_branch is None: | 116 if upstream_branch is None: |
116 upstream_branch = GIT.GetUpstreamBranch(cwd) | 117 upstream_branch = GIT.GetUpstreamBranch(cwd) |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 command = ['diff', '-p', '--no-color', '--no-prefix', '--no-ext-diff', | 353 command = ['diff', '-p', '--no-color', '--no-prefix', '--no-ext-diff', |
353 branch + "..." + branch_head] | 354 branch + "..." + branch_head] |
354 if full_move: | 355 if full_move: |
355 command.append('--no-renames') | 356 command.append('--no-renames') |
356 else: | 357 else: |
357 command.append('-C') | 358 command.append('-C') |
358 # TODO(maruel): --binary support. | 359 # TODO(maruel): --binary support. |
359 if files: | 360 if files: |
360 command.append('--') | 361 command.append('--') |
361 command.extend(files) | 362 command.extend(files) |
362 diff = GIT.Capture(command, cwd=cwd).splitlines(True) | 363 diff = GIT.Capture(command, cwd=cwd, strip_out=False).splitlines(True) |
363 for i in range(len(diff)): | 364 for i in range(len(diff)): |
364 # In the case of added files, replace /dev/null with the path to the | 365 # In the case of added files, replace /dev/null with the path to the |
365 # file being added. | 366 # file being added. |
366 if diff[i].startswith('--- /dev/null'): | 367 if diff[i].startswith('--- /dev/null'): |
367 diff[i] = '--- %s' % diff[i+1][4:] | 368 diff[i] = '--- %s' % diff[i+1][4:] |
368 return ''.join(diff) | 369 return ''.join(diff) |
369 | 370 |
370 @staticmethod | 371 @staticmethod |
371 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): | 372 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): |
372 """Returns the list of modified files between two branches.""" | 373 """Returns the list of modified files between two branches.""" |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 # revert, like for properties. | 1107 # revert, like for properties. |
1107 if not os.path.isdir(cwd): | 1108 if not os.path.isdir(cwd): |
1108 # '.' was deleted. It's not worth continuing. | 1109 # '.' was deleted. It's not worth continuing. |
1109 return | 1110 return |
1110 try: | 1111 try: |
1111 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1112 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
1112 except subprocess2.CalledProcessError: | 1113 except subprocess2.CalledProcessError: |
1113 if not os.path.exists(file_path): | 1114 if not os.path.exists(file_path): |
1114 continue | 1115 continue |
1115 raise | 1116 raise |
OLD | NEW |