Skip to content

Commit

Permalink
Merge branch 'gsoc_commit' of git://github.com/in3xes/buildbot
Browse files Browse the repository at this point in the history
* 'gsoc_commit' of git://github.com/in3xes/buildbot:
  Remove unnecessarily variables
  Minor changes to Git, Mercurial. Check for installation on slave
  • Loading branch information
djmitche committed Jul 10, 2011
2 parents 486f4c1 + 13e15b8 commit 209b670
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 13 deletions.
23 changes: 19 additions & 4 deletions master/buildbot/steps/source/git.py
Expand Up @@ -89,15 +89,15 @@ def __init__(self, repourl=None, branch='master', mode='incremental',
self.repourl = self.repourl and _ComputeRepositoryURL(self.repourl)

def startVC(self, branch, revision, patch):
slavever = self.slaveVersion('git')
if not slavever:
raise BuildSlaveTooOldError("slave is too old, does not know "
"about git")
self.branch = branch or 'master'
self.revision = revision
self.method = self._getMethod()
self.stdio_log = self.addLog("stdio")

gitInstalled = self.checkGit()
if not gitInstalled:
raise BuildSlaveTooOldError("git is not installed on slave")

if self.mode == 'incremental':
d = self.incremental()
elif self.mode == 'full':
Expand Down Expand Up @@ -327,6 +327,11 @@ def clobber(res):
d.addCallback(clobber)
return d

def computeSourceRevision(self, changes):
if not changes:
return None
return changes[-1].revision

def _sourcedirIsUpdatable(self):
cmd = buildstep.LoggedRemoteCommand('stat', {'file': self.workdir + '/.git'})
log.msg(self.workdir)
Expand Down Expand Up @@ -361,3 +366,13 @@ def _getMethod(self):
return None
elif self.method is None and self.mode == 'full':
return 'fresh'

def checkGit(self):
d = self._dovccmd(['--version'])
def check(res):
if res == 0:
return True
return False
d.addCallback(check)
return d

34 changes: 27 additions & 7 deletions master/buildbot/steps/source/mercurial.py
Expand Up @@ -98,13 +98,12 @@ def __init__(self, repourl=None, baseURL=None, mode='incremental',
self.baseURL = self.baseURL and _ComputeRepositoryURL(self.baseURL)

def startVC(self, branch, revision, patch):

slavever = self.slaveVersion('hg')
if not slavever:
raise BuildSlaveTooOldError("slave is too old, does not know "
"about hg")
self.revision = revision
self.method = self._getMethod()
self.stdio_log = self.addLog("stdio")
hgInstalled = self.checkHg()
if not hgInstalled:
raise BuildSlaveTooOldError("Mercurial is not installed on slave")

if self.branchType == 'dirname':
assert self.repourl is None
Expand All @@ -116,8 +115,6 @@ def startVC(self, branch, revision, patch):
self.update_branch = (branch or 'default')
else:
raise ValueError("Invalid branch type")

self.stdio_log = self.addLog("stdio")

if self.mode == 'full':
d = self.full()
Expand Down Expand Up @@ -256,6 +253,19 @@ def evaluateCommand(cmd):
d.addCallback(lambda _: evaluateCommand(cmd))
return d

def computeSourceRevision(self, changes):
if not changes:
return None
# without knowing the revision ancestry graph, we can't sort the
# changes at all. So for now, assume they were given to us in sorted
# order, and just pay attention to the last one. See ticket #103 for
# more details.
if len(changes) > 1:
log.msg("Mercurial.computeSourceRevision: warning: "
"there are %d changes here, assuming the last one is "
"the most recent" % len(changes))
return changes[-1].revision

def _getCurrentBranch(self):
if self.branchType == 'dirname':
return defer.succeed(self.branch)
Expand Down Expand Up @@ -292,3 +302,13 @@ def _update(self, _):
command += ['--rev', self.revision]
d = self._dovccmd(command)
return d

def checkHg(self):
d = self._dovccmd(['--version'])
def check(res):
if res == 0:
return True
return False
d.addCallback(check)
return d

4 changes: 2 additions & 2 deletions master/buildbot/steps/source/oldsource.py
Expand Up @@ -653,7 +653,7 @@ def checkCompatibility(self):
"buildbot-0.7.10 or newer." % (self.build.slavename,))
raise BuildSlaveTooOldError(m)

def getSvnUrl(self, branch, revision, patch):
def getSvnUrl(self, branch):
''' Compute the svn url that will be passed to the svn remote command '''
if self.svnurl:
return self.svnurl
Expand All @@ -677,7 +677,7 @@ def startVC(self, branch, revision, patch):

self.checkCompatibility()

self.args['svnurl'] = self.getSvnUrl(branch, revision, patch)
self.args['svnurl'] = self.getSvnUrl(branch)
self.args['revision'] = revision
self.args['patch'] = patch
self.args['always_purge'] = self.always_purge
Expand Down
52 changes: 52 additions & 0 deletions master/buildbot/test/unit/test_steps_source_git.py
Expand Up @@ -33,6 +33,9 @@ def test_mode_full_clean(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -60,6 +63,10 @@ def test_mode_full_clean_no_existing_repo(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,

ExpectLogged('stat', dict(file='wkdir/.git'))
+ 1,
ExpectShell(workdir='wkdir',
Expand All @@ -81,6 +88,9 @@ def test_mode_full_clobber(self):
mode='full', method='clobber', progress=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('rmdir', dict(dir='wkdir'))
+ 0,
ExpectShell(workdir='wkdir',
Expand All @@ -102,6 +112,9 @@ def test_mode_incremental(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='incremental'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand All @@ -127,6 +140,9 @@ def test_mode_full_fresh(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='fresh'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -156,6 +172,9 @@ def test_mode_incremental_given_revision(self):
revision='abcdef01',
))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand All @@ -178,6 +197,9 @@ def test_mode_full_fresh_submodule(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='fresh', submodule=True))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -213,6 +235,9 @@ def test_mode_full_clobber_shallow(self):
mode='full', method='clobber', shallow=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('rmdir', dict(dir='wkdir'))
+ 0,
ExpectShell(workdir='wkdir',
Expand All @@ -235,6 +260,9 @@ def test_mode_incremental_retryFetch(self):
mode='incremental', retryFetch=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -268,6 +296,9 @@ def test_mode_incremental_clobberOnFailure(self):
mode='incremental', clobberOnFailure=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -300,6 +331,9 @@ def test_mode_full_copy(self):
mode='full', method='copy', shallow=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('rmdir', dict(dir='wkdir')),
ExpectLogged('stat', dict(file='source/.git'))
+ 0,
Expand Down Expand Up @@ -328,6 +362,9 @@ def test_mode_incremental_no_existing_repo(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='incremental'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 1,
ExpectShell(workdir='wkdir',
Expand All @@ -351,6 +388,9 @@ def test_mode_full_clobber_given_revision(self):
revision='abcdef01',
))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('rmdir', dict(dir='wkdir'))
+ 0,
ExpectShell(workdir='wkdir',
Expand All @@ -376,6 +416,9 @@ def test_mode_full_clobber_submodule(self):
mode='full', method='clobber', submodule=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('rmdir', dict(dir='wkdir'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -406,6 +449,9 @@ def test_mode_full_fresh_revision(self):
revision='abcdef01',
))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 1,
ExpectShell(workdir='wkdir',
Expand All @@ -431,6 +477,9 @@ def test_mode_full_fresh_clobberOnFailure(self):
mode='full', method='fresh', clobberOnFailure=True))

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 1,
ExpectShell(workdir='wkdir',
Expand Down Expand Up @@ -458,6 +507,9 @@ def test_mode_full_no_method(self):
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
ExpectLogged('stat', dict(file='wkdir/.git'))
+ 0,
ExpectShell(workdir='wkdir',
Expand Down

1 comment on commit 209b670

@dabrahams
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to say, I'm very happy to see this in the trunk. Nice work, all!

Please sign in to comment.