Skip to content

Commit

Permalink
Merge pull request #1640 from jaredgrubb/jgrubb-git-magic-nums
Browse files Browse the repository at this point in the history
Git: Use RC_SUCCESS instead of 0
  • Loading branch information
Mikhail Sobolev committed Apr 30, 2015
2 parents 205deee + af4577f commit 81e7702
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions master/buildbot/steps/source/git.py
Expand Up @@ -23,6 +23,10 @@
from buildbot.process import buildstep
from buildbot.steps.source.base import Source

RC_SUCCESS = 0
RC_FAIL = 1
GIT_HASH_LENGTH = 40


def isTrueOrIsExactlyZero(v):
# nonzero values are true...
Expand Down Expand Up @@ -151,7 +155,7 @@ def startVC(self, branch, revision, patch):
def checkInstall(gitInstalled):
if not gitInstalled:
raise BuildSlaveTooOldError("git is not installed on slave")
return 0
return RC_SUCCESS
d.addCallback(checkInstall)

d.addCallback(lambda _: self.sourcedirIsPatched())
Expand All @@ -160,7 +164,7 @@ def checkPatched(patched):
if patched:
return self._dovccmd(['clean', '-f', '-f', '-d', '-x'])
else:
return 0
return RC_SUCCESS
d.addCallback(checkPatched)

if self.mode == 'incremental':
Expand Down Expand Up @@ -219,7 +223,7 @@ def incremental(self):

# if revision exists checkout to that revision
# else fetch and update
if rc == 0:
if rc == RC_SUCCESS:
yield self._dovccmd(['reset', '--hard', self.revision, '--'])

if self.branch != 'HEAD':
Expand All @@ -244,14 +248,14 @@ def clean(self):
def clobber(self):
yield self._doClobber()
res = yield self._fullClone(shallowClone=self.shallow)
if res != 0:
if res != RC_SUCCESS:
raise buildstep.BuildStepFailed

@defer.inlineCallbacks
def fresh(self):
res = yield self._dovccmd(['clean', '-f', '-f', '-d', '-x'],
abandonOnFailure=False)
if res == 0:
if res == RC_SUCCESS:
yield self._fetchOrFallback()
else:
yield self._doClobber()
Expand Down Expand Up @@ -280,7 +284,7 @@ def copy(_):

def resetWorkdir(_):
self.workdir = old_workdir
return 0
return RC_SUCCESS

d.addCallback(resetWorkdir)
return d
Expand All @@ -301,17 +305,17 @@ def _gotResults(results):
def parseGotRevision(self, _=None):
stdout = yield self._dovccmd(['rev-parse', 'HEAD'], collectStdout=True)
revision = stdout.strip()
if len(revision) != 40:
if len(revision) != GIT_HASH_LENGTH:
raise buildstep.BuildStepFailed()
log.msg("Got Git revision %s" % (revision, ))
self.updateSourceProperty('got_revision', revision)

defer.returnValue(0)
defer.returnValue(RC_SUCCESS)

@defer.inlineCallbacks
def parseCommitDescription(self, _=None):
if self.getDescription == False: # dict() should not return here
defer.returnValue(0)
defer.returnValue(RC_SUCCESS)
return

cmd = ['describe']
Expand All @@ -333,7 +337,7 @@ def parseCommitDescription(self, _=None):
except:
pass

defer.returnValue(0)
defer.returnValue(RC_SUCCESS)

def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False, initialStdin=None):
full_command = ['git']
Expand Down Expand Up @@ -385,7 +389,7 @@ def checkout(_):
d.addCallback(checkout)

def renameBranch(res):
if res != 0:
if res != RC_SUCCESS:
return res
d = self._dovccmd(['branch', '-M', self.branch], abandonOnFailure=False)
# Ignore errors
Expand All @@ -403,7 +407,7 @@ def _fetchOrFallback(self, _=None):
wrapper for self._fetch
"""
res = yield self._fetch(None)
if res == 0:
if res == RC_SUCCESS:
defer.returnValue(res)
return
elif self.retryFetch:
Expand Down Expand Up @@ -445,7 +449,7 @@ def _clone(self, shallowClone):
d.addCallback(lambda _: self._fetch(None))

def _retry(res):
if self.stopped or res == 0: # or shallow clone??
if self.stopped or res == RC_SUCCESS: # or shallow clone??
return res
delay, repeats = self.retry
if repeats > 0:
Expand All @@ -469,7 +473,7 @@ def _fullClone(self, shallowClone=False):
In the case of shallow clones if any of the step fail abort whole build step.
"""
res = yield self._clone(shallowClone)
if res != 0:
if res != RC_SUCCESS:
defer.returnValue(res)
return

Expand All @@ -495,7 +499,7 @@ def _fullCloneOrFallback(self):
d = self._fullClone()

def clobber(res):
if res != 0:
if res != RC_SUCCESS:
if self.clobberOnFailure:
return self.clobber()
else:
Expand All @@ -518,14 +522,14 @@ def _syncSubmodule(self, _=None):
if self.submodules:
return self._dovccmd(['submodule', 'sync'])
else:
return defer.succeed(0)
return defer.succeed(RC_SUCCESS)

def _updateSubmodule(self, _=None):
if self.submodules:
return self._dovccmd(['submodule', 'update',
'--init', '--recursive', '--force'])
else:
return defer.succeed(0)
return defer.succeed(RC_SUCCESS)

def _cleanSubmodule(self, _=None):
if self.submodules:
Expand All @@ -534,7 +538,7 @@ def _cleanSubmodule(self, _=None):
command.append('-x')
return self._dovccmd(command)
else:
return defer.succeed(0)
return defer.succeed(RC_SUCCESS)

def _getMethod(self):
if self.method is not None and self.mode != 'incremental':
Expand Down

0 comments on commit 81e7702

Please sign in to comment.