diff options
Diffstat (limited to 'subcmds')
-rw-r--r-- | subcmds/cherry_pick.py | 1 | ||||
-rw-r--r-- | subcmds/forall.py | 40 | ||||
-rw-r--r-- | subcmds/init.py | 4 | ||||
-rw-r--r-- | subcmds/sync.py | 34 |
4 files changed, 63 insertions, 16 deletions
diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py index 520e4c32..1f7dffdc 100644 --- a/subcmds/cherry_pick.py +++ b/subcmds/cherry_pick.py | |||
@@ -76,6 +76,7 @@ change id will be added. | |||
76 | capture_stdout = True, | 76 | capture_stdout = True, |
77 | capture_stderr = True) | 77 | capture_stderr = True) |
78 | p.stdin.write(new_msg) | 78 | p.stdin.write(new_msg) |
79 | p.stdin.close() | ||
79 | if p.Wait() != 0: | 80 | if p.Wait() != 0: |
80 | print("error: Failed to update commit message", file=sys.stderr) | 81 | print("error: Failed to update commit message", file=sys.stderr) |
81 | sys.exit(1) | 82 | sys.exit(1) |
diff --git a/subcmds/forall.py b/subcmds/forall.py index 88b23fbd..b93cd6d0 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -20,6 +20,7 @@ import multiprocessing | |||
20 | import re | 20 | import re |
21 | import os | 21 | import os |
22 | import select | 22 | import select |
23 | import signal | ||
23 | import sys | 24 | import sys |
24 | import subprocess | 25 | import subprocess |
25 | 26 | ||
@@ -150,11 +151,15 @@ without iterating through the remaining projects. | |||
150 | attributes that we need. | 151 | attributes that we need. |
151 | 152 | ||
152 | """ | 153 | """ |
154 | if not self.manifest.IsMirror: | ||
155 | lrev = project.GetRevisionId() | ||
156 | else: | ||
157 | lrev = None | ||
153 | return { | 158 | return { |
154 | 'name': project.name, | 159 | 'name': project.name, |
155 | 'relpath': project.relpath, | 160 | 'relpath': project.relpath, |
156 | 'remote_name': project.remote.name, | 161 | 'remote_name': project.remote.name, |
157 | 'lrev': project.GetRevisionId(), | 162 | 'lrev': lrev, |
158 | 'rrev': project.revisionExpr, | 163 | 'rrev': project.revisionExpr, |
159 | 'annotations': dict((a.name, a.value) for a in project.annotations), | 164 | 'annotations': dict((a.name, a.value) for a in project.annotations), |
160 | 'gitdir': project.gitdir, | 165 | 'gitdir': project.gitdir, |
@@ -200,6 +205,13 @@ without iterating through the remaining projects. | |||
200 | mirror = self.manifest.IsMirror | 205 | mirror = self.manifest.IsMirror |
201 | rc = 0 | 206 | rc = 0 |
202 | 207 | ||
208 | smart_sync_manifest_name = "smart_sync_override.xml" | ||
209 | smart_sync_manifest_path = os.path.join( | ||
210 | self.manifest.manifestProject.worktree, smart_sync_manifest_name) | ||
211 | |||
212 | if os.path.isfile(smart_sync_manifest_path): | ||
213 | self.manifest.Override(smart_sync_manifest_path) | ||
214 | |||
203 | if not opt.regex: | 215 | if not opt.regex: |
204 | projects = self.GetProjects(args) | 216 | projects = self.GetProjects(args) |
205 | else: | 217 | else: |
@@ -207,14 +219,12 @@ without iterating through the remaining projects. | |||
207 | 219 | ||
208 | os.environ['REPO_COUNT'] = str(len(projects)) | 220 | os.environ['REPO_COUNT'] = str(len(projects)) |
209 | 221 | ||
210 | pool = multiprocessing.Pool(opt.jobs) | 222 | pool = multiprocessing.Pool(opt.jobs, InitWorker) |
211 | try: | 223 | try: |
212 | config = self.manifest.manifestProject.config | 224 | config = self.manifest.manifestProject.config |
213 | results_it = pool.imap( | 225 | results_it = pool.imap( |
214 | DoWorkWrapper, | 226 | DoWorkWrapper, |
215 | ([mirror, opt, cmd, shell, cnt, config, self._SerializeProject(p)] | 227 | self.ProjectArgs(projects, mirror, opt, cmd, shell, config)) |
216 | for cnt, p in enumerate(projects)) | ||
217 | ) | ||
218 | pool.close() | 228 | pool.close() |
219 | for r in results_it: | 229 | for r in results_it: |
220 | rc = rc or r | 230 | rc = rc or r |
@@ -236,12 +246,28 @@ without iterating through the remaining projects. | |||
236 | if rc != 0: | 246 | if rc != 0: |
237 | sys.exit(rc) | 247 | sys.exit(rc) |
238 | 248 | ||
249 | def ProjectArgs(self, projects, mirror, opt, cmd, shell, config): | ||
250 | for cnt, p in enumerate(projects): | ||
251 | try: | ||
252 | project = self._SerializeProject(p) | ||
253 | except Exception as e: | ||
254 | print('Project list error: %r' % e, | ||
255 | file=sys.stderr) | ||
256 | return | ||
257 | except KeyboardInterrupt: | ||
258 | print('Project list interrupted', | ||
259 | file=sys.stderr) | ||
260 | return | ||
261 | yield [mirror, opt, cmd, shell, cnt, config, project] | ||
239 | 262 | ||
240 | class WorkerKeyboardInterrupt(Exception): | 263 | class WorkerKeyboardInterrupt(Exception): |
241 | """ Keyboard interrupt exception for worker processes. """ | 264 | """ Keyboard interrupt exception for worker processes. """ |
242 | pass | 265 | pass |
243 | 266 | ||
244 | 267 | ||
268 | def InitWorker(): | ||
269 | signal.signal(signal.SIGINT, signal.SIG_IGN) | ||
270 | |||
245 | def DoWorkWrapper(args): | 271 | def DoWorkWrapper(args): |
246 | """ A wrapper around the DoWork() method. | 272 | """ A wrapper around the DoWork() method. |
247 | 273 | ||
@@ -263,7 +289,9 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config): | |||
263 | def setenv(name, val): | 289 | def setenv(name, val): |
264 | if val is None: | 290 | if val is None: |
265 | val = '' | 291 | val = '' |
266 | env[name] = val.encode() | 292 | if hasattr(val, 'encode'): |
293 | val = val.encode() | ||
294 | env[name] = val | ||
267 | 295 | ||
268 | setenv('REPO_PROJECT', project['name']) | 296 | setenv('REPO_PROJECT', project['name']) |
269 | setenv('REPO_PATH', project['relpath']) | 297 | setenv('REPO_PATH', project['relpath']) |
diff --git a/subcmds/init.py b/subcmds/init.py index b73de71c..dbb6ddda 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
@@ -27,7 +27,7 @@ else: | |||
27 | import imp | 27 | import imp |
28 | import urlparse | 28 | import urlparse |
29 | urllib = imp.new_module('urllib') | 29 | urllib = imp.new_module('urllib') |
30 | urllib.parse = urlparse.urlparse | 30 | urllib.parse = urlparse |
31 | 31 | ||
32 | from color import Coloring | 32 | from color import Coloring |
33 | from command import InteractiveCommand, MirrorSafeCommand | 33 | from command import InteractiveCommand, MirrorSafeCommand |
@@ -153,7 +153,7 @@ to update the working directory files. | |||
153 | # server where this git is located, so let's save that here. | 153 | # server where this git is located, so let's save that here. |
154 | mirrored_manifest_git = None | 154 | mirrored_manifest_git = None |
155 | if opt.reference: | 155 | if opt.reference: |
156 | manifest_git_path = urllib.parse(opt.manifest_url).path[1:] | 156 | manifest_git_path = urllib.parse.urlparse(opt.manifest_url).path[1:] |
157 | mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path) | 157 | mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path) |
158 | if not mirrored_manifest_git.endswith(".git"): | 158 | if not mirrored_manifest_git.endswith(".git"): |
159 | mirrored_manifest_git += ".git" | 159 | mirrored_manifest_git += ".git" |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 2bdab3a6..ec333ae7 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -131,6 +131,10 @@ of a project from server. | |||
131 | The -c/--current-branch option can be used to only fetch objects that | 131 | The -c/--current-branch option can be used to only fetch objects that |
132 | are on the branch specified by a project's revision. | 132 | are on the branch specified by a project's revision. |
133 | 133 | ||
134 | The --optimized-fetch option can be used to only fetch projects that | ||
135 | are fixed to a sha1 revision if the sha1 revision does not already | ||
136 | exist locally. | ||
137 | |||
134 | SSH Connections | 138 | SSH Connections |
135 | --------------- | 139 | --------------- |
136 | 140 | ||
@@ -206,6 +210,9 @@ later is required to fix a server side protocol bug. | |||
206 | p.add_option('--no-tags', | 210 | p.add_option('--no-tags', |
207 | dest='no_tags', action='store_true', | 211 | dest='no_tags', action='store_true', |
208 | help="don't fetch tags") | 212 | help="don't fetch tags") |
213 | p.add_option('--optimized-fetch', | ||
214 | dest='optimized_fetch', action='store_true', | ||
215 | help='only fetch projects fixed to sha1 if revision does not exist locally') | ||
209 | if show_smart: | 216 | if show_smart: |
210 | p.add_option('-s', '--smart-sync', | 217 | p.add_option('-s', '--smart-sync', |
211 | dest='smart_sync', action='store_true', | 218 | dest='smart_sync', action='store_true', |
@@ -275,7 +282,8 @@ later is required to fix a server side protocol bug. | |||
275 | quiet=opt.quiet, | 282 | quiet=opt.quiet, |
276 | current_branch_only=opt.current_branch_only, | 283 | current_branch_only=opt.current_branch_only, |
277 | clone_bundle=not opt.no_clone_bundle, | 284 | clone_bundle=not opt.no_clone_bundle, |
278 | no_tags=opt.no_tags, archive=self.manifest.IsArchive) | 285 | no_tags=opt.no_tags, archive=self.manifest.IsArchive, |
286 | optimized_fetch=opt.optimized_fetch) | ||
279 | self._fetch_times.Set(project, time.time() - start) | 287 | self._fetch_times.Set(project, time.time() - start) |
280 | 288 | ||
281 | # Lock around all the rest of the code, since printing, updating a set | 289 | # Lock around all the rest of the code, since printing, updating a set |
@@ -509,6 +517,9 @@ later is required to fix a server side protocol bug. | |||
509 | self.manifest.Override(opt.manifest_name) | 517 | self.manifest.Override(opt.manifest_name) |
510 | 518 | ||
511 | manifest_name = opt.manifest_name | 519 | manifest_name = opt.manifest_name |
520 | smart_sync_manifest_name = "smart_sync_override.xml" | ||
521 | smart_sync_manifest_path = os.path.join( | ||
522 | self.manifest.manifestProject.worktree, smart_sync_manifest_name) | ||
512 | 523 | ||
513 | if opt.smart_sync or opt.smart_tag: | 524 | if opt.smart_sync or opt.smart_tag: |
514 | if not self.manifest.manifest_server: | 525 | if not self.manifest.manifest_server: |
@@ -575,17 +586,16 @@ later is required to fix a server side protocol bug. | |||
575 | [success, manifest_str] = server.GetManifest(opt.smart_tag) | 586 | [success, manifest_str] = server.GetManifest(opt.smart_tag) |
576 | 587 | ||
577 | if success: | 588 | if success: |
578 | manifest_name = "smart_sync_override.xml" | 589 | manifest_name = smart_sync_manifest_name |
579 | manifest_path = os.path.join(self.manifest.manifestProject.worktree, | ||
580 | manifest_name) | ||
581 | try: | 590 | try: |
582 | f = open(manifest_path, 'w') | 591 | f = open(smart_sync_manifest_path, 'w') |
583 | try: | 592 | try: |
584 | f.write(manifest_str) | 593 | f.write(manifest_str) |
585 | finally: | 594 | finally: |
586 | f.close() | 595 | f.close() |
587 | except IOError: | 596 | except IOError as e: |
588 | print('error: cannot write manifest to %s' % manifest_path, | 597 | print('error: cannot write manifest to %s:\n%s' |
598 | % (smart_sync_manifest_path, e), | ||
589 | file=sys.stderr) | 599 | file=sys.stderr) |
590 | sys.exit(1) | 600 | sys.exit(1) |
591 | self._ReloadManifest(manifest_name) | 601 | self._ReloadManifest(manifest_name) |
@@ -602,6 +612,13 @@ later is required to fix a server side protocol bug. | |||
602 | % (self.manifest.manifest_server, e.errcode, e.errmsg), | 612 | % (self.manifest.manifest_server, e.errcode, e.errmsg), |
603 | file=sys.stderr) | 613 | file=sys.stderr) |
604 | sys.exit(1) | 614 | sys.exit(1) |
615 | else: # Not smart sync or smart tag mode | ||
616 | if os.path.isfile(smart_sync_manifest_path): | ||
617 | try: | ||
618 | os.remove(smart_sync_manifest_path) | ||
619 | except OSError as e: | ||
620 | print('error: failed to remove existing smart sync override manifest: %s' % | ||
621 | e, file=sys.stderr) | ||
605 | 622 | ||
606 | rp = self.manifest.repoProject | 623 | rp = self.manifest.repoProject |
607 | rp.PreSync() | 624 | rp.PreSync() |
@@ -615,7 +632,8 @@ later is required to fix a server side protocol bug. | |||
615 | if not opt.local_only: | 632 | if not opt.local_only: |
616 | mp.Sync_NetworkHalf(quiet=opt.quiet, | 633 | mp.Sync_NetworkHalf(quiet=opt.quiet, |
617 | current_branch_only=opt.current_branch_only, | 634 | current_branch_only=opt.current_branch_only, |
618 | no_tags=opt.no_tags) | 635 | no_tags=opt.no_tags, |
636 | optimized_fetch=opt.optimized_fetch) | ||
619 | 637 | ||
620 | if mp.HasChanges: | 638 | if mp.HasChanges: |
621 | syncbuf = SyncBuffer(mp.config) | 639 | syncbuf = SyncBuffer(mp.config) |