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

Side by Side Diff: build/util/lastchange.py

Issue 6267010: lastchange: handle the git-but-not-git-svn case (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | webkit/build/webkit_version.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 lastchange.py -- Chromium revision fetching utility. 7 lastchange.py -- Chromium revision fetching utility.
8 """ 8 """
9 9
10 import optparse 10 import optparse
11 import os 11 import os
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 14
15 class VersionInfo(object): 15 class VersionInfo(object):
16 def __init__(self, url, root, revision): 16 def __init__(self, url, root, revision):
17 self.url = url 17 self.url = url
18 self.root = root 18 self.root = root
19 self.revision = revision 19 self.revision = revision
20 20
21 21
22 def IsGitSVN(directory):
23 """Return true if the directory is managed by git-svn."""
24
25 # To test whether git-svn has been set up, query the config for any
26 # svn-related configuration. This command exits with an error code
27 # if there aren't any matches, so ignore its output.
28 status = subprocess.call(['git', 'config', '--get-regexp', '^svn'],
29 stdout=subprocess.PIPE,
30 stderr=subprocess.PIPE,
31 cwd=directory)
32 return status == 0
33
34
22 def FetchSVNRevision(command, directory): 35 def FetchSVNRevision(command, directory):
23 """ 36 """
24 Fetch the Subversion branch and revision for the a given directory 37 Fetch the Subversion branch and revision for the a given directory
25 by running the given command (e.g. "svn info"). 38 by running the given command (e.g. "svn info").
26 39
27 Errors are swallowed. 40 Errors are swallowed.
28 41
29 Returns: 42 Returns:
30 a VersionInfo object or None on error. 43 a VersionInfo object or None on error.
31 """ 44 """
32 45
33 # Force shell usage under cygwin & win32. This is a workaround for 46 # Force shell usage under cygwin & win32. This is a workaround for
34 # mysterious loss of cwd while invoking cygwin's git. 47 # mysterious loss of cwd while invoking cygwin's git.
35 # We can't just pass shell=True to Popen, as under win32 this will 48 # We can't just pass shell=True to Popen, as under win32 this will
36 # cause CMD to be used, while we explicitly want a cygwin shell. 49 # cause CMD to be used, while we explicitly want a cygwin shell.
37 if sys.platform in ('cygwin', 'win32'): 50 if sys.platform in ('cygwin', 'win32'):
38 command = [ 'sh', '-c', ' '.join(command) ]; 51 command = ['sh', '-c', ' '.join(command)]
39 try: 52 try:
40 proc = subprocess.Popen(command, 53 proc = subprocess.Popen(command,
41 stdout=subprocess.PIPE, 54 stdout=subprocess.PIPE,
42 stderr=subprocess.PIPE, 55 stderr=subprocess.PIPE,
43 cwd=directory) 56 cwd=directory)
44 except OSError: 57 except OSError:
45 # command is apparently either not installed or not executable. 58 # command is apparently either not installed or not executable.
46 return None 59 return None
47 if not proc: 60 if not proc:
48 return None 61 return None
(...skipping 16 matching lines...) Expand all
65 return VersionInfo(url, root, revision) 78 return VersionInfo(url, root, revision)
66 79
67 80
68 def FetchVersionInfo(default_lastchange, directory=None): 81 def FetchVersionInfo(default_lastchange, directory=None):
69 """ 82 """
70 Returns the last change (in the form of a branch, revision tuple), 83 Returns the last change (in the form of a branch, revision tuple),
71 from some appropriate revision control system. 84 from some appropriate revision control system.
72 """ 85 """
73 version_info = FetchSVNRevision(['svn', 'info'], directory) 86 version_info = FetchSVNRevision(['svn', 'info'], directory)
74 if not version_info: 87 if not version_info:
75 version_info = FetchSVNRevision(['git', 'svn', 'info'], directory) 88 # Check that this is a git-svn repo before running 'git svn info',
89 # as that will hang if not.
90 if IsGitSVN(directory):
tony 2011/01/24 17:57:44 Nit: Maybe merge this condition with the 'not vers
91 version_info = FetchSVNRevision(['git', 'svn', 'info'], directory)
76 if not version_info: 92 if not version_info:
77 if default_lastchange and os.path.exists(default_lastchange): 93 if default_lastchange and os.path.exists(default_lastchange):
78 revision = open(default_lastchange, 'r').read().strip() 94 revision = open(default_lastchange, 'r').read().strip()
79 version_info = VersionInfo(None, None, revision) 95 version_info = VersionInfo(None, None, revision)
80 else: 96 else:
81 version_info = VersionInfo('', '', '0') 97 version_info = VersionInfo('unknown', '', '0')
82 return version_info 98 return version_info
83 99
84 100
85 def WriteIfChanged(file_name, contents): 101 def WriteIfChanged(file_name, contents):
86 """ 102 """
87 Writes the specified contents to the specified file_name 103 Writes the specified contents to the specified file_name
88 iff the contents are different than the current contents. 104 iff the contents are different than the current contents.
89 """ 105 """
90 try: 106 try:
91 old_contents = open(file_name, 'r').read() 107 old_contents = open(file_name, 'r').read()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if out_file: 146 if out_file:
131 WriteIfChanged(out_file, contents) 147 WriteIfChanged(out_file, contents)
132 else: 148 else:
133 sys.stdout.write(contents) 149 sys.stdout.write(contents)
134 150
135 return 0 151 return 0
136 152
137 153
138 if __name__ == '__main__': 154 if __name__ == '__main__':
139 sys.exit(main()) 155 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | webkit/build/webkit_version.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698