OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 re | 10 import re |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 proc = RunGitCommand(directory, ['svn', 'info', '--url']) | 133 proc = RunGitCommand(directory, ['svn', 'info', '--url']) |
134 if proc: | 134 if proc: |
135 output = proc.communicate()[0].strip() | 135 output = proc.communicate()[0].strip() |
136 if proc.returncode == 0: | 136 if proc.returncode == 0: |
137 match = re.search(r'^\w+://.*$', output, re.M) | 137 match = re.search(r'^\w+://.*$', output, re.M) |
138 if match: | 138 if match: |
139 return match.group(0) | 139 return match.group(0) |
140 return '' | 140 return '' |
141 | 141 |
142 | 142 |
143 def FetchGitSVNRoot(directory): | |
144 """ | |
145 Fetch root of SVN repository bound to git. | |
146 | |
147 Errors are swallowed. | |
148 | |
149 Returns: | |
150 SVN root repository. | |
151 """ | |
152 if IsGitSVN(directory): | |
153 git_command = ['config', '--get-regexp', '^svn-remote.svn.url$'] | |
154 proc = RunGitCommand(directory, git_command) | |
155 if proc: | |
156 output = proc.communicate()[0].strip() | |
157 if proc.returncode == 0: | |
158 match = re.search(r'\S+$', output) | |
Evan Martin
2011/03/04 00:17:05
Ah, I see. You want to grab the right half of the
Denis Lagno
2011/03/04 00:49:21
Done.
| |
159 if match: | |
160 return match.group(0) | |
161 return '' | |
162 | |
163 | |
143 def LookupGitSVNRevision(directory, depth): | 164 def LookupGitSVNRevision(directory, depth): |
144 """ | 165 """ |
145 Fetch the Git-SVN identifier for the local tree. | 166 Fetch the Git-SVN identifier for the local tree. |
146 Parses first |depth| commit messages. | 167 Parses first |depth| commit messages. |
147 | 168 |
148 Errors are swallowed. | 169 Errors are swallowed. |
149 """ | 170 """ |
150 if not IsGitSVN(directory): | 171 if not IsGitSVN(directory): |
151 return None | 172 return None |
152 git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M) | 173 git_re = re.compile(r'^\s*git-svn-id:\s+(\S+)@(\d+)') |
153 proc = RunGitCommand(directory, ['log', '-' + str(depth)]) | 174 proc = RunGitCommand(directory, ['log', '-' + str(depth)]) |
154 if proc: | 175 if proc: |
155 for line in proc.stdout: | 176 for line in proc.stdout: |
156 match = git_re.search(line) | 177 match = git_re.match(line) |
157 if match: | 178 if match: |
158 id = match.group(2) | 179 id = match.group(2) |
159 if id: | 180 if id: |
160 proc.stdout.close() # Cut pipe for fast exit. | 181 proc.stdout.close() # Cut pipe for fast exit. |
161 return id | 182 return id |
162 return None | 183 return None |
163 | 184 |
164 | 185 |
165 def IsGitSVNDirty(directory): | 186 def IsGitSVNDirty(directory): |
166 """ | 187 """ |
(...skipping 11 matching lines...) Expand all Loading... | |
178 Fetch the Git-SVN identifier for the local tree. | 199 Fetch the Git-SVN identifier for the local tree. |
179 | 200 |
180 Errors are swallowed. | 201 Errors are swallowed. |
181 """ | 202 """ |
182 # We assume that at least first 999 commit messages contain svn evidence. | 203 # We assume that at least first 999 commit messages contain svn evidence. |
183 revision = LookupGitSVNRevision(directory, 999) | 204 revision = LookupGitSVNRevision(directory, 999) |
184 if not revision: | 205 if not revision: |
185 return None | 206 return None |
186 if IsGitSVNDirty(directory): | 207 if IsGitSVNDirty(directory): |
187 revision = revision + '-dirty' | 208 revision = revision + '-dirty' |
188 return VersionInfo(FetchGitSVNURL(directory), 'git-svn', revision) | 209 url = FetchGitSVNURL(directory) |
210 root = FetchGitSVNRoot(directory) | |
211 return VersionInfo(url, root, revision) | |
189 | 212 |
190 | 213 |
191 def FetchVersionInfo(default_lastchange, directory=None): | 214 def FetchVersionInfo(default_lastchange, directory=None): |
192 """ | 215 """ |
193 Returns the last change (in the form of a branch, revision tuple), | 216 Returns the last change (in the form of a branch, revision tuple), |
194 from some appropriate revision control system. | 217 from some appropriate revision control system. |
195 """ | 218 """ |
196 version_info = (FetchSVNRevision(directory) or | 219 version_info = (FetchSVNRevision(directory) or |
197 FetchGitSVNRevision(directory) or FetchGitRevision(directory)) | 220 FetchGitSVNRevision(directory) or FetchGitRevision(directory)) |
198 if not version_info: | 221 if not version_info: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 if out_file: | 275 if out_file: |
253 WriteIfChanged(out_file, contents) | 276 WriteIfChanged(out_file, contents) |
254 else: | 277 else: |
255 sys.stdout.write(contents) | 278 sys.stdout.write(contents) |
256 | 279 |
257 return 0 | 280 return 0 |
258 | 281 |
259 | 282 |
260 if __name__ == '__main__': | 283 if __name__ == '__main__': |
261 sys.exit(main()) | 284 sys.exit(main()) |
OLD | NEW |