Commit aae3d86d authored by pkasting@chromium.org's avatar pkasting@chromium.org

Tweak GenerateDiff:

* Update comment for accuracy
* Keep the base diff command in a variable; this fixes an oversight where GenerateDiff would run svn diff without the --config-dir hack, and makes later refactoring easy
* Apply review comments from https://codereview.chromium.org/14247007/ to existing code

Review URL: https://chromiumcodereview.appspot.com/14366029

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@195308 0039d316-1c4b-4281-b951-d872f2087c98
parent 917ea7fa
...@@ -790,15 +790,16 @@ class SVN(object): ...@@ -790,15 +790,16 @@ class SVN(object):
# If the user specified a custom diff command in their svn config file, # If the user specified a custom diff command in their svn config file,
# then it'll be used when we do svn diff, which we don't want to happen # then it'll be used when we do svn diff, which we don't want to happen
# since we want the unified diff. Using --diff-cmd=diff doesn't always # since we want the unified diff. Using --diff-cmd=diff doesn't always
# work, since they can have another diff executable in their path that # work, since e.g. Windows cmd users may not have a "diff" executable in
# gives different line endings. So we use a bogus temp directory as the # their path at all. So we use an empty temporary directory as the config
# config directory, which gets around these problems. # directory, which gets around these problems.
bogus_dir = tempfile.mkdtemp() bogus_dir = tempfile.mkdtemp()
command = ['diff', '--config-dir', bogus_dir]
try: try:
# Cleanup filenames # Cleanup filenames
filenames = [RelativePath(f, root) for f in filenames] filenames = [RelativePath(f, root) for f in filenames]
# Get information about the modified items (files and directories) # Get information about the modified items (files and directories)
data = dict([(f, SVN.CaptureLocalInfo([f], root)) for f in filenames]) data = dict((f, SVN.CaptureLocalInfo([f], root)) for f in filenames)
diffs = [] diffs = []
if full_move: if full_move:
# Eliminate modified files inside moved/copied directory. # Eliminate modified files inside moved/copied directory.
...@@ -831,7 +832,7 @@ class SVN(object): ...@@ -831,7 +832,7 @@ class SVN(object):
# revision the file was deleted. # revision the file was deleted.
srcinfo = {'Revision': rev} srcinfo = {'Revision': rev}
if (srcinfo.get('Revision') != rev and if (srcinfo.get('Revision') != rev and
SVN.Capture(['diff', '-r', '%d:head' % rev, srcurl], cwd)): SVN.Capture(command + ['-r', '%d:head' % rev, srcurl], cwd)):
metaheaders.append("#$ svn cp -r %d %s %s " metaheaders.append("#$ svn cp -r %d %s %s "
"### WARNING: note non-trunk copy\n" % "### WARNING: note non-trunk copy\n" %
(rev, src, filename)) (rev, src, filename))
...@@ -844,9 +845,9 @@ class SVN(object): ...@@ -844,9 +845,9 @@ class SVN(object):
diffs.extend(metaheaders) diffs.extend(metaheaders)
diffs.append("### END SVN COPY METADATA\n") diffs.append("### END SVN COPY METADATA\n")
# Now ready to do the actual diff. # Now ready to do the actual diff.
for filename in sorted(data.iterkeys()): for filename in sorted(data):
diffs.append(SVN._DiffItemInternal( diffs.append(SVN._DiffItemInternal(
filename, cwd, data[filename], bogus_dir, full_move, revision)) filename, cwd, data[filename], command, full_move, revision))
# Use StringIO since it can be messy when diffing a directory move with # Use StringIO since it can be messy when diffing a directory move with
# full_move=True. # full_move=True.
buf = cStringIO.StringIO() buf = cStringIO.StringIO()
...@@ -859,9 +860,9 @@ class SVN(object): ...@@ -859,9 +860,9 @@ class SVN(object):
gclient_utils.RemoveDirectory(bogus_dir) gclient_utils.RemoveDirectory(bogus_dir)
@staticmethod @staticmethod
def _DiffItemInternal(filename, cwd, info, bogus_dir, full_move, revision): def _DiffItemInternal(filename, cwd, info, diff_command, full_move, revision):
"""Grabs the diff data.""" """Grabs the diff data."""
command = ["diff", "--config-dir", bogus_dir, filename] command = diff_command + [filename]
if revision: if revision:
command.extend(['--revision', revision]) command.extend(['--revision', revision])
data = None data = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment