diff options
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r-- | subcmds/sync.py | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index 9b8a6122..6cac2e52 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -23,6 +23,11 @@ import sys | |||
23 | import time | 23 | import time |
24 | import xmlrpclib | 24 | import xmlrpclib |
25 | 25 | ||
26 | try: | ||
27 | import threading as _threading | ||
28 | except ImportError: | ||
29 | import dummy_threading as _threading | ||
30 | |||
26 | from git_command import GIT | 31 | from git_command import GIT |
27 | from git_refs import R_HEADS | 32 | from git_refs import R_HEADS |
28 | from project import HEAD | 33 | from project import HEAD |
@@ -35,6 +40,7 @@ from project import SyncBuffer | |||
35 | from progress import Progress | 40 | from progress import Progress |
36 | 41 | ||
37 | class Sync(Command, MirrorSafeCommand): | 42 | class Sync(Command, MirrorSafeCommand): |
43 | jobs = 1 | ||
38 | common = True | 44 | common = True |
39 | helpSummary = "Update working tree to the latest revision" | 45 | helpSummary = "Update working tree to the latest revision" |
40 | helpUsage = """ | 46 | helpUsage = """ |
@@ -104,6 +110,9 @@ later is required to fix a server side protocol bug. | |||
104 | p.add_option('-d','--detach', | 110 | p.add_option('-d','--detach', |
105 | dest='detach_head', action='store_true', | 111 | dest='detach_head', action='store_true', |
106 | help='detach projects back to manifest revision') | 112 | help='detach projects back to manifest revision') |
113 | p.add_option('-j','--jobs', | ||
114 | dest='jobs', action='store', type='int', | ||
115 | help="number of projects to fetch simultaneously") | ||
107 | if show_smart: | 116 | if show_smart: |
108 | p.add_option('-s', '--smart-sync', | 117 | p.add_option('-s', '--smart-sync', |
109 | dest='smart_sync', action='store_true', | 118 | dest='smart_sync', action='store_true', |
@@ -117,16 +126,44 @@ later is required to fix a server side protocol bug. | |||
117 | dest='repo_upgraded', action='store_true', | 126 | dest='repo_upgraded', action='store_true', |
118 | help=SUPPRESS_HELP) | 127 | help=SUPPRESS_HELP) |
119 | 128 | ||
129 | def _FetchHelper(self, project, lock, fetched, pm, sem): | ||
130 | if not project.Sync_NetworkHalf(): | ||
131 | print >>sys.stderr, 'error: Cannot fetch %s' % project.name | ||
132 | sem.release() | ||
133 | sys.exit(1) | ||
134 | |||
135 | lock.acquire() | ||
136 | fetched.add(project.gitdir) | ||
137 | pm.update() | ||
138 | lock.release() | ||
139 | sem.release() | ||
140 | |||
120 | def _Fetch(self, projects): | 141 | def _Fetch(self, projects): |
121 | fetched = set() | 142 | fetched = set() |
122 | pm = Progress('Fetching projects', len(projects)) | 143 | pm = Progress('Fetching projects', len(projects)) |
123 | for project in projects: | 144 | |
124 | pm.update() | 145 | if self.jobs == 1: |
125 | if project.Sync_NetworkHalf(): | 146 | for project in projects: |
126 | fetched.add(project.gitdir) | 147 | pm.update() |
127 | else: | 148 | if project.Sync_NetworkHalf(): |
128 | print >>sys.stderr, 'error: Cannot fetch %s' % project.name | 149 | fetched.add(project.gitdir) |
129 | sys.exit(1) | 150 | else: |
151 | print >>sys.stderr, 'error: Cannot fetch %s' % project.name | ||
152 | sys.exit(1) | ||
153 | else: | ||
154 | threads = set() | ||
155 | lock = _threading.Lock() | ||
156 | sem = _threading.Semaphore(self.jobs) | ||
157 | for project in projects: | ||
158 | sem.acquire() | ||
159 | t = _threading.Thread(target = self._FetchHelper, | ||
160 | args = (project, lock, fetched, pm, sem)) | ||
161 | threads.add(t) | ||
162 | t.start() | ||
163 | |||
164 | for t in threads: | ||
165 | t.join() | ||
166 | |||
130 | pm.end() | 167 | pm.end() |
131 | return fetched | 168 | return fetched |
132 | 169 | ||
@@ -190,6 +227,8 @@ uncommitted changes are present' % project.relpath | |||
190 | return 0 | 227 | return 0 |
191 | 228 | ||
192 | def Execute(self, opt, args): | 229 | def Execute(self, opt, args): |
230 | if opt.jobs: | ||
231 | self.jobs = opt.jobs | ||
193 | if opt.network_only and opt.detach_head: | 232 | if opt.network_only and opt.detach_head: |
194 | print >>sys.stderr, 'error: cannot combine -n and -d' | 233 | print >>sys.stderr, 'error: cannot combine -n and -d' |
195 | sys.exit(1) | 234 | sys.exit(1) |