Commit 8ede00e1 authored by maruel@chromium.org's avatar maruel@chromium.org

Add the capability to filter out files on try job with regexp.

By default, filters out 'ChangeLog'. A pain directly coming from Webkit.

TEST=none
BUG=none

Review URL: http://codereview.chromium.org/543012

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@36008 0039d316-1c4b-4281-b951-d872f2087c98
parent d2e78ff6
...@@ -230,16 +230,21 @@ class GIT(object): ...@@ -230,16 +230,21 @@ class GIT(object):
return upstream_branch return upstream_branch
@staticmethod @staticmethod
def GenerateDiff(cwd, branch=None, full_move=False): def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False,
files=None):
"""Diffs against the upstream branch or optionally another branch. """Diffs against the upstream branch or optionally another branch.
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 not branch: if not branch:
branch = GIT.GetUpstream(cwd) branch = GIT.GetUpstream(cwd)
command = ['diff-tree', '-p', '--no-prefix', branch, 'HEAD'] command = ['diff-tree', '-p', '--no-prefix', branch, branch_head]
if not full_move: if not full_move:
command.append('-C') command.append('-C')
# TODO(maruel): --binary support.
if files:
command.append('--')
command.extend(files)
diff = GIT.Capture(command, cwd).splitlines(True) diff = GIT.Capture(command, cwd).splitlines(True)
for i in range(len(diff)): for i in range(len(diff)):
# In the case of added files, replace /dev/null with the path to the # In the case of added files, replace /dev/null with the path to the
...@@ -248,6 +253,14 @@ class GIT(object): ...@@ -248,6 +253,14 @@ class GIT(object):
diff[i] = '--- %s' % diff[i+1][4:] diff[i] = '--- %s' % diff[i+1][4:]
return ''.join(diff) return ''.join(diff)
@staticmethod
def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'):
"""Returns the list of modified files between two branches."""
if not branch:
branch = GIT.GetUpstream(cwd)
command = ['diff', '--name-only', branch, branch_head]
return GIT.Capture(command, cwd).splitlines(False)
@staticmethod @staticmethod
def GetPatchName(cwd): def GetPatchName(cwd):
"""Constructs a name for this patch.""" """Constructs a name for this patch."""
......
...@@ -361,7 +361,7 @@ from :3 ...@@ -361,7 +361,7 @@ from :3
members = [ members = [
'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple', 'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple',
'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot',
'GetEmail', 'GetPatchName', 'GetSVNBranch', 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch',
'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName',
'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
......
...@@ -118,7 +118,7 @@ from :3 ...@@ -118,7 +118,7 @@ from :3
members = [ members = [
'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple', 'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple',
'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot',
'GetEmail', 'GetPatchName', 'GetSVNBranch', 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch',
'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
......
...@@ -33,6 +33,7 @@ class TryChangeTestsBase(SuperMoxTestBase): ...@@ -33,6 +33,7 @@ class TryChangeTestsBase(SuperMoxTestBase):
self.options.diff = None self.options.diff = None
self.options.name = None self.options.name = None
self.options.email = None self.options.email = None
self.options.exclude = []
class TryChangeUnittest(TryChangeTestsBase): class TryChangeUnittest(TryChangeTestsBase):
...@@ -43,7 +44,7 @@ class TryChangeUnittest(TryChangeTestsBase): ...@@ -43,7 +44,7 @@ class TryChangeUnittest(TryChangeTestsBase):
'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess',
'SCM', 'SVN', 'TryChange', 'USAGE', 'SCM', 'SVN', 'TryChange', 'USAGE',
'breakpad', 'datetime', 'errno', 'gclient_utils', 'getpass', 'logging', 'breakpad', 'datetime', 'errno', 'gclient_utils', 'getpass', 'logging',
'optparse', 'os', 'posixpath', 'scm', 'shutil', 'sys', 'tempfile', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', 'sys', 'tempfile',
'urllib', 'urllib',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
...@@ -90,6 +91,7 @@ class GITUnittest(TryChangeTestsBase): ...@@ -90,6 +91,7 @@ class GITUnittest(TryChangeTestsBase):
trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
trychange.scm.GIT.GenerateDiff(self.fake_root, trychange.scm.GIT.GenerateDiff(self.fake_root,
full_move=True, full_move=True,
files=['foo.txt', 'bar.txt'],
branch=None).AndReturn('A diff') branch=None).AndReturn('A diff')
trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233')
trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com')
......
...@@ -14,6 +14,7 @@ import logging ...@@ -14,6 +14,7 @@ import logging
import optparse import optparse
import os import os
import posixpath import posixpath
import re
import shutil import shutil
import sys import sys
import tempfile import tempfile
...@@ -174,11 +175,19 @@ class SVN(SCM): ...@@ -174,11 +175,19 @@ class SVN(SCM):
if not self.files: if not self.files:
previous_cwd = os.getcwd() previous_cwd = os.getcwd()
os.chdir(self.checkout_root) os.chdir(self.checkout_root)
excluded = ['!', '?', 'X', ' ', '~'] excluded = ['!', '?', 'X', ' ', '~']
self.files = [ def Excluded(f):
f[1] for f in scm.SVN.CaptureStatus(self.checkout_root) if f[0][0] in excluded:
if f[0][0] not in excluded return True
] for r in self.options.exclude:
if re.search(r, f[1]):
logging.info('Ignoring "%s"' % f[1])
return True
return False
self.files = [f[1] for f in scm.SVN.CaptureStatus(self.checkout_root)
if not Excluded(f)]
os.chdir(previous_cwd) os.chdir(previous_cwd)
return scm.SVN.GenerateDiff(self.files, self.checkout_root, full_move=True, return scm.SVN.GenerateDiff(self.files, self.checkout_root, full_move=True,
revision=self.diff_against) revision=self.diff_against)
...@@ -206,8 +215,20 @@ class GIT(SCM): ...@@ -206,8 +215,20 @@ class GIT(SCM):
return None return None
def GenerateDiff(self): def GenerateDiff(self):
# For now, ignores self.files if not self.files:
return scm.GIT.GenerateDiff(self.checkout_root, full_move=True, self.files = scm.GIT.GetDifferentFiles(self.checkout_root,
branch=self.diff_against)
def NotExcluded(f):
for r in self.options.exclude:
if re.search(r, f):
logging.info('Ignoring "%s"' % f)
return False
return True
self.files = filter(NotExcluded, self.files)
return scm.GIT.GenerateDiff(self.checkout_root, files=self.files,
full_move=True,
branch=self.diff_against) branch=self.diff_against)
...@@ -489,13 +510,16 @@ def TryChange(argv, ...@@ -489,13 +510,16 @@ def TryChange(argv,
try: try:
group.add_option("--webkit", action="append_const", group.add_option("--webkit", action="append_const",
const="third_party/WebKit", const="third_party/WebKit",
dest="sub_rep", dest="PATH",
help="Shorthand for -s third_party/WebKit") help="Shorthand for -s third_party/WebKit")
except optparse.OptionError: except optparse.OptionError:
# append_const is not supported on 2.4. Too bad. # append_const is not supported on 2.4. Too bad.
pass pass
group.add_option("--no_gclient", action="store_true", group.add_option("--no_gclient", action="store_true",
help="Disable automatic search for gclient checkout.") help="Disable automatic search for gclient checkout.")
group.add_option("-E", "--exclude", action="append",
default=['ChangeLog'], metavar='REGEXP',
help="Regexp patterns to exclude files. Default: %default")
parser.add_option_group(group) parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Access the try server by HTTP") group = optparse.OptionGroup(parser, "Access the try server by HTTP")
......
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