svndiff: report added and deleted files, not just modified files

Review URL: https://codereview.appspot.com/6260052

git-svn-id: http://skia.googlecode.com/svn/trunk@4063 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
epoger@google.com 2012-05-29 21:28:12 +00:00
parent 3ec68f047a
commit 6dbf6cde3b
2 changed files with 40 additions and 23 deletions

View File

@ -12,6 +12,12 @@ import subprocess
PROPERTY_MIMETYPE = 'svn:mime-type'
# Status types for GetFilesWithStatus()
STATUS_ADDED = 0x01
STATUS_DELETED = 0x02
STATUS_MODIFIED = 0x04
STATUS_NOT_UNDER_SVN_CONTROL = 0x08
class Svn:
def __init__(self, directory):
@ -50,27 +56,33 @@ class Svn:
"""Return a list of files which are in this directory but NOT under
SVN control.
"""
stdout = self._RunCommand(['svn', 'status'])
new_regex = re.compile('^\?.....\s+(.+)$', re.MULTILINE)
files = new_regex.findall(stdout)
return files
return self.GetFilesWithStatus(STATUS_NOT_UNDER_SVN_CONTROL)
def GetNewAndModifiedFiles(self):
"""Return a list of files in this dir which are newly added or modified,
including those that are not (yet) under SVN control.
"""
stdout = self._RunCommand(['svn', 'status'])
new_regex = re.compile('^[AM\?].....\s+(.+)$', re.MULTILINE)
files = new_regex.findall(stdout)
return files
return self.GetFilesWithStatus(
STATUS_ADDED | STATUS_MODIFIED | STATUS_NOT_UNDER_SVN_CONTROL)
def GetModifiedFiles(self):
"""Return a list of files in this dir which are under SVN control, and
have been modified.
def GetFilesWithStatus(self, status):
"""Return a list of files in this dir with the given SVN status.
@param status bitfield combining one or more STATUS_xxx values
"""
status_types_string = ''
if status & STATUS_ADDED:
status_types_string += 'A'
if status & STATUS_DELETED:
status_types_string += 'D'
if status & STATUS_MODIFIED:
status_types_string += 'M'
if status & STATUS_NOT_UNDER_SVN_CONTROL:
status_types_string += '\?'
status_regex_string = '^[%s].....\s+(.+)$' % status_types_string
stdout = self._RunCommand(['svn', 'status'])
new_regex = re.compile('^M.....\s+(.+)$', re.MULTILINE)
files = new_regex.findall(stdout)
status_regex = re.compile(status_regex_string, re.MULTILINE)
files = status_regex.findall(stdout)
return files
def AddFiles(self, filenames):

View File

@ -1,6 +1,5 @@
'''
Compares all locally modified images within this SVN checkout against the
SVN base revision of each image.
Generates a visual diff of all pending changes in the local SVN checkout.
Launch with --help to see more information.
@ -24,8 +23,11 @@ import svn
USAGE_STRING = 'Usage: %s [options]'
HELP_STRING = '''
Compares all locally modified images within this SVN checkout against the
SVN base revision of each image.
Generates a visual diff of all pending changes in the local SVN checkout.
This includes a list of all files that have been added, deleted, or modified
(as far as SVN knows about). For any image modifications, pixel diffs will
be generated.
'''
@ -69,8 +71,7 @@ def FindPathToSkDiff(user_set_path=None):
possible_paths, OPTION_PATH_TO_SKDIFF))
def SvnDiff(path_to_skdiff, dest_dir):
"""Compares all locally modified images within this SVN checkout against
the SVN base revision of each image.
"""Generates a visual diff of all pending changes in the local SVN checkout.
@param path_to_skdiff
@param dest_dir existing directory within which to write results
@ -88,17 +89,21 @@ def SvnDiff(path_to_skdiff, dest_dir):
shutil.rmtree(dir, ignore_errors=True)
os.mkdir(dir)
# Get a list of all locally modified files, descending subdirectories.
# Get a list of all locally modified (including added/deleted) files,
# descending subdirectories.
svn_repo = svn.Svn('.')
modified_file_paths = svn_repo.GetModifiedFiles()
modified_file_paths = svn_repo.GetFilesWithStatus(
svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED)
# For each modified file:
# 1. copy its current contents into modified_flattened_dir
# 2. copy its original contents into original_flattened_dir
for modified_file_path in modified_file_paths:
dest_filename = re.sub(os.sep, '__', modified_file_path)
shutil.copyfile(modified_file_path,
os.path.join(modified_flattened_dir, dest_filename))
# If the file had STATUS_DELETED, it won't exist anymore...
if os.path.isfile(modified_file_path):
shutil.copyfile(modified_file_path,
os.path.join(modified_flattened_dir, dest_filename))
svn_repo.ExportBaseVersionOfFile(
modified_file_path,
os.path.join(original_flattened_dir, dest_filename))