Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: scm.py

Issue 18408006: Fix GenerateDiff -- don't strip whitespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, **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 no_strip = kwargs.pop('no_strip', None)
iannucci 2013/07/12 22:49:08 "I'm gonna pop some kwargs -- only got 20 vars in
Isaac (away) 2013/07/12 23:19:41 Done -- named it strip_out
105 output = subprocess2.check_output(
105 ['git'] + args, 106 ['git'] + args,
106 cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs).strip() 107 cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs)
108 if no_strip:
109 return output
110 else:
111 return output.strip()
iannucci 2013/07/12 22:49:08 return output if no_strip else output.strip()
Isaac (away) 2013/07/12 23:19:41 Done.
107 112
108 @staticmethod 113 @staticmethod
109 def CaptureStatus(files, cwd, upstream_branch): 114 def CaptureStatus(files, cwd, upstream_branch):
110 """Returns git status. 115 """Returns git status.
111 116
112 @files can be a string (one file) or a list of files. 117 @files can be a string (one file) or a list of files.
113 118
114 Returns an array of (status, file) tuples.""" 119 Returns an array of (status, file) tuples."""
115 if upstream_branch is None: 120 if upstream_branch is None:
116 upstream_branch = GIT.GetUpstreamBranch(cwd) 121 upstream_branch = GIT.GetUpstreamBranch(cwd)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 command = ['diff', '-p', '--no-color', '--no-prefix', '--no-ext-diff', 357 command = ['diff', '-p', '--no-color', '--no-prefix', '--no-ext-diff',
353 branch + "..." + branch_head] 358 branch + "..." + branch_head]
354 if full_move: 359 if full_move:
355 command.append('--no-renames') 360 command.append('--no-renames')
356 else: 361 else:
357 command.append('-C') 362 command.append('-C')
358 # TODO(maruel): --binary support. 363 # TODO(maruel): --binary support.
359 if files: 364 if files:
360 command.append('--') 365 command.append('--')
361 command.extend(files) 366 command.extend(files)
362 diff = GIT.Capture(command, cwd=cwd).splitlines(True) 367 diff = GIT.Capture(command, cwd=cwd, no_strip=True).splitlines(True)
363 for i in range(len(diff)): 368 for i in range(len(diff)):
364 # In the case of added files, replace /dev/null with the path to the 369 # In the case of added files, replace /dev/null with the path to the
365 # file being added. 370 # file being added.
366 if diff[i].startswith('--- /dev/null'): 371 if diff[i].startswith('--- /dev/null'):
367 diff[i] = '--- %s' % diff[i+1][4:] 372 diff[i] = '--- %s' % diff[i+1][4:]
368 return ''.join(diff) 373 return ''.join(diff)
369 374
370 @staticmethod 375 @staticmethod
371 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): 376 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'):
372 """Returns the list of modified files between two branches.""" 377 """Returns the list of modified files between two branches."""
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 # revert, like for properties. 1111 # revert, like for properties.
1107 if not os.path.isdir(cwd): 1112 if not os.path.isdir(cwd):
1108 # '.' was deleted. It's not worth continuing. 1113 # '.' was deleted. It's not worth continuing.
1109 return 1114 return
1110 try: 1115 try:
1111 SVN.Capture(['revert', file_status[1]], cwd=cwd) 1116 SVN.Capture(['revert', file_status[1]], cwd=cwd)
1112 except subprocess2.CalledProcessError: 1117 except subprocess2.CalledProcessError:
1113 if not os.path.exists(file_path): 1118 if not os.path.exists(file_path):
1114 continue 1119 continue
1115 raise 1120 raise
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698