Index: git_tools.py |
diff --git a/git_tools.py b/git_tools.py |
index 3a5408f6f3965d6a505df48856f51aba37371e68..1f10885fbc9de8e89968a8024b28c28ee34c7e1e 100644 |
--- a/git_tools.py |
+++ b/git_tools.py |
@@ -3,7 +3,6 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
- |
import cStringIO |
import os |
import re |
@@ -11,6 +10,15 @@ import subprocess |
import sys |
import threading |
+try: |
+ import git_cache |
+except ImportError: |
+ for p in os.environ['PATH'].split(os.pathsep): |
+ if (os.path.basename(p) == 'depot_tools' and |
+ os.path.exists(os.path.join(p, 'git_cache.py'))): |
+ sys.path.append(p) |
+ import git_cache |
+ |
# Show more information about the commands being executed. |
VERBOSE = False |
@@ -127,36 +135,8 @@ def Git(git_repo, command, is_mirror=False, out_buffer=None): |
return (status, output) |
-def GetCacheRepoDir(git_url, cache_dir): |
- """Assuming we used git_cache to populate a cache, get the repo directory.""" |
- _, out = Git(None, 'cache exists --cache-dir=%s %s' % (cache_dir, git_url), |
- is_mirror=True) |
- return out.strip() |
- |
- |
-def Clone(git_url, git_repo, is_mirror, out_queue=None, cache_dir=None, |
- shallow=False): |
+def Clone(git_url, git_repo, is_mirror, out_buffer=None): |
"""Clone a repository.""" |
- repo_name = git_url.split('/')[-1] |
- if out_queue: |
- buf = StdioBuffer(repo_name, out_queue) |
- else: |
- buf = None |
- |
- if is_mirror == 'bare': |
- if shallow: |
- if 'adobe' in git_url: |
- # --shallow by default checks out 10000 revision, but for really large |
- # repos like adobe ones, we want significantly less than 10000. |
- shallow_arg = '--depth 10 ' |
- else: |
- shallow_arg = '--shallow ' |
- else: |
- shallow_arg = '' |
- cmd = 'cache populate -v --cache-dir %s %s%s' % (cache_dir, shallow_arg, |
- git_url) |
- return Git(None, cmd, is_mirror=True, out_buffer=buf) |
- |
cmd = 'clone' |
if is_mirror: |
cmd += ' --mirror' |
@@ -165,7 +145,18 @@ def Clone(git_url, git_repo, is_mirror, out_queue=None, cache_dir=None, |
if not is_mirror and not os.path.exists(git_repo): |
os.makedirs(git_repo) |
- return Git(None, cmd, is_mirror, buf) |
+ return Git(None, cmd, is_mirror=is_mirror, out_buffer=out_buffer) |
+ |
+ |
+def PopulateCache(git_url, shallow=False): |
+ # --shallow by default checks out 10000 revision, but for really large |
+ # repos like adobe ones, we want significantly less than 10000. |
+ depth = None |
+ if shallow and 'adobe' in git_url: |
+ depth = 10 |
+ mirror = git_cache.Mirror(git_url, print_func=lambda *args: None) |
+ mirror.populate(depth=depth, shallow=shallow) |
+ return mirror.mirror_path |
def Fetch(git_repo, git_url, is_mirror): |
@@ -289,13 +280,6 @@ def _SearchImpl(git_repo, svn_rev, is_mirror, refspec, fetch_url, regex): |
if not re.match('^[0-9a-fA-F]{40}$', output): |
raise SearchError('Cannot find revision %s in %s:%s' % (svn_rev, git_repo, |
refspec)) |
- |
- # Check if it actually matched the svn_rev that was requested. |
- found_rev = _FindRevForCommitish(git_repo, output, is_mirror) |
- found_msg = svn_rev |
- if found_rev != int(svn_rev): |
- found_msg = '%s [actual: %s]' % (svn_rev, found_rev) |
- 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
|
return output |