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 # Zero return code implies presence of requested configuration variable. |
| 159 # Its value is second (last) field of output. |
| 160 match = re.search(r'\S+$', output) |
| 161 if match: |
| 162 return match.group(0) |
| 163 return '' |
| 164 |
| 165 |
143 def LookupGitSVNRevision(directory, depth): | 166 def LookupGitSVNRevision(directory, depth): |
144 """ | 167 """ |
145 Fetch the Git-SVN identifier for the local tree. | 168 Fetch the Git-SVN identifier for the local tree. |
146 Parses first |depth| commit messages. | 169 Parses first |depth| commit messages. |
147 | 170 |
148 Errors are swallowed. | 171 Errors are swallowed. |
149 """ | 172 """ |
150 if not IsGitSVN(directory): | 173 if not IsGitSVN(directory): |
151 return None | 174 return None |
152 git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M) | 175 git_re = re.compile(r'^\s*git-svn-id:\s+(\S+)@(\d+)') |
153 proc = RunGitCommand(directory, ['log', '-' + str(depth)]) | 176 proc = RunGitCommand(directory, ['log', '-' + str(depth)]) |
154 if proc: | 177 if proc: |
155 for line in proc.stdout: | 178 for line in proc.stdout: |
156 match = git_re.search(line) | 179 match = git_re.match(line) |
157 if match: | 180 if match: |
158 id = match.group(2) | 181 id = match.group(2) |
159 if id: | 182 if id: |
160 proc.stdout.close() # Cut pipe for fast exit. | 183 proc.stdout.close() # Cut pipe for fast exit. |
161 return id | 184 return id |
162 return None | 185 return None |
163 | 186 |
164 | 187 |
165 def IsGitSVNDirty(directory): | 188 def IsGitSVNDirty(directory): |
166 """ | 189 """ |
(...skipping 11 matching lines...) Expand all Loading... |
178 Fetch the Git-SVN identifier for the local tree. | 201 Fetch the Git-SVN identifier for the local tree. |
179 | 202 |
180 Errors are swallowed. | 203 Errors are swallowed. |
181 """ | 204 """ |
182 # We assume that at least first 999 commit messages contain svn evidence. | 205 # We assume that at least first 999 commit messages contain svn evidence. |
183 revision = LookupGitSVNRevision(directory, 999) | 206 revision = LookupGitSVNRevision(directory, 999) |
184 if not revision: | 207 if not revision: |
185 return None | 208 return None |
186 if IsGitSVNDirty(directory): | 209 if IsGitSVNDirty(directory): |
187 revision = revision + '-dirty' | 210 revision = revision + '-dirty' |
188 return VersionInfo(FetchGitSVNURL(directory), 'git-svn', revision) | 211 url = FetchGitSVNURL(directory) |
| 212 root = FetchGitSVNRoot(directory) |
| 213 return VersionInfo(url, root, revision) |
189 | 214 |
190 | 215 |
191 def FetchVersionInfo(default_lastchange, directory=None): | 216 def FetchVersionInfo(default_lastchange, directory=None): |
192 """ | 217 """ |
193 Returns the last change (in the form of a branch, revision tuple), | 218 Returns the last change (in the form of a branch, revision tuple), |
194 from some appropriate revision control system. | 219 from some appropriate revision control system. |
195 """ | 220 """ |
196 version_info = (FetchSVNRevision(directory) or | 221 version_info = (FetchSVNRevision(directory) or |
197 FetchGitSVNRevision(directory) or FetchGitRevision(directory)) | 222 FetchGitSVNRevision(directory) or FetchGitRevision(directory)) |
198 if not version_info: | 223 if not version_info: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if out_file: | 277 if out_file: |
253 WriteIfChanged(out_file, contents) | 278 WriteIfChanged(out_file, contents) |
254 else: | 279 else: |
255 sys.stdout.write(contents) | 280 sys.stdout.write(contents) |
256 | 281 |
257 return 0 | 282 return 0 |
258 | 283 |
259 | 284 |
260 if __name__ == '__main__': | 285 if __name__ == '__main__': |
261 sys.exit(main()) | 286 sys.exit(main()) |
OLD | NEW |