Skip to content

Commit

Permalink
Fixed an issue with the P4 step not handling whitespace in the viewspec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg MacDonald committed May 21, 2015
1 parent c82c5ed commit 4708de1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
25 changes: 21 additions & 4 deletions master/buildbot/steps/source/p4.py
Expand Up @@ -287,6 +287,9 @@ def _createClientSpec(self):
# Setup a view
client_spec += "View:\n"

def has_whitespace(*args):
return any([re.search(r'\s', i) for i in args])

if self.p4viewspec:
# uses only p4viewspec array of tuples to build view
# If the user specifies a viewspec via an array of tuples then
Expand All @@ -295,19 +298,33 @@ def _createClientSpec(self):
for k, v in self.p4viewspec:
if debug_logging:
log.msg('P4:_createClientSpec():key:%s value:%s' % (k, v))
client_spec += '\t%s%s //%s/%s%s\n' % (k, suffix, self.p4client, v, suffix)

qa = '"' if has_whitespace(k, suffix) else ''
qb = '"' if has_whitespace(self.p4client, v, suffix) else ''
client_spec += '\t%s%s%s%s %s//%s/%s%s%s\n' % (qa, k, suffix, qa,
qb, self.p4client, v, suffix, qb)
else:
# Uses p4base, p4branch, p4extra_views
client_spec += "\t%s" % (self.p4base)

qa = '"' if has_whitespace(self.p4base, self.p4branch) else ''

client_spec += "\t%s%s" % (qa, self.p4base)

if self.p4branch:
client_spec += "/%s" % (self.p4branch)

client_spec += "/... //%s/...\n" % (self.p4client)
client_spec += "/...%s " % qa

qb = '"' if has_whitespace(self.p4client) else ''
client_spec += "%s//%s/...%s\n" % (qb, self.p4client, qb)

if self.p4extra_views:
for k, v in self.p4extra_views:
client_spec += "\t%s/... //%s/%s/...\n" % (k, self.p4client, v)
qa = '"' if has_whitespace(k) else ''
qb = '"' if has_whitespace(k, self.p4client, v) else ''

client_spec += "\t%s%s/...%s %s//%s/%s/...%s\n" % (qa, k, qa,
qb, self.p4client, v, qb)

client_spec = client_spec.encode('utf-8') # resolve unicode issues
if debug_logging:
Expand Down
32 changes: 26 additions & 6 deletions master/buildbot/test/unit/test_steps_source_p4.py
Expand Up @@ -207,7 +207,8 @@ def test_mode_incremental_p4base_with_p4extra_views(self):
self.setupStep(P4(p4port='localhost:12000', mode='incremental',
p4base='//depot', p4branch='trunk',
p4extra_views=[('-//depot/trunk/test', 'test'),
('-//depot/trunk/doc', 'doc')],
('-//depot/trunk/doc', 'doc'),
('-//depot/trunk/white space', 'white space')],
p4user='user', p4client='p4_client1', p4passwd='pass'))

root_dir = '/home/user/workspace/wkdir'
Expand All @@ -231,12 +232,15 @@ def test_mode_incremental_p4base_with_p4extra_views(self):
\t//depot/trunk/... //p4_client1/...
\t-//depot/trunk/test/... //p4_client1/test/...
\t-//depot/trunk/doc/... //p4_client1/doc/...
\t"-//depot/trunk/white space/..." "//p4_client1/white space/..."
''' % root_dir)
self._incremental(client_stdin=client_spec)

def test_mode_incremental_p4viewspec(self):
self.setupStep(P4(p4port='localhost:12000', mode='incremental',
p4viewspec=[('//depot/trunk/', '')],
p4viewspec=[('//depot/trunk/', ''),
('//depot/white space/', 'white space/'),
('-//depot/white space/excluded/', 'white space/excluded/')],
p4user='user', p4client='p4_client1', p4passwd='pass'))

root_dir = '/home/user/workspace/wkdir'
Expand All @@ -258,13 +262,17 @@ def test_mode_incremental_p4viewspec(self):
View:
\t//depot/trunk/... //p4_client1/...
\t"//depot/white space/..." "//p4_client1/white space/..."
\t"-//depot/white space/excluded/..." "//p4_client1/white space/excluded/..."
''' % root_dir)
self._incremental(client_stdin=client_spec)

def test_mode_incremental_p4viewspec_suffix(self):
self.setupStep(P4(p4port='localhost:12000', mode='incremental',
p4viewspec_suffix=None,
p4viewspec=[('//depot/trunk/foo.xml', 'bar.xml')],
p4viewspec=[('//depot/trunk/foo.xml', 'bar.xml'),
('//depot/white space/...', 'white space/...'),
('-//depot/white space/excluded/...', 'white space/excluded/...')],
p4user='user', p4client='p4_client1', p4passwd='pass'))

root_dir = '/home/user/workspace/wkdir'
Expand All @@ -286,6 +294,8 @@ def test_mode_incremental_p4viewspec_suffix(self):
View:
\t//depot/trunk/foo.xml //p4_client1/bar.xml
\t"//depot/white space/..." "//p4_client1/white space/..."
\t"-//depot/white space/excluded/..." "//p4_client1/white space/excluded/..."
''' % root_dir)
self._incremental(client_stdin=client_spec)

Expand Down Expand Up @@ -473,7 +483,10 @@ def test_mode_full_p4base(self):
def test_mode_full_p4viewspec(self):
self.setupStep(
P4(p4port='localhost:12000',
mode='full', p4viewspec=[('//depot/main/', '')],
mode='full',
p4viewspec=[('//depot/main/', ''),
('//depot/main/white space/', 'white space/'),
('-//depot/main/white space/excluded/', 'white space/excluded/')],
p4user='user', p4client='p4_client1', p4passwd='pass'))

root_dir = '/home/user/workspace/wkdir'
Expand All @@ -494,7 +507,10 @@ def test_mode_full_p4viewspec(self):
LineEnd:\tlocal
View:
\t//depot/main/... //p4_client1/...\n''' % root_dir)
\t//depot/main/... //p4_client1/...
\t"//depot/main/white space/..." "//p4_client1/white space/..."
\t"-//depot/main/white space/excluded/..." "//p4_client1/white space/excluded/..."
''' % root_dir)

self._full(client_stdin=client_stdin)

Expand Down Expand Up @@ -621,7 +637,9 @@ def test_mode_full_renderable_p4viewspec(self):
def test_mode_full_p4viewspec_suffix(self):
self.setupStep(P4(p4port='localhost:12000', mode='full',
p4viewspec_suffix=None,
p4viewspec=[('//depot/trunk/foo.xml', 'bar.xml')],
p4viewspec=[('//depot/trunk/foo.xml', 'bar.xml'),
('//depot/trunk/white space/...', 'white space/...'),
('-//depot/trunk/white space/excluded/...', 'white space/excluded/...')],
p4user='user', p4client='p4_client1', p4passwd='pass'))

root_dir = '/home/user/workspace/wkdir'
Expand All @@ -643,6 +661,8 @@ def test_mode_full_p4viewspec_suffix(self):
View:
\t//depot/trunk/foo.xml //p4_client1/bar.xml
\t"//depot/trunk/white space/..." "//p4_client1/white space/..."
\t"-//depot/trunk/white space/excluded/..." "//p4_client1/white space/excluded/..."
''' % root_dir)
self._full(client_stdin=client_spec)

Expand Down

0 comments on commit 4708de1

Please sign in to comment.