Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1117)

Unified Diff: build/util/lastchange.py

Issue 7104106: Unify the version string to be displayed on "About Chromium" dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Improve the way to extract the SVN revision through Git Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/app/nibs/About.xib » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/util/lastchange.py
diff --git a/build/util/lastchange.py b/build/util/lastchange.py
index 4d7a1fe808d4a2707c0378ddef54d3f41a267144..be2a6bdf13d66630644a152c5ff79057cf6b80f7 100755
--- a/build/util/lastchange.py
+++ b/build/util/lastchange.py
@@ -102,117 +102,63 @@ def FetchGitRevision(directory):
return None
-def IsGitSVN(directory):
+def MatchGitSVNRevision(output):
"""
- Checks whether git-svn has been set up.
+ Extract the lastest SVN revision and the SVN URL.
Denis Lagno 2011/06/15 17:14:55 nit: there is no such word "lastest"
haraken1 2011/06/16 00:38:01 Done. "latest".
Errors are swallowed.
-
- Returns:
- whether git-svn has been set up.
- """
- # To test whether git-svn has been set up, query the config for any
- # svn-related configuration. This command exits with an error code
- # if there aren't any matches, so ignore its output.
- proc = RunGitCommand(directory, ['config', '--get-regexp', '^svn'])
- if proc:
- return (proc.wait() == 0)
- return False
-
-
-def FetchGitSVNURL(directory):
- """
- Fetch URL of SVN repository bound to git.
-
- Errors are swallowed.
-
- Returns:
- SVN URL.
- """
- if IsGitSVN(directory):
- proc = RunGitCommand(directory, ['svn', 'info', '--url'])
- if proc:
- output = proc.communicate()[0].strip()
- if proc.returncode == 0:
- match = re.search(r'^\w+://.*$', output, re.M)
- if match:
- return match.group(0)
- return ''
-
-
-def FetchGitSVNRoot(directory):
"""
- Fetch root of SVN repository bound to git.
-
- Errors are swallowed.
+ # The target line is the "git-svn-id: ..." line that appears first
+ # after "Review URL: ..." line, like this:
+ #
+ # Review URL: http://codereview.chromium.org/7057025
+ # git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85528 0039d316...
+ match = re.search(r'^Review URL:', output, re.MULTILINE)
+ if match:
+ match = re.search(r'^git-svn-id:\s*([^@]*)@([0-9]+)',
+ output[match.end():], re.MULTILINE)
+ if match:
+ return (match.group(1), match.group(2))
+ return (None, None)
- Returns:
- SVN root repository.
- """
- if IsGitSVN(directory):
- git_command = ['config', '--get-regexp', '^svn-remote.svn.url$']
- proc = RunGitCommand(directory, git_command)
- if proc:
- output = proc.communicate()[0].strip()
- if proc.returncode == 0:
- # Zero return code implies presence of requested configuration variable.
- # Its value is second (last) field of output.
- match = re.search(r'\S+$', output)
- if match:
- return match.group(0)
- return ''
-
-
-def LookupGitSVNRevision(directory, depth):
+def FetchGitSVNRevision(directory):
"""
- Fetch the Git-SVN identifier for the local tree.
- Parses first |depth| commit messages.
+ Fetch the SVN revision for a given directory through Git.
Errors are swallowed.
"""
- if not IsGitSVN(directory):
- return None
- git_re = re.compile(r'^\s*git-svn-id:\s+(\S+)@(\d+)')
- proc = RunGitCommand(directory, ['log', '-' + str(depth)])
+ proc = RunGitCommand(directory, ['log', '-1',
+ '--grep=git-svn-id', '--format=%b'])
if proc:
- for line in proc.stdout:
- match = git_re.match(line)
- if match:
- id = match.group(2)
- if id:
- proc.stdout.close() # Cut pipe for fast exit.
- return id
+ output = proc.communicate()[0].strip()
+ if proc.returncode == 0 and output:
+ # Extract the lastest SVN revision and the SVN URL.
+ (url, revision) = MatchGitSVNRevision(output)
+
+ if url and revision:
+ # Check if there are any local changes.
+ dirty = True
+ proc = RunGitCommand(directory, ['log', '-1'])
+ if proc:
+ output = proc.communicate()[0].strip()
+ if proc.returncode == 0 and output:
+ # Check if there are any local commits.
+ (dummy_url, dummy_revision) = MatchGitSVNRevision(output)
+
+ if dummy_url and dummy_revision:
+ # Check if there are any local uncommitted changes.
+ proc = RunGitCommand(directory, ['checkout'])
+ if proc:
+ output = proc.communicate()[0].strip()
+ if proc.returncode == 0 and not output:
+ dirty = False
+
+ if dirty:
+ revision = revision + "-dirty"
+ return VersionInfo(url, 'git-svn', revision)
return None
-def IsGitSVNDirty(directory):
- """
- Checks whether our git-svn tree contains clean trunk or some branch.
-
- Errors are swallowed.
- """
- # For git branches the last commit message is either
- # some local commit or a merge.
- return LookupGitSVNRevision(directory, 1) is None
-
-
-def FetchGitSVNRevision(directory):
- """
- Fetch the Git-SVN identifier for the local tree.
-
- Errors are swallowed.
- """
- # We assume that at least first 999 commit messages contain svn evidence.
- revision = LookupGitSVNRevision(directory, 999)
- if not revision:
- return None
- if IsGitSVNDirty(directory):
- revision = revision + '-dirty'
- url = FetchGitSVNURL(directory)
- root = FetchGitSVNRoot(directory)
- return VersionInfo(url, root, revision)
-
-
def FetchVersionInfo(default_lastchange, directory=None):
"""
Returns the last change (in the form of a branch, revision tuple),
« no previous file with comments | « no previous file | chrome/app/nibs/About.xib » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698