Skip to content

Commit

Permalink
Merge branch 'SvnLastChangedRev' of git://github.com/jaredgrubb/buildbot
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Mar 3, 2013
2 parents 198029d + 88974e7 commit 6dfff6a
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 19 deletions.
52 changes: 36 additions & 16 deletions master/buildbot/steps/source/svn.py
Expand Up @@ -37,7 +37,7 @@ class SVN(Source):
def __init__(self, repourl=None, mode='incremental',
method=None, username=None,
password=None, extra_args=None, keep_on_purge=None,
depth=None, **kwargs):
depth=None, preferLastChangedRev=False, **kwargs):

self.repourl = repourl
self.username = username
Expand All @@ -47,6 +47,7 @@ def __init__(self, repourl=None, mode='incremental',
self.depth = depth
self.method = method
self.mode = mode
self.preferLastChangedRev = preferLastChangedRev
Source.__init__(self, **kwargs)
errors = []
if self.mode not in self.possible_modes:
Expand Down Expand Up @@ -250,6 +251,7 @@ def _sourcedirIsUpdatable(self):
defer.returnValue(mo and mo.group(1) == self.repourl)
return

@defer.inlineCallbacks
def parseGotRevision(self, _):
# if this was a full/export, then we need to check svnversion in the
# *source* directory, not the build directory
Expand All @@ -262,23 +264,41 @@ def parseGotRevision(self, _):
timeout=self.timeout,
collectStdout=True)
cmd.useLog(self.stdio_log, False)
d = self.runCommand(cmd)
def _setrev(_):
stdout = cmd.stdout
yield self.runCommand(cmd)

stdout = cmd.stdout
try:
stdout_xml = xml.dom.minidom.parseString(stdout)
except xml.parsers.expat.ExpatError:
msg = "Corrupted xml, aborting step"
self.stdio_log.addHeader(msg)
raise buildstep.BuildStepFailed()

revision = None
if self.preferLastChangedRev:
try:
revision = stdout_xml.getElementsByTagName('commit')[0].attributes['revision'].value
except (KeyError, IndexError):
msg =("SVN.parseGotRevision unable to detect Last Changed Rev in"
" output of svn info")
log.msg(msg)
# fall through and try to get 'Revision' instead

if revision is None:
try:
stdout_xml = xml.dom.minidom.parseString(stdout)
match = stdout_xml.getElementsByTagName('entry')[0].attributes['revision'].value
except xml.parsers.expat.ExpatError:
msg = "Corrupted xml, aborting step"
self.stdio_log.addHeader(msg)
revision = stdout_xml.getElementsByTagName('entry')[0].attributes['revision'].value
except (KeyError, IndexError):
msg =("SVN.parseGotRevision unable to detect revision in"
" output of svn info")
log.msg(msg)
raise buildstep.BuildStepFailed()
revision = match
msg = "Got SVN revision %s" % (revision, )
self.stdio_log.addHeader(msg)
self.updateSourceProperty('got_revision', revision)
return 0
d.addCallback(lambda _: _setrev(cmd.rc))
return d

msg = "Got SVN revision %s" % (revision, )
self.stdio_log.addHeader(msg)
self.updateSourceProperty('got_revision', revision)

defer.returnValue(cmd.rc)


def purge(self, ignore_ignores):
"""Delete everything that shown up on status."""
Expand Down
109 changes: 108 additions & 1 deletion master/buildbot/test/unit/test_steps_source_svn.py
Expand Up @@ -78,7 +78,7 @@ class TestSVN(sourcesteps.SourceStepMixin, unittest.TestCase):
<depth>infinity</depth>
</wc-info>
<commit
revision="100">
revision="90">
<author>sally</author>
<date>2003-01-15T23:35:12.847647Z</date>
</commit>
Expand Down Expand Up @@ -193,6 +193,38 @@ def _checkType():
d.addCallback(lambda _: _checkType())
return d

def test_revision_missing(self):
"""Fail if 'revision' tag isnt there"""
svn_info_stdout = self.svn_info_stdout_xml.replace('entry', 'Blah')

svnTestStep = svn.SVN(repourl='http://svn.local/app/trunk')
self.setupStep(svnTestStep)
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['svn', '--version'])
+ 0,
Expect('stat', dict(file='wkdir/.svn',
logEnviron=True))
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'info', '--non-interactive',
'--no-auth-cache'])
+ ExpectShell.log('stdio',
stdout="URL: http://svn.local/app/trunk")
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'update', '--non-interactive',
'--no-auth-cache'])
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'info', '--xml'])
+ ExpectShell.log('stdio',
stdout=svn_info_stdout)
+ 0,
)
self.expectOutcome(result=FAILURE, status_text=["updating"])
return self.runStep()

def test_mode_incremental(self):
self.setupStep(
svn.SVN(repourl='http://svn.local/app/trunk',
Expand Down Expand Up @@ -424,6 +456,81 @@ def test_mode_incremental_win32path(self):
self.expectOutcome(result=SUCCESS, status_text=["update"])
return self.runStep()

def test_mode_incremental_preferLastChangedRev(self):
"""Give the last-changed rev if 'preferLastChangedRev' is set"""
self.setupStep(
svn.SVN(repourl='http://svn.local/app/trunk',
mode='incremental',username='user',
preferLastChangedRev=True,
password='pass', extra_args=['--random']))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['svn', '--version'])
+ 0,
Expect('stat', dict(file='wkdir/.svn',
logEnviron=True))
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'info', '--non-interactive',
'--no-auth-cache', '--username', 'user',
'--password', 'pass', '--random'])
+ ExpectShell.log('stdio',
stdout="URL: http://svn.local/app/trunk")
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'update', '--non-interactive',
'--no-auth-cache', '--username', 'user',
'--password', 'pass', '--random'])
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'info', '--xml'])
+ ExpectShell.log('stdio',
stdout=self.svn_info_stdout_xml)
+ 0,
)
self.expectOutcome(result=SUCCESS, status_text=["update"])
self.expectProperty('got_revision', '90', 'SVN')
return self.runStep()

def test_mode_incremental_preferLastChangedRev_butMissing(self):
"""If 'preferLastChangedRev' is set, but missing, fall back
to the regular revision value."""
svn_info_stdout = self.svn_info_stdout_xml.replace('commit', 'Blah')

self.setupStep(
svn.SVN(repourl='http://svn.local/app/trunk',
mode='incremental',username='user',
preferLastChangedRev=True,
password='pass', extra_args=['--random']))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['svn', '--version'])
+ 0,
Expect('stat', dict(file='wkdir/.svn',
logEnviron=True))
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'info', '--non-interactive',
'--no-auth-cache', '--username', 'user',
'--password', 'pass', '--random'])
+ ExpectShell.log('stdio',
stdout="URL: http://svn.local/app/trunk")
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'update', '--non-interactive',
'--no-auth-cache', '--username', 'user',
'--password', 'pass', '--random'])
+ 0,
ExpectShell(workdir='wkdir',
command=['svn', 'info', '--xml'])
+ ExpectShell.log('stdio',
stdout=svn_info_stdout)
+ 0,
)
self.expectOutcome(result=SUCCESS, status_text=["update"])
self.expectProperty('got_revision', '100', 'SVN')
return self.runStep()

def test_mode_full_clobber(self):
self.setupStep(
svn.SVN(repourl='http://svn.local/app/trunk',
Expand Down
5 changes: 5 additions & 0 deletions master/docs/manual/cfg-buildsteps.rst
Expand Up @@ -519,6 +519,11 @@ Alternatively, the ``repourl`` argument can be used to create the :bb:step:`SVN`
have depth-infinity. Infinity is equivalent to SVN default update
behavior, without specifying any depth argument.

``preferLastChangedRev``
(optional): By default, the ``got_revision`` property is set to the
repository's global revision ("Revision" in the `svn info` output). Set this
parameter to ``True`` to have it set to the "Last Changed Rev" instead.

``mode``
``method``

Expand Down
5 changes: 3 additions & 2 deletions master/docs/relnotes/index.rst
Expand Up @@ -36,8 +36,9 @@ Features

* The latent buildslave support is less buggy, thanks to :bb:pull:`646`.

* The ``treeStableTimer`` for ``AnyBranchScheduler`` now maintains separate timers for separate branches,
codebases, projects, and repositories.
* The ``treeStableTimer`` for ``AnyBranchScheduler`` now maintains separate timers for separate branches, codebases, projects, and repositories.

* :bb:step:`SVN` has a new option `preferLastChangedRev=True` to use the last changed revision for ``got_revision``

Deprecations, Removals, and Non-Compatible Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 6dfff6a

Please sign in to comment.