summaryrefslogtreecommitdiffstats
path: root/build/util
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 01:28:58 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 01:28:58 +0000
commitb13d29eec6bf0dd2ca457cce09e67a4a41a250d1 (patch)
tree4787978c1ee71939e4d4205daca18c72c38499d7 /build/util
parentc1590348b8a7b7d5adedfeffc306eaf9dde77f97 (diff)
downloadchromium_src-b13d29eec6bf0dd2ca457cce09e67a4a41a250d1.zip
chromium_src-b13d29eec6bf0dd2ca457cce09e67a4a41a250d1.tar.gz
chromium_src-b13d29eec6bf0dd2ca457cce09e67a4a41a250d1.tar.bz2
lastchange.py: fix style, unify git codepath
1) Change style to match style guide. 2) Use "git svn info" so we can use the same parsing code for both git and svn. TEST=ran manually Review URL: http://codereview.chromium.org/6263009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/util')
-rwxr-xr-x[-rw-r--r--]build/util/lastchange.py56
1 files changed, 15 insertions, 41 deletions
diff --git a/build/util/lastchange.py b/build/util/lastchange.py
index 00b275f..ff518fc 100644..100755
--- a/build/util/lastchange.py
+++ b/build/util/lastchange.py
@@ -14,61 +14,35 @@ import subprocess
import sys
-def svn_fetch_revision():
+def FetchSVNRevision(command):
"""
Fetch the Subversion revision for the local tree.
Errors are swallowed.
"""
try:
- p = subprocess.Popen(['svn', 'info'],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- shell=(sys.platform=='win32'))
- except OSError, e:
- # 'svn' is apparently either not installed or not executable.
- return None
- revision = None
- if p:
- svn_re = re.compile('^Revision:\s+(\d+)', re.M)
- m = svn_re.search(p.stdout.read())
- if m:
- revision = m.group(1)
- return revision
-
-
-def git_fetch_id():
- """
- Fetch the GIT identifier for the local tree.
-
- Errors are swallowed.
- """
- git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M)
- try:
- proc = subprocess.Popen(['git', 'log', '-999'],
+ proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=(sys.platform=='win32'))
- for line in proc.stdout:
- match = git_re.search(line)
- if match:
- id = match.group(2)
- if id:
- proc.stdout.close() # Cut pipe.
- return id
except OSError:
- # 'git' is apparently either not installed or not executable.
- pass
+ # command is apparently either not installed or not executable.
+ return None
+ if proc:
+ svn_re = re.compile('^Revision:\s+(\d+)', re.M)
+ match = svn_re.search(proc.stdout.read())
+ if match:
+ return match.group(1)
return None
-def fetch_change(default_lastchange):
+def FetchChange(default_lastchange):
"""
Returns the last change, from some appropriate revision control system.
"""
- change = svn_fetch_revision()
+ change = FetchSVNRevision(['svn', 'info'])
if not change and sys.platform in ('linux2',):
- change = git_fetch_id()
+ change = FetchSVNRevision(['git', 'svn', 'info'])
if not change:
if default_lastchange and os.path.exists(default_lastchange):
change = open(default_lastchange, 'r').read().strip()
@@ -77,7 +51,7 @@ def fetch_change(default_lastchange):
return change
-def write_if_changed(file_name, contents):
+def WriteIfChanged(file_name, contents):
"""
Writes the specified contents to the specified file_name
iff the contents are different than the current contents.
@@ -114,12 +88,12 @@ def main(argv=None):
parser.print_help()
sys.exit(2)
- change = fetch_change(opts.default_lastchange)
+ change = FetchChange(opts.default_lastchange)
contents = "LASTCHANGE=%s\n" % change
if out_file:
- write_if_changed(out_file, contents)
+ WriteIfChanged(out_file, contents)
else:
sys.stdout.write(contents)