Allow clone depth to be specified per project

If the clone-depth attribute is set on a project, its value will
be used to set the depth when fetching the git.  The value, if
given, must be a positive integer.

The value in the clone-depth attribute overrides any value given to
repo init via the --depth command line option.

Change-Id: I273015b3724213600b63e40cca4cafaa9f782ddf
This commit is contained in:
David Pursehouse 2012-11-27 22:25:30 +09:00
parent 04d84a23fd
commit ede7f12d4a
3 changed files with 23 additions and 2 deletions

View File

@ -56,6 +56,7 @@ following DTD:
<!ATTLIST project sync-c CDATA #IMPLIED> <!ATTLIST project sync-c CDATA #IMPLIED>
<!ATTLIST project sync-s CDATA #IMPLIED> <!ATTLIST project sync-s CDATA #IMPLIED>
<!ATTLIST project upstream CDATA #IMPLIED> <!ATTLIST project upstream CDATA #IMPLIED>
<!ATTLIST project clone-depth CDATA #IMPLIED>
<!ELEMENT annotation (EMPTY)> <!ELEMENT annotation (EMPTY)>
<!ATTLIST annotation name CDATA #REQUIRED> <!ATTLIST annotation name CDATA #REQUIRED>
@ -222,6 +223,10 @@ Attribute `upstream`: Name of the Git branch in which a sha1
can be found. Used when syncing a revision locked manifest in can be found. Used when syncing a revision locked manifest in
-c mode to avoid having to sync the entire ref space. -c mode to avoid having to sync the entire ref space.
Attribute `clone-depth`: Set the depth to use when fetching this
project. If specified, this value will override any value given
to repo init with the --depth option on the command line.
Element annotation Element annotation
------------------ ------------------

View File

@ -665,6 +665,16 @@ class XmlManifest(object):
else: else:
sync_s = sync_s.lower() in ("yes", "true", "1") sync_s = sync_s.lower() in ("yes", "true", "1")
clone_depth = node.getAttribute('clone-depth')
if clone_depth:
try:
clone_depth = int(clone_depth)
if clone_depth <= 0:
raise ValueError()
except ValueError:
raise ManifestParseError('invalid clone-depth %s in %s' %
(clone_depth, self.manifestFile))
upstream = node.getAttribute('upstream') upstream = node.getAttribute('upstream')
groups = '' groups = ''
@ -692,6 +702,7 @@ class XmlManifest(object):
groups = groups, groups = groups,
sync_c = sync_c, sync_c = sync_c,
sync_s = sync_s, sync_s = sync_s,
clone_depth = clone_depth,
upstream = upstream, upstream = upstream,
parent = parent) parent = parent)

View File

@ -488,6 +488,7 @@ class Project(object):
groups = None, groups = None,
sync_c = False, sync_c = False,
sync_s = False, sync_s = False,
clone_depth = None,
upstream = None, upstream = None,
parent = None, parent = None,
is_derived = False): is_derived = False):
@ -533,6 +534,7 @@ class Project(object):
self.groups = groups self.groups = groups
self.sync_c = sync_c self.sync_c = sync_c
self.sync_s = sync_s self.sync_s = sync_s
self.clone_depth = clone_depth
self.upstream = upstream self.upstream = upstream
self.parent = parent self.parent = parent
self.is_derived = is_derived self.is_derived = is_derived
@ -1645,7 +1647,10 @@ class Project(object):
# The --depth option only affects the initial fetch; after that we'll do # The --depth option only affects the initial fetch; after that we'll do
# full fetches of changes. # full fetches of changes.
depth = self.manifest.manifestProject.config.GetString('repo.depth') if self.clone_depth:
depth = self.clone_depth
else:
depth = self.manifest.manifestProject.config.GetString('repo.depth')
if depth and initial: if depth and initial:
cmd.append('--depth=%s' % depth) cmd.append('--depth=%s' % depth)
@ -1705,7 +1710,7 @@ class Project(object):
return ok return ok
def _ApplyCloneBundle(self, initial=False, quiet=False): def _ApplyCloneBundle(self, initial=False, quiet=False):
if initial and self.manifest.manifestProject.config.GetString('repo.depth'): if initial and (self.manifest.manifestProject.config.GetString('repo.depth') or self.clone_depth):
return False return False
remote = self.GetRemote(self.remote.name) remote = self.GetRemote(self.remote.name)