Fix version calculation for older commits on a release branch (fixes issue #2659)

This commit is contained in:
Chris Dziemborowicz 2019-05-15 14:35:41 +00:00 committed by Marshall Greenblatt
parent c7701b8a61
commit f9b042c375
3 changed files with 22 additions and 5 deletions

View File

@ -172,11 +172,18 @@ class VersionFormatter:
cef_commit = self.get_cef_commit_components()
cef_commit_hash = self._format_commit_hash(cef_commit['HASH'])
# Remove the remote name prefix, if any.
cef_branch_name = git.get_branch_name(self.cef_path).split('/')[-1]
# Determine whether the current commit is on a release branch. For example,
# if using Chrome build 3683, are we on CEF branch "3683" or "origin/3683"?
release_branch = chrome_version['BUILD']
on_release_branch = (
git.is_ancestor(self.cef_path, 'HEAD', release_branch) or
git.is_ancestor(self.cef_path, 'HEAD', 'origin/' + release_branch))
if not on_release_branch:
# Not on a commit that is part of an official named release branch. See
# if we can get the name of the branch we are on (may be just "HEAD").
cef_branch_name = git.get_branch_name(self.cef_path).split('/')[-1]
if cef_branch_name != chrome_version['BUILD']:
# Not on an official named release branch.
self._version_parts = {'MAJOR': int(chrome_major), 'MINOR': 0, 'PATCH': 0}
self._version_string = '%s.0.0-%s.%s+%s+%s' % \
(chrome_major, cef_branch_name, cef_commit['NUMBER'],

View File

@ -10,6 +10,7 @@ def exec_cmd(cmd, path, input_string=None):
""" Execute the specified command and return the result. """
out = ''
err = ''
ret = -1
parts = cmd.split()
try:
if input_string is None:
@ -20,6 +21,7 @@ def exec_cmd(cmd, path, input_string=None):
stderr=PIPE,
shell=(sys.platform == 'win32'))
out, err = process.communicate()
ret = process.returncode
else:
process = Popen(
parts,
@ -29,8 +31,9 @@ def exec_cmd(cmd, path, input_string=None):
stderr=PIPE,
shell=(sys.platform == 'win32'))
out, err = process.communicate(input=input_string)
ret = process.returncode
except IOError, (errno, strerror):
raise
except:
raise
return {'out': out, 'err': err}
return {'out': out, 'err': err, 'ret': ret}

View File

@ -18,6 +18,13 @@ def is_checkout(path):
return os.path.isdir(os.path.join(path, '.git'))
def is_ancestor(path='.', commit1='HEAD', commit2='master'):
""" Returns whether |commit1| is an ancestor of |commit2|. """
cmd = "%s merge-base --is-ancestor %s %s" % (git_exe, commit1, commit2)
result = exec_cmd(cmd, path)
return result['ret'] == 0
def get_hash(path='.', branch='HEAD'):
""" Returns the git hash for the specified branch/tag/hash. """
cmd = "%s rev-parse %s" % (git_exe, branch)