Просмотр исходного кода

sync: Allow -j to have a default in manifest

This permits manifest authors to suggest a number of parallel
fetch operations against a remote server. For example, Gerrit
Code Review servers support queuing of requests and processes
them in first-in, first-out order. Running concurrent fetches
can utilize multiple CPUs on the Gerrit server, but will also
decrease overall operation latency by having the request put
into the queue ready to execute as soon as a CPU is free.

Change-Id: I3d3904acb6f63516bae4b071c510ad57a2afab18
Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce 14 лет назад
Родитель
Сommit
6392c87945
3 измененных файлов с 14 добавлено и 1 удалено
  1. 1 0
      docs/manifest-format.txt
  2. 9 0
      manifest_xml.py
  3. 4 1
      subcmds/sync.py

+ 1 - 0
docs/manifest-format.txt

@@ -38,6 +38,7 @@ following DTD:
     <!ELEMENT default (EMPTY)>
     <!ELEMENT default (EMPTY)>
     <!ATTLIST default remote   IDREF #IMPLIED>
     <!ATTLIST default remote   IDREF #IMPLIED>
     <!ATTLIST default revision CDATA #IMPLIED>
     <!ATTLIST default revision CDATA #IMPLIED>
+    <!ATTLIST default sync-j   CDATA #IMPLIED>
 
 
     <!ELEMENT manifest-server (EMPTY)>
     <!ELEMENT manifest-server (EMPTY)>
     <!ATTLIST url              CDATA #REQUIRED>
     <!ATTLIST url              CDATA #REQUIRED>

+ 9 - 0
manifest_xml.py

@@ -29,6 +29,7 @@ class _Default(object):
 
 
   revisionExpr = None
   revisionExpr = None
   remote = None
   remote = None
+  sync_j = 1
 
 
 class _XmlRemote(object):
 class _XmlRemote(object):
   def __init__(self,
   def __init__(self,
@@ -133,6 +134,9 @@ class XmlManifest(object):
     if d.revisionExpr:
     if d.revisionExpr:
       have_default = True
       have_default = True
       e.setAttribute('revision', d.revisionExpr)
       e.setAttribute('revision', d.revisionExpr)
+    if d.sync_j > 1:
+      have_default = True
+      e.setAttribute('sync-j', '%d' % d.sync_j)
     if have_default:
     if have_default:
       root.appendChild(e)
       root.appendChild(e)
       root.appendChild(doc.createTextNode(''))
       root.appendChild(doc.createTextNode(''))
@@ -401,6 +405,11 @@ class XmlManifest(object):
     d.revisionExpr = node.getAttribute('revision')
     d.revisionExpr = node.getAttribute('revision')
     if d.revisionExpr == '':
     if d.revisionExpr == '':
       d.revisionExpr = None
       d.revisionExpr = None
+    sync_j = node.getAttribute('sync-j')
+    if sync_j == '' or sync_j is None:
+      d.sync_j = 1
+    else:
+      d.sync_j = int(sync_j)
     return d
     return d
 
 
   def _ParseNotice(self, node):
   def _ParseNotice(self, node):

+ 4 - 1
subcmds/sync.py

@@ -117,6 +117,8 @@ later is required to fix a server side protocol bug.
 """
 """
 
 
   def _Options(self, p, show_smart=True):
   def _Options(self, p, show_smart=True):
+    self.jobs = self.manifest.default.sync_j
+
     p.add_option('-f', '--force-broken',
     p.add_option('-f', '--force-broken',
                  dest='force_broken', action='store_true',
                  dest='force_broken', action='store_true',
                  help="continue sync even if a project fails to sync")
                  help="continue sync even if a project fails to sync")
@@ -134,7 +136,8 @@ later is required to fix a server side protocol bug.
                  help='be more quiet')
                  help='be more quiet')
     p.add_option('-j','--jobs',
     p.add_option('-j','--jobs',
                  dest='jobs', action='store', type='int',
                  dest='jobs', action='store', type='int',
-                 help="number of projects to fetch simultaneously")
+                 default=self.jobs,
+                 help="projects to fetch simultaneously (default %d)" % self.jobs)
     if show_smart:
     if show_smart:
       p.add_option('-s', '--smart-sync',
       p.add_option('-s', '--smart-sync',
                    dest='smart_sync', action='store_true',
                    dest='smart_sync', action='store_true',