| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 ''' | 2 ''' |
| 3 Copyright 2012 Google Inc. | 3 Copyright 2012 Google Inc. |
| 4 | 4 |
| 5 Use of this source code is governed by a BSD-style license that can be | 5 Use of this source code is governed by a BSD-style license that can be |
| 6 found in the LICENSE file. | 6 found in the LICENSE file. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 ''' | 9 ''' |
| 10 Generates a visual diff of all pending changes in the local SVN (or git!) | 10 Generates a visual diff of all pending changes in the local SVN (or git!) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 # the 'tools' directory containing this script, which will be the case if | 39 # the 'tools' directory containing this script, which will be the case if |
| 40 # 'trunk' was checked out as a single unit. | 40 # 'trunk' was checked out as a single unit. |
| 41 GM_DIRECTORY = os.path.realpath( | 41 GM_DIRECTORY = os.path.realpath( |
| 42 os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) | 42 os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 43 if GM_DIRECTORY not in sys.path: | 43 if GM_DIRECTORY not in sys.path: |
| 44 sys.path.append(GM_DIRECTORY) | 44 sys.path.append(GM_DIRECTORY) |
| 45 import gm_json | 45 import gm_json |
| 46 import jsondiff | 46 import jsondiff |
| 47 import svn | 47 import svn |
| 48 | 48 |
| 49 CHECKOUT_ROOT = os.path.realpath( |
| 50 os.path.join(os.path.dirname(__file__), os.pardir)) |
| 51 sys.path.append(CHECKOUT_ROOT) |
| 52 from common.py.utils import git_utils |
| 53 |
| 49 USAGE_STRING = 'Usage: %s [options]' | 54 USAGE_STRING = 'Usage: %s [options]' |
| 50 HELP_STRING = ''' | 55 HELP_STRING = ''' |
| 51 | 56 |
| 52 Generates a visual diff of all pending changes in the local SVN/git checkout. | 57 Generates a visual diff of all pending changes in the local SVN/git checkout. |
| 53 | 58 |
| 54 This includes a list of all files that have been added, deleted, or modified | 59 This includes a list of all files that have been added, deleted, or modified |
| 55 (as far as SVN/git knows about). For any image modifications, pixel diffs will | 60 (as far as SVN/git knows about). For any image modifications, pixel diffs will |
| 56 be generated. | 61 be generated. |
| 57 | 62 |
| 58 ''' | 63 ''' |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 @param args a list of arguments | 183 @param args a list of arguments |
| 179 """ | 184 """ |
| 180 proc = subprocess.Popen(args, | 185 proc = subprocess.Popen(args, |
| 181 stdout=subprocess.PIPE, | 186 stdout=subprocess.PIPE, |
| 182 stderr=subprocess.PIPE) | 187 stderr=subprocess.PIPE) |
| 183 (stdout, stderr) = proc.communicate() | 188 (stdout, stderr) = proc.communicate() |
| 184 if proc.returncode is not 0: | 189 if proc.returncode is not 0: |
| 185 raise Exception('command "%s" failed: %s' % (args, stderr)) | 190 raise Exception('command "%s" failed: %s' % (args, stderr)) |
| 186 return stdout | 191 return stdout |
| 187 | 192 |
| 188 def _GitGetModifiedFiles(): | |
| 189 """Returns a list of locally modified files within the current working dir. | |
| 190 | |
| 191 TODO(epoger): Move this into a git utility package? | |
| 192 """ | |
| 193 return _RunCommand(['git', 'ls-files', '-m']).splitlines() | |
| 194 | 193 |
| 195 def _GitExportBaseVersionOfFile(file_within_repo, dest_path): | 194 def _GitExportBaseVersionOfFile(file_within_repo, dest_path): |
| 196 """Retrieves a copy of the base version of a file within the repository. | 195 """Retrieves a copy of the base version of a file within the repository. |
| 197 | 196 |
| 198 @param file_within_repo path to the file within the repo whose base | 197 @param file_within_repo path to the file within the repo whose base |
| 199 version you wish to obtain | 198 version you wish to obtain |
| 200 @param dest_path destination to which to write the base content | 199 @param dest_path destination to which to write the base content |
| 201 | 200 |
| 202 TODO(epoger): Move this into a git utility package? | 201 TODO(epoger): Move this into a git utility package? |
| 203 """ | 202 """ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 for dir in [modified_flattened_dir, original_flattened_dir, diff_dir] : | 246 for dir in [modified_flattened_dir, original_flattened_dir, diff_dir] : |
| 248 shutil.rmtree(dir, ignore_errors=True) | 247 shutil.rmtree(dir, ignore_errors=True) |
| 249 os.mkdir(dir) | 248 os.mkdir(dir) |
| 250 | 249 |
| 251 # Get a list of all locally modified (including added/deleted) files, | 250 # Get a list of all locally modified (including added/deleted) files, |
| 252 # descending subdirectories. | 251 # descending subdirectories. |
| 253 if using_svn: | 252 if using_svn: |
| 254 modified_file_paths = svn_repo.GetFilesWithStatus( | 253 modified_file_paths = svn_repo.GetFilesWithStatus( |
| 255 svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED) | 254 svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED) |
| 256 else: | 255 else: |
| 257 modified_file_paths = _GitGetModifiedFiles() | 256 modified_file_paths = git_utils.GetModifiedFiles() |
| 258 | 257 |
| 259 # For each modified file: | 258 # For each modified file: |
| 260 # 1. copy its current contents into modified_flattened_dir | 259 # 1. copy its current contents into modified_flattened_dir |
| 261 # 2. copy its original contents into original_flattened_dir | 260 # 2. copy its original contents into original_flattened_dir |
| 262 for modified_file_path in modified_file_paths: | 261 for modified_file_path in modified_file_paths: |
| 263 if modified_file_path.endswith('.json'): | 262 if modified_file_path.endswith('.json'): |
| 264 # Special handling for JSON files, in the hopes that they | 263 # Special handling for JSON files, in the hopes that they |
| 265 # contain GM result summaries. | 264 # contain GM result summaries. |
| 266 original_file = tempfile.NamedTemporaryFile(delete = False) | 265 original_file = tempfile.NamedTemporaryFile(delete = False) |
| 267 original_file.close() | 266 original_file.close() |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 help='path to already-built skdiff tool; if not set, ' | 326 help='path to already-built skdiff tool; if not set, ' |
| 328 'will search for it in typical directories near this ' | 327 'will search for it in typical directories near this ' |
| 329 'script') | 328 'script') |
| 330 parser.add_option(OPTION_SOURCE_DIR, | 329 parser.add_option(OPTION_SOURCE_DIR, |
| 331 action='store', type='string', | 330 action='store', type='string', |
| 332 default=os.path.join('expectations', 'gm'), | 331 default=os.path.join('expectations', 'gm'), |
| 333 help='root directory within which to compare all ' + | 332 help='root directory within which to compare all ' + |
| 334 'files; defaults to "%default"') | 333 'files; defaults to "%default"') |
| 335 (options, args) = parser.parse_args() | 334 (options, args) = parser.parse_args() |
| 336 Main(options, args) | 335 Main(options, args) |
| OLD | NEW |