@ -781,34 +781,21 @@ class SVN(object):
The diff will always use relative paths .
The diff will always use relative paths .
"""
"""
assert isinstance ( filenames , ( list , tuple ) )
assert isinstance ( filenames , ( list , tuple ) )
# 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
# since we want the unified diff.
if SVN . AssertVersion ( " 1.7 " ) [ 0 ] :
# On svn >= 1.7, the "--internal-diff" flag will solve this.
return SVN . _GenerateDiffInternal ( filenames , cwd , full_move , revision ,
[ " diff " , " --internal-diff " ] )
else :
# On svn < 1.7, the "--internal-diff" flag doesn't exist. Using
# --diff-cmd=diff doesn't always work, since e.g. Windows cmd users may
# not have a "diff" executable in their path at all. So we use an empty
# temporary directory as the config directory, which bypasses any user
# settings for the diff-cmd.
bogus_dir = tempfile . mkdtemp ( )
try :
return SVN . _GenerateDiffInternal ( filenames , cwd , full_move , revision ,
[ " diff " , " --config_dir " , bogus_dir ] )
finally :
gclient_utils . RemoveDirectory ( bogus_dir )
@staticmethod
def _GenerateDiffInternal ( filenames , cwd , full_move , revision , diff_command ) :
root = os . path . normcase ( os . path . join ( cwd , ' ' ) )
root = os . path . normcase ( os . path . join ( cwd , ' ' ) )
def RelativePath ( path , root ) :
def RelativePath ( path , root ) :
""" We must use relative paths. """
""" We must use relative paths. """
if os . path . normcase ( path ) . startswith ( root ) :
if os . path . normcase ( path ) . startswith ( root ) :
return path [ len ( root ) : ]
return path [ len ( root ) : ]
return path
return path
# 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
# since we want the unified diff. Using --diff-cmd=diff doesn't always
# work, since e.g. Windows cmd users may not have a "diff" executable in
# their path at all. So we use an empty temporary directory as the config
# directory, which gets around these problems.
bogus_dir = tempfile . mkdtemp ( )
command = [ ' diff ' , ' --config-dir ' , bogus_dir ]
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)
@ -845,13 +832,14 @@ 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_ command + [ ' -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 ) )
else :
else :
metaheaders . append ( " #$ cp %s %s \n " % ( src ,
metaheaders . append ( " #$ cp %s %s \n " % ( src ,
filename ) )
filename ) )
if metaheaders :
if metaheaders :
diffs . append ( " ### BEGIN SVN COPY METADATA \n " )
diffs . append ( " ### BEGIN SVN COPY METADATA \n " )
diffs . extend ( metaheaders )
diffs . extend ( metaheaders )
@ -859,7 +847,7 @@ class SVN(object):
# Now ready to do the actual diff.
# Now ready to do the actual diff.
for filename in sorted ( data ) :
for filename in sorted ( data ) :
diffs . append ( SVN . _DiffItemInternal (
diffs . append ( SVN . _DiffItemInternal (
filename , cwd , data [ filename ] , diff_ command, 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 ( )
@ -868,6 +856,8 @@ class SVN(object):
result = buf . getvalue ( )
result = buf . getvalue ( )
buf . close ( )
buf . close ( )
return result
return result
finally :
gclient_utils . RemoveDirectory ( bogus_dir )
@staticmethod
@staticmethod
def _DiffItemInternal ( filename , cwd , info , diff_command , full_move , revision ) :
def _DiffItemInternal ( filename , cwd , info , diff_command , full_move , revision ) :