Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 | |
| 7 import cStringIO | 6 import cStringIO |
| 8 import os | 7 import os |
| 9 import re | 8 import re |
| 10 import subprocess | 9 import subprocess |
| 11 import sys | 10 import sys |
| 12 import threading | 11 import threading |
| 13 | 12 |
| 13 try: | |
| 14 import git_cache | |
| 15 except ImportError: | |
| 16 for p in os.environ['PATH'].split(os.pathsep): | |
| 17 if (os.path.basename(p) == 'depot_tools' and | |
| 18 os.path.exists(os.path.join(p, 'git_cache.py'))): | |
| 19 sys.path.append(p) | |
| 20 import git_cache | |
| 21 | |
| 14 | 22 |
| 15 # Show more information about the commands being executed. | 23 # Show more information about the commands being executed. |
| 16 VERBOSE = False | 24 VERBOSE = False |
| 17 | 25 |
| 18 # The longest any single subprocess will be allowed to run. | 26 # The longest any single subprocess will be allowed to run. |
| 19 TIMEOUT = 40 * 60 | 27 TIMEOUT = 40 * 60 |
| 20 | 28 |
| 21 class AbnormalExit(Exception): | 29 class AbnormalExit(Exception): |
| 22 pass | 30 pass |
| 23 | 31 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 # For Abnormal Exit, Windows returns -1, Posix returns 128. | 128 # For Abnormal Exit, Windows returns -1, Posix returns 128. |
| 121 if status in [-1, 128]: | 129 if status in [-1, 128]: |
| 122 raise AbnormalExit('Failed to run %s. Exited Abnormally. output %s' % | 130 raise AbnormalExit('Failed to run %s. Exited Abnormally. output %s' % |
| 123 (cmd, output)) | 131 (cmd, output)) |
| 124 elif status != 0: | 132 elif status != 0: |
| 125 raise Exception('Failed to run %s. error %d. output %s' % (cmd, status, | 133 raise Exception('Failed to run %s. error %d. output %s' % (cmd, status, |
| 126 output)) | 134 output)) |
| 127 return (status, output) | 135 return (status, output) |
| 128 | 136 |
| 129 | 137 |
| 130 def GetCacheRepoDir(git_url, cache_dir): | 138 def Clone(git_url, git_repo, is_mirror, out_buffer=None): |
| 131 """Assuming we used git_cache to populate a cache, get the repo directory.""" | |
| 132 _, out = Git(None, 'cache exists --cache-dir=%s %s' % (cache_dir, git_url), | |
| 133 is_mirror=True) | |
| 134 return out.strip() | |
| 135 | |
| 136 | |
| 137 def Clone(git_url, git_repo, is_mirror, out_queue=None, cache_dir=None, | |
| 138 shallow=False): | |
| 139 """Clone a repository.""" | 139 """Clone a repository.""" |
| 140 repo_name = git_url.split('/')[-1] | |
| 141 if out_queue: | |
| 142 buf = StdioBuffer(repo_name, out_queue) | |
| 143 else: | |
| 144 buf = None | |
| 145 | |
| 146 if is_mirror == 'bare': | |
| 147 if shallow: | |
| 148 if 'adobe' in git_url: | |
| 149 # --shallow by default checks out 10000 revision, but for really large | |
| 150 # repos like adobe ones, we want significantly less than 10000. | |
| 151 shallow_arg = '--depth 10 ' | |
| 152 else: | |
| 153 shallow_arg = '--shallow ' | |
| 154 else: | |
| 155 shallow_arg = '' | |
| 156 cmd = 'cache populate -v --cache-dir %s %s%s' % (cache_dir, shallow_arg, | |
| 157 git_url) | |
| 158 return Git(None, cmd, is_mirror=True, out_buffer=buf) | |
| 159 | |
| 160 cmd = 'clone' | 140 cmd = 'clone' |
| 161 if is_mirror: | 141 if is_mirror: |
| 162 cmd += ' --mirror' | 142 cmd += ' --mirror' |
| 163 cmd += ' %s %s' % (git_url, git_repo) | 143 cmd += ' %s %s' % (git_url, git_repo) |
| 164 | 144 |
| 165 if not is_mirror and not os.path.exists(git_repo): | 145 if not is_mirror and not os.path.exists(git_repo): |
| 166 os.makedirs(git_repo) | 146 os.makedirs(git_repo) |
| 167 | 147 |
| 168 return Git(None, cmd, is_mirror, buf) | 148 return Git(None, cmd, is_mirror=is_mirror, out_buffer=out_buffer) |
| 149 | |
| 150 | |
| 151 def PopulateCache(git_url, shallow=False): | |
| 152 # --shallow by default checks out 10000 revision, but for really large | |
| 153 # repos like adobe ones, we want significantly less than 10000. | |
| 154 depth = None | |
| 155 if shallow and 'adobe' in git_url: | |
| 156 depth = 10 | |
| 157 mirror = git_cache.Mirror(git_url, print_func=lambda *args: None) | |
| 158 mirror.populate(depth=depth, shallow=shallow) | |
| 159 return mirror.mirror_path | |
| 169 | 160 |
| 170 | 161 |
| 171 def Fetch(git_repo, git_url, is_mirror): | 162 def Fetch(git_repo, git_url, is_mirror): |
| 172 """Fetch the latest objects for a given git repository.""" | 163 """Fetch the latest objects for a given git repository.""" |
| 173 # Always update the upstream url | 164 # Always update the upstream url |
| 174 Git(git_repo, 'config remote.origin.url %s' % git_url) | 165 Git(git_repo, 'config remote.origin.url %s' % git_url) |
| 175 Git(git_repo, 'fetch origin', is_mirror) | 166 Git(git_repo, 'fetch origin', is_mirror) |
| 176 | 167 |
| 177 | 168 |
| 178 def Ping(git_repo, verbose=False): | 169 def Ping(git_repo, verbose=False): |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 # Find the first commit matching the given git-svn-id regex. | 273 # Find the first commit matching the given git-svn-id regex. |
| 283 _, output = Git( | 274 _, output = Git( |
| 284 git_repo, | 275 git_repo, |
| 285 ('log -E --grep="^git-svn-id: [^@]*@%s [A-Za-z0-9-]*$" ' | 276 ('log -E --grep="^git-svn-id: [^@]*@%s [A-Za-z0-9-]*$" ' |
| 286 '-1 --format="%%H" %s') % (regex, refspec), | 277 '-1 --format="%%H" %s') % (regex, refspec), |
| 287 is_mirror) | 278 is_mirror) |
| 288 output = output.strip() | 279 output = output.strip() |
| 289 if not re.match('^[0-9a-fA-F]{40}$', output): | 280 if not re.match('^[0-9a-fA-F]{40}$', output): |
| 290 raise SearchError('Cannot find revision %s in %s:%s' % (svn_rev, git_repo, | 281 raise SearchError('Cannot find revision %s in %s:%s' % (svn_rev, git_repo, |
| 291 refspec)) | 282 refspec)) |
| 292 | |
| 293 # Check if it actually matched the svn_rev that was requested. | |
| 294 found_rev = _FindRevForCommitish(git_repo, output, is_mirror) | |
| 295 found_msg = svn_rev | |
| 296 if found_rev != int(svn_rev): | |
| 297 found_msg = '%s [actual: %s]' % (svn_rev, found_rev) | |
| 298 print '%s: %s <-> %s' % (git_repo, output, found_msg) | |
|
Michael Moss
2014/05/15 16:26:40
Why are you getting rid of this? Just to cut down
szager1
2014/05/19 21:40:07
This is the only noise printed to stdout, other th
Michael Moss
2014/05/19 22:09:11
I have actually found it helpful in the past (thou
| |
| 299 return output | 283 return output |
| 300 | 284 |
| 301 | 285 |
| 302 def SearchExact(git_repo, svn_rev, is_mirror, refspec='FETCH_HEAD', | 286 def SearchExact(git_repo, svn_rev, is_mirror, refspec='FETCH_HEAD', |
| 303 fetch_url=None): | 287 fetch_url=None): |
| 304 """Return the Git commit id exactly matching the given SVN revision. | 288 """Return the Git commit id exactly matching the given SVN revision. |
| 305 | 289 |
| 306 If fetch_url is not None, will update repo if revision is newer.""" | 290 If fetch_url is not None, will update repo if revision is newer.""" |
| 307 regex = str(svn_rev) | 291 regex = str(svn_rev) |
| 308 return _SearchImpl(git_repo, svn_rev, is_mirror, refspec, fetch_url, regex) | 292 return _SearchImpl(git_repo, svn_rev, is_mirror, refspec, fetch_url, regex) |
| 309 | 293 |
| 310 | 294 |
| 311 def Search(git_repo, svn_rev, is_mirror, refspec='FETCH_HEAD', fetch_url=None): | 295 def Search(git_repo, svn_rev, is_mirror, refspec='FETCH_HEAD', fetch_url=None): |
| 312 """Return the Git commit id fuzzy matching the given SVN revision. | 296 """Return the Git commit id fuzzy matching the given SVN revision. |
| 313 | 297 |
| 314 If fetch_url is not None, will update repo if revision is newer.""" | 298 If fetch_url is not None, will update repo if revision is newer.""" |
| 315 regex = CreateLessThanOrEqualRegex(svn_rev) | 299 regex = CreateLessThanOrEqualRegex(svn_rev) |
| 316 return _SearchImpl(git_repo, svn_rev, is_mirror, refspec, fetch_url, regex) | 300 return _SearchImpl(git_repo, svn_rev, is_mirror, refspec, fetch_url, regex) |
| OLD | NEW |