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

Side by Side Diff: gclient_scm.py

Issue 343523002: Refactor cache-updating code to eliminate unnecessary fetches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 6 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 | git_cache.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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Gclient-specific SCM-specific operations.""" 5 """Gclient-specific SCM-specific operations."""
6 6
7 from __future__ import print_function 7 from __future__ import print_function
8 8
9 import errno 9 import errno
10 import logging 10 import logging
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 rev_str = ' at %s' % revision 349 rev_str = ' at %s' % revision
350 files = [] if file_list is not None else None 350 files = [] if file_list is not None else None
351 351
352 printed_path = False 352 printed_path = False
353 verbose = [] 353 verbose = []
354 if options.verbose: 354 if options.verbose:
355 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) 355 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
356 verbose = ['--verbose'] 356 verbose = ['--verbose']
357 printed_path = True 357 printed_path = True
358 358
359 url = self._CreateOrUpdateCache(url, options)
360
361 if revision.startswith('refs/'): 359 if revision.startswith('refs/'):
362 rev_type = "branch" 360 rev_type = "branch"
363 elif revision.startswith(self.remote + '/'): 361 elif revision.startswith(self.remote + '/'):
364 # Rewrite remote refs to their local equivalents. 362 # Rewrite remote refs to their local equivalents.
365 revision = 'refs/remotes/' + revision 363 revision = 'refs/remotes/' + revision
366 rev_type = "branch" 364 rev_type = "branch"
367 else: 365 else:
368 # hash is also a tag, only make a distinction at checkout 366 # hash is also a tag, only make a distinction at checkout
369 rev_type = "hash" 367 rev_type = "hash"
370 368
369 mirror = self._GetMirror(url, options)
370 if mirror:
371 url = mirror.mirror_path
372
371 if (not os.path.exists(self.checkout_path) or 373 if (not os.path.exists(self.checkout_path) or
372 (os.path.isdir(self.checkout_path) and 374 (os.path.isdir(self.checkout_path) and
373 not os.path.exists(os.path.join(self.checkout_path, '.git')))): 375 not os.path.exists(os.path.join(self.checkout_path, '.git')))):
376 if mirror:
377 self._UpdateMirror(mirror, options)
374 try: 378 try:
375 self._Clone(revision, url, options) 379 self._Clone(revision, url, options)
376 except subprocess2.CalledProcessError: 380 except subprocess2.CalledProcessError:
377 self._DeleteOrMove(options.force) 381 self._DeleteOrMove(options.force)
378 self._Clone(revision, url, options) 382 self._Clone(revision, url, options)
379 if deps_revision and deps_revision.startswith('branch-heads/'): 383 if deps_revision and deps_revision.startswith('branch-heads/'):
380 deps_branch = deps_revision.replace('branch-heads/', '') 384 deps_branch = deps_revision.replace('branch-heads/', '')
381 self._Capture(['branch', deps_branch, deps_revision]) 385 self._Capture(['branch', deps_branch, deps_revision])
382 self._Capture(['checkout', '--quiet', deps_branch]) 386 self._Capture(['checkout', '--quiet', deps_branch])
383 if file_list is not None: 387 if file_list is not None:
384 files = self._Capture(['ls-files']).splitlines() 388 files = self._Capture(['ls-files']).splitlines()
385 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 389 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
386 if not verbose: 390 if not verbose:
387 # Make the output a little prettier. It's nice to have some whitespace 391 # Make the output a little prettier. It's nice to have some whitespace
388 # between projects when cloning. 392 # between projects when cloning.
389 self.Print('') 393 self.Print('')
390 return self._Capture(['rev-parse', '--verify', 'HEAD']) 394 return self._Capture(['rev-parse', '--verify', 'HEAD'])
391 395
392 if not managed: 396 if not managed:
393 self._UpdateBranchHeads(options, fetch=False) 397 self._UpdateBranchHeads(options, fetch=False)
394 self.Print('________ unmanaged solution; skipping %s' % self.relpath) 398 self.Print('________ unmanaged solution; skipping %s' % self.relpath)
395 return self._Capture(['rev-parse', '--verify', 'HEAD']) 399 return self._Capture(['rev-parse', '--verify', 'HEAD'])
396 400
401 if mirror:
402 self._UpdateMirror(mirror, options)
403
397 # See if the url has changed (the unittests use git://foo for the url, let 404 # See if the url has changed (the unittests use git://foo for the url, let
398 # that through). 405 # that through).
399 current_url = self._Capture(['config', 'remote.%s.url' % self.remote]) 406 current_url = self._Capture(['config', 'remote.%s.url' % self.remote])
400 return_early = False 407 return_early = False
401 # TODO(maruel): Delete url != 'git://foo' since it's just to make the 408 # TODO(maruel): Delete url != 'git://foo' since it's just to make the
402 # unit test pass. (and update the comment above) 409 # unit test pass. (and update the comment above)
403 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. 410 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set.
404 # This allows devs to use experimental repos which have a different url 411 # This allows devs to use experimental repos which have a different url
405 # but whose branch(s) are the same as official repos. 412 # but whose branch(s) are the same as official repos.
406 if (current_url.rstrip('/') != url.rstrip('/') and 413 if (current_url.rstrip('/') != url.rstrip('/') and
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 '#Initial_checkout' ) % rev) 745 '#Initial_checkout' ) % rev)
739 746
740 return sha1 747 return sha1
741 748
742 def FullUrlForRelativeUrl(self, url): 749 def FullUrlForRelativeUrl(self, url):
743 # Strip from last '/' 750 # Strip from last '/'
744 # Equivalent to unix basename 751 # Equivalent to unix basename
745 base_url = self.url 752 base_url = self.url
746 return base_url[:base_url.rfind('/')] + url 753 return base_url[:base_url.rfind('/')] + url
747 754
748 def _CreateOrUpdateCache(self, url, options): 755 def _GetMirror(self, url, options):
749 """Make a new git mirror or update existing mirror for |url|, and return the 756 """Get a git_cache.Mirror object for the argument url."""
750 mirror URI to clone from. 757 if not git_cache.Mirror.GetCachePath():
751 758 return None
752 If no cache-dir is specified, just return |url| unchanged.
753 """
754 if not self.cache_dir:
755 return url
756 mirror_kwargs = { 759 mirror_kwargs = {
757 'print_func': self.filter, 760 'print_func': self.filter,
758 'refs': [] 761 'refs': []
759 } 762 }
760 # TODO(hinoka): This currently just fails because lkcr/lkgr are branches 763 # TODO(hinoka): This currently just fails because lkcr/lkgr are branches
761 # not tags. This also adds 20 seconds to every bot_update 764 # not tags. This also adds 20 seconds to every bot_update
762 # run, so I'm commenting this out until lkcr/lkgr become 765 # run, so I'm commenting this out until lkcr/lkgr become
763 # tags. (2014/4/24) 766 # tags. (2014/4/24)
764 # if url == CHROMIUM_SRC_URL or url + '.git' == CHROMIUM_SRC_URL: 767 # if url == CHROMIUM_SRC_URL or url + '.git' == CHROMIUM_SRC_URL:
765 # mirror_kwargs['refs'].extend(['refs/tags/lkgr', 'refs/tags/lkcr']) 768 # mirror_kwargs['refs'].extend(['refs/tags/lkgr', 'refs/tags/lkcr'])
766 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: 769 if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
767 mirror_kwargs['refs'].append('refs/branch-heads/*') 770 mirror_kwargs['refs'].append('refs/branch-heads/*')
768 mirror = git_cache.Mirror(url, **mirror_kwargs) 771 return git_cache.Mirror(url, **mirror_kwargs)
772
773 @staticmethod
774 def _UpdateMirror(mirror, options):
775 """Update a git mirror by fetching the latest commits from the remote."""
769 if options.shallow: 776 if options.shallow:
770 # HACK(hinoka): These repositories should be super shallow. 777 # HACK(hinoka): These repositories should be super shallow.
iannucci 2014/06/17 23:08:17 oh, huge barf... this is why we can't have nice th
771 if 'flash' in url: 778 if 'flash' in mirror.url:
772 depth = 10 779 depth = 10
773 else: 780 else:
774 depth = 10000 781 depth = 10000
775 else: 782 else:
776 depth = None 783 depth = None
777 mirror.populate(verbose=options.verbose, bootstrap=True, depth=depth) 784 mirror.populate(verbose=options.verbose, bootstrap=True, depth=depth)
778 mirror.unlock() 785 mirror.unlock()
779 return mirror.mirror_path if mirror.exists() else None
780 786
781 def _Clone(self, revision, url, options): 787 def _Clone(self, revision, url, options):
782 """Clone a git repository from the given URL. 788 """Clone a git repository from the given URL.
783 789
784 Once we've cloned the repo, we checkout a working branch if the specified 790 Once we've cloned the repo, we checkout a working branch if the specified
785 revision is a branch head. If it is a tag or a specific commit, then we 791 revision is a branch head. If it is a tag or a specific commit, then we
786 leave HEAD detached as it makes future updates simpler -- in this case the 792 leave HEAD detached as it makes future updates simpler -- in this case the
787 user should first create a new branch or switch to an existing branch before 793 user should first create a new branch or switch to an existing branch before
788 making changes in the repo.""" 794 making changes in the repo."""
789 if not options.verbose: 795 if not options.verbose:
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 new_command.append('--force') 1489 new_command.append('--force')
1484 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1490 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1485 new_command.extend(('--accept', 'theirs-conflict')) 1491 new_command.extend(('--accept', 'theirs-conflict'))
1486 elif options.manually_grab_svn_rev: 1492 elif options.manually_grab_svn_rev:
1487 new_command.append('--force') 1493 new_command.append('--force')
1488 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1494 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1489 new_command.extend(('--accept', 'postpone')) 1495 new_command.extend(('--accept', 'postpone'))
1490 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1496 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1491 new_command.extend(('--accept', 'postpone')) 1497 new_command.extend(('--accept', 'postpone'))
1492 return new_command 1498 return new_command
OLDNEW
« no previous file with comments | « no previous file | git_cache.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698