diff options
Diffstat (limited to 'subcmds/checkout.py')
| -rw-r--r-- | subcmds/checkout.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/subcmds/checkout.py b/subcmds/checkout.py index 379bfa18..859ddf6c 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py | |||
| @@ -20,7 +20,6 @@ from command import DEFAULT_LOCAL_JOBS | |||
| 20 | from error import GitError | 20 | from error import GitError |
| 21 | from error import RepoExitError | 21 | from error import RepoExitError |
| 22 | from progress import Progress | 22 | from progress import Progress |
| 23 | from project import Project | ||
| 24 | from repo_logging import RepoLogger | 23 | from repo_logging import RepoLogger |
| 25 | 24 | ||
| 26 | 25 | ||
| @@ -30,7 +29,7 @@ logger = RepoLogger(__file__) | |||
| 30 | class CheckoutBranchResult(NamedTuple): | 29 | class CheckoutBranchResult(NamedTuple): |
| 31 | # Whether the Project is on the branch (i.e. branch exists and no errors) | 30 | # Whether the Project is on the branch (i.e. branch exists and no errors) |
| 32 | result: bool | 31 | result: bool |
| 33 | project: Project | 32 | project_idx: int |
| 34 | error: Exception | 33 | error: Exception |
| 35 | 34 | ||
| 36 | 35 | ||
| @@ -62,15 +61,17 @@ The command is equivalent to: | |||
| 62 | if not args: | 61 | if not args: |
| 63 | self.Usage() | 62 | self.Usage() |
| 64 | 63 | ||
| 65 | def _ExecuteOne(self, nb, project): | 64 | @classmethod |
| 65 | def _ExecuteOne(cls, nb, project_idx): | ||
| 66 | """Checkout one project.""" | 66 | """Checkout one project.""" |
| 67 | error = None | 67 | error = None |
| 68 | result = None | 68 | result = None |
| 69 | project = cls.get_parallel_context()["projects"][project_idx] | ||
| 69 | try: | 70 | try: |
| 70 | result = project.CheckoutBranch(nb) | 71 | result = project.CheckoutBranch(nb) |
| 71 | except GitError as e: | 72 | except GitError as e: |
| 72 | error = e | 73 | error = e |
| 73 | return CheckoutBranchResult(result, project, error) | 74 | return CheckoutBranchResult(result, project_idx, error) |
| 74 | 75 | ||
| 75 | def Execute(self, opt, args): | 76 | def Execute(self, opt, args): |
| 76 | nb = args[0] | 77 | nb = args[0] |
| @@ -83,22 +84,25 @@ The command is equivalent to: | |||
| 83 | 84 | ||
| 84 | def _ProcessResults(_pool, pm, results): | 85 | def _ProcessResults(_pool, pm, results): |
| 85 | for result in results: | 86 | for result in results: |
| 87 | project = all_projects[result.project_idx] | ||
| 86 | if result.error is not None: | 88 | if result.error is not None: |
| 87 | err.append(result.error) | 89 | err.append(result.error) |
| 88 | err_projects.append(result.project) | 90 | err_projects.append(project) |
| 89 | elif result.result: | 91 | elif result.result: |
| 90 | success.append(result.project) | 92 | success.append(project) |
| 91 | pm.update(msg="") | 93 | pm.update(msg="") |
| 92 | 94 | ||
| 93 | self.ExecuteInParallel( | 95 | with self.ParallelContext(): |
| 94 | opt.jobs, | 96 | self.get_parallel_context()["projects"] = all_projects |
| 95 | functools.partial(self._ExecuteOne, nb), | 97 | self.ExecuteInParallel( |
| 96 | all_projects, | 98 | opt.jobs, |
| 97 | callback=_ProcessResults, | 99 | functools.partial(self._ExecuteOne, nb), |
| 98 | output=Progress( | 100 | range(len(all_projects)), |
| 99 | f"Checkout {nb}", len(all_projects), quiet=opt.quiet | 101 | callback=_ProcessResults, |
| 100 | ), | 102 | output=Progress( |
| 101 | ) | 103 | f"Checkout {nb}", len(all_projects), quiet=opt.quiet |
| 104 | ), | ||
| 105 | ) | ||
| 102 | 106 | ||
| 103 | if err_projects: | 107 | if err_projects: |
| 104 | for p in err_projects: | 108 | for p in err_projects: |
