Restore under flag historic behaviour of lastchange.py wrt. Git-SVN repos

Adds optional flag '--git-svn-go-deeper' to allow lastchange.py find
the last committed SVN revision in a Git-SVN repo.

This is to help access DevTools frontend on Android for Chromium developers
that have local changes to Blink.

BUG=468691

Review URL: https://codereview.chromium.org/1197483002

Cr-Original-Commit-Position: refs/heads/master@{#335156}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b73e2ea7a4e319eb2e6183090dfe6b9796d42c3b
This commit is contained in:
mnaganov 2015-06-18 16:16:23 -07:00 коммит произвёл Commit bot
Родитель 07f9035953
Коммит 2997f0f83b
1 изменённых файлов: 16 добавлений и 7 удалений

Просмотреть файл

@ -121,7 +121,7 @@ def FetchGitRevision(directory):
return VersionInfo('git', '%s-%s' % (hsh, pos)) return VersionInfo('git', '%s-%s' % (hsh, pos))
def FetchGitSVNURLAndRevision(directory, svn_url_regex): def FetchGitSVNURLAndRevision(directory, svn_url_regex, go_deeper):
""" """
Fetch the Subversion URL and revision through Git. Fetch the Subversion URL and revision through Git.
@ -130,7 +130,10 @@ def FetchGitSVNURLAndRevision(directory, svn_url_regex):
Returns: Returns:
A tuple containing the Subversion URL and revision. A tuple containing the Subversion URL and revision.
""" """
proc = RunGitCommand(directory, ['log', '-1', '--format=%b']) git_args = ['log', '-1', '--format=%b']
if go_deeper:
git_args.append('--grep=git-svn-id')
proc = RunGitCommand(directory, git_args)
if proc: if proc:
output = proc.communicate()[0].strip() output = proc.communicate()[0].strip()
if proc.returncode == 0 and output: if proc.returncode == 0 and output:
@ -149,20 +152,21 @@ def FetchGitSVNURLAndRevision(directory, svn_url_regex):
return None, None return None, None
def FetchGitSVNRevision(directory, svn_url_regex): def FetchGitSVNRevision(directory, svn_url_regex, go_deeper):
""" """
Fetch the Git-SVN identifier for the local tree. Fetch the Git-SVN identifier for the local tree.
Errors are swallowed. Errors are swallowed.
""" """
url, revision = FetchGitSVNURLAndRevision(directory, svn_url_regex) url, revision = FetchGitSVNURLAndRevision(directory, svn_url_regex, go_deeper)
if url and revision: if url and revision:
return VersionInfo(url, revision) return VersionInfo(url, revision)
return None return None
def FetchVersionInfo(default_lastchange, directory=None, def FetchVersionInfo(default_lastchange, directory=None,
directory_regex_prior_to_src_url='chrome|blink|svn'): directory_regex_prior_to_src_url='chrome|blink|svn',
go_deeper=False):
""" """
Returns the last change (in the form of a branch, revision tuple), Returns the last change (in the form of a branch, revision tuple),
from some appropriate revision control system. from some appropriate revision control system.
@ -171,7 +175,7 @@ def FetchVersionInfo(default_lastchange, directory=None,
r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)')
version_info = (FetchSVNRevision(directory, svn_url_regex) or version_info = (FetchSVNRevision(directory, svn_url_regex) or
FetchGitSVNRevision(directory, svn_url_regex) or FetchGitSVNRevision(directory, svn_url_regex, go_deeper) or
FetchGitRevision(directory)) FetchGitRevision(directory))
if not version_info: if not version_info:
if default_lastchange and os.path.exists(default_lastchange): if default_lastchange and os.path.exists(default_lastchange):
@ -256,6 +260,9 @@ def main(argv=None):
"file-output-related options.") "file-output-related options.")
parser.add_option("-s", "--source-dir", metavar="DIR", parser.add_option("-s", "--source-dir", metavar="DIR",
help="Use repository in the given directory.") help="Use repository in the given directory.")
parser.add_option("--git-svn-go-deeper", action='store_true',
help="In a Git-SVN repo, dig down to the last committed " +
"SVN change (historic behaviour).")
opts, args = parser.parse_args(argv[1:]) opts, args = parser.parse_args(argv[1:])
out_file = opts.output out_file = opts.output
@ -274,7 +281,9 @@ def main(argv=None):
else: else:
src_dir = os.path.dirname(os.path.abspath(__file__)) src_dir = os.path.dirname(os.path.abspath(__file__))
version_info = FetchVersionInfo(opts.default_lastchange, src_dir) version_info = FetchVersionInfo(opts.default_lastchange,
directory=src_dir,
go_deeper=opts.git_svn_go_deeper)
if version_info.revision == None: if version_info.revision == None:
version_info.revision = '0' version_info.revision = '0'