@ -10,6 +10,7 @@ import logging
import os
import os
import re
import re
import sys
import sys
import tempfile
import time
import time
from xml . etree import ElementTree
from xml . etree import ElementTree
@ -779,19 +780,30 @@ class SVN(object):
expected relative path .
expected relative path .
full_move means that move or copy operations should completely recreate the
full_move means that move or copy operations should completely recreate the
files , usually in the prospect to apply the patch for a try job . """
files , usually in the prospect to apply the patch for a try job . """
# 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 they can have another diff executable in their path that
# gives different line endings. So we use a bogus temp directory as the
# config directory, which gets around these problems.
bogus_dir = tempfile . mkdtemp ( )
try :
# Use "svn info" output instead of os.path.isdir because the latter fails
# Use "svn info" output instead of os.path.isdir because the latter fails
# when the file is deleted.
# when the file is deleted.
return SVN . _DiffItemInternal (
return SVN . _DiffItemInternal (
filename ,
filename ,
cwd ,
cwd ,
SVN . CaptureLocalInfo ( [ filename ] , cwd ) ,
SVN . CaptureLocalInfo ( [ filename ] , cwd ) ,
bogus_dir ,
full_move ,
full_move ,
revision )
revision )
finally :
gclient_utils . RemoveDirectory ( bogus_dir )
@staticmethod
@staticmethod
def _DiffItemInternal ( filename , cwd , info , full_move, revision ) :
def _DiffItemInternal ( filename , cwd , info , bogus_dir, full_move, revision ) :
""" Grabs the diff data. """
""" Grabs the diff data. """
command = [ " diff " , " -- internal-diff" , filename ]
command = [ " diff " , " -- config-dir" , bogus_dir , filename ]
if revision :
if revision :
command . extend ( [ ' --revision ' , revision ] )
command . extend ( [ ' --revision ' , revision ] )
data = None
data = None
@ -859,6 +871,14 @@ class SVN(object):
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 they can have another diff executable in their path that
# gives different line endings. So we use a bogus temp directory as the
# config directory, which gets around these problems.
bogus_dir = tempfile . mkdtemp ( )
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)
@ -895,13 +915,13 @@ 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 ' , ' --internal-diff ' , ' -r ' , ' %d :head ' % rev ,
SVN . Capture ( [ ' diff ' , ' -r ' , ' %d :head ' % rev , srcurl ] , cwd ) ) :
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 , filename ) )
metaheaders . append ( " #$ cp %s %s \n " % ( src ,
filename ) )
if metaheaders :
if metaheaders :
diffs . append ( " ### BEGIN SVN COPY METADATA \n " )
diffs . append ( " ### BEGIN SVN COPY METADATA \n " )
@ -909,8 +929,8 @@ class SVN(object):
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 . iterkeys ( ) ) :
diffs . append ( SVN . _DiffItemInternal ( filename , cwd , data [ filename ] ,
diffs . append ( SVN . _DiffItemInternal (
full_move , revision ) )
filename , cwd , data [ filename ] , bogus_dir , 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 ( )
@ -919,6 +939,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 GetEmail ( cwd ) :
def GetEmail ( cwd ) :