Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not line:
continue
key, val = line.split(': ', 1)
attrs[key] = val
try:
match = svn_url_regex.search(attrs['URL'])
if match:
url = match.group(2)
else:
url = ''
revision = attrs['Revision']
except KeyError:
return None
return VersionInfo(url, revision)
if proc.returncode == 0 and output:
hsh = output
if not hsh:
return None
pos = ''
proc = RunGitCommand(directory, ['cat-file', 'commit', 'HEAD'])
if proc:
output = proc.communicate()[0]
if proc.returncode == 0 and output:
for line in reversed(output.splitlines()):
if line.startswith('Cr-Commit-Position:'):
pos = line.rsplit()[-1].strip()
break
if not pos:
return VersionInfo('git', hsh)
return VersionInfo('git', '%s-%s' % (hsh, pos))
output = proc.communicate()[0].strip()
if proc.returncode == 0 and output:
hsh = output
if not hsh:
return None
pos = ''
proc = RunGitCommand(directory, ['cat-file', 'commit', 'HEAD'])
if proc:
output = proc.communicate()[0]
if proc.returncode == 0 and output:
for line in reversed(output.splitlines()):
if line.startswith('Cr-Commit-Position:'):
pos = line.rsplit()[-1].strip()
break
if not pos:
return VersionInfo('git', hsh)
return VersionInfo('git', '%s-%s' % (hsh, pos))
"""
Returns the last change (in the form of a branch, revision tuple),
from some appropriate revision control system.
"""
svn_url_regex = re.compile(
r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)')
version_info = (FetchSVNRevision(directory, svn_url_regex) or
FetchGitSVNRevision(directory, svn_url_regex, go_deeper) or
FetchGitRevision(directory))
if not version_info:
if default_lastchange and os.path.exists(default_lastchange):
revision = open(default_lastchange, 'r').read().strip()
version_info = VersionInfo(None, revision)
else:
version_info = VersionInfo(None, None)
return version_info
def FetchVersionInfo(default_lastchange, directory=None):
"""
Returns the last change (in the form of a branch, revision tuple),
from some appropriate revision control system.
"""
version_info = FetchSVNRevision(directory) or FetchGitRevision(directory)
if not version_info:
if default_lastchange and os.path.exists(default_lastchange):
revision = open(default_lastchange, 'r').read().strip()
version_info = VersionInfo(None, None, revision)
else:
version_info = VersionInfo('unknown', '', '0')
return version_info
directory_regex_prior_to_src_url='chrome|blink|svn',
go_deeper=False):
"""
Returns the last change (in the form of a branch, revision tuple),
from some appropriate revision control system.
"""
svn_url_regex = re.compile(
r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)')
version_info = (FetchSVNRevision(directory, svn_url_regex) or
FetchGitSVNRevision(directory, svn_url_regex, go_deeper) or
FetchGitRevision(directory))
if not version_info:
if default_lastchange and os.path.exists(default_lastchange):
revision = open(default_lastchange, 'r').read().strip()
version_info = VersionInfo(None, revision)
else:
version_info = VersionInfo(None, None)
return version_info
# mysterious loss of cwd while invoking cygwin's git.
# We can't just pass shell=True to Popen, as under win32 this will
# cause CMD to be used, while we explicitly want a cygwin shell.
command = ['git', 'rev-parse', 'HEAD']
if sys.platform in ('cygwin', 'win32'):
command = ['sh', '-c', ' '.join(command)]
try:
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=directory)
except OSError:
return None
output = proc.communicate()[0].strip()
if proc.returncode == 0 and output:
return VersionInfo('git', 'git', output[:7])
return None
def FetchVersionInfo(default_lastchange, directory=None):
"""
Returns the last change (in the form of a branch, revision tuple),
from some appropriate revision control system.
"""
version_info = FetchSVNRevision(directory) or FetchGitRevision(directory)
if not version_info:
if default_lastchange and os.path.exists(default_lastchange):
revision = open(default_lastchange, 'r').read().strip()
version_info = VersionInfo(None, None, revision)
else:
version_info = VersionInfo('unknown', '', '0')
return version_info