Commit bdaef127 authored by agable@chromium.org's avatar agable@chromium.org

Get lastchange.py to work correctly on Git repositories.

This changes lastchange.py in two ways:
1) If the commit it finds is a Git hash, it outputs the whole hash, not just
   the first 7 characters.
2) It only looks at HEAD to see if there is a git-svn id. Previously, it used
   --grep=git-svn-id, which would find the most recent commit containing a
   git-svn id. This would be broken after the switch to git, as it would always
   find the last commit before the switch. Now, it only inspects the most recent
   commit, and falls through to pure-Git if that fails.

R=dilmah@chromium.org, stip@chromium.org
BUG=399113

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

Cr-Commit-Position: refs/heads/master@{#291165}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291165 0039d316-1c4b-4281-b951-d872f2087c98
parent 03b08926
...@@ -99,12 +99,25 @@ def FetchGitRevision(directory): ...@@ -99,12 +99,25 @@ def FetchGitRevision(directory):
Returns: Returns:
A VersionInfo object or None on error. A VersionInfo object or None on error.
""" """
hsh = ''
proc = RunGitCommand(directory, ['rev-parse', 'HEAD']) proc = RunGitCommand(directory, ['rev-parse', 'HEAD'])
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:
return VersionInfo('git', output[:7]) hsh = output
return None if not hsh:
return None
pos = ''
proc = RunGitCommand(directory, ['show', '-s', '--format=%B', '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()
if not pos:
return VersionInfo('git', hsh)
return VersionInfo('git', '%s-%s' % (hsh, pos))
def FetchGitSVNURLAndRevision(directory, svn_url_regex): def FetchGitSVNURLAndRevision(directory, svn_url_regex):
...@@ -116,8 +129,7 @@ def FetchGitSVNURLAndRevision(directory, svn_url_regex): ...@@ -116,8 +129,7 @@ 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', proc = RunGitCommand(directory, ['log', '-1', '--format=%b'])
'--grep=git-svn-id', '--format=%b'])
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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment