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

Unified Diff: gclient_scm.py

Issue 437903002: Add --no-history option to fetch and gclient for shallow clones. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Add test to gclient_smoketest.py Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient.py ('k') | gclient_utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_scm.py
diff --git a/gclient_scm.py b/gclient_scm.py
index a87032e749902122c676b6621dde4fec33f8f232..df1054f112233032e21cb45a21a50d48af8dbc74 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -825,6 +825,25 @@ class GitWrapper(SCMWrapper):
# create it, so we need to do it manually.
parent_dir = os.path.dirname(self.checkout_path)
gclient_utils.safe_makedirs(parent_dir)
+
+ template_dir = None
+ if options.no_history:
+ if gclient_utils.IsGitSha(revision):
+ # In the case of a subproject, the pinned sha is not necessarily the
+ # head of the remote branch (so we can't just use --depth=N). Instead,
+ # we tell git to fetch all the remote objects from SHA..HEAD by means of
+ # a template git dir which has a 'shallow' file pointing to the sha.
+ template_dir = tempfile.mkdtemp(
+ prefix='_gclient_gittmp_%s' % os.path.basename(self.checkout_path),
+ dir=parent_dir)
+ self._Run(['init', '--bare', template_dir], options, cwd=self._root_dir)
+ with open(os.path.join(template_dir, 'shallow'), 'w') as template_file:
+ template_file.write(revision)
+ clone_cmd.append('--template=' + template_dir)
+ else:
+ # Otherwise, we're just interested in the HEAD. Just use --depth.
+ clone_cmd.append('--depth=1')
+
tmp_dir = tempfile.mkdtemp(
prefix='_gclient_%s_' % os.path.basename(self.checkout_path),
dir=parent_dir)
@@ -841,6 +860,8 @@ class GitWrapper(SCMWrapper):
if os.listdir(tmp_dir):
self.Print('_____ removing non-empty tmp dir %s' % tmp_dir)
gclient_utils.rmtree(tmp_dir)
+ if template_dir:
+ gclient_utils.rmtree(template_dir)
self._UpdateBranchHeads(options, fetch=True)
self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True)
if self._GetCurrentBranch() is None:
« no previous file with comments | « gclient.py ('k') | gclient_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698