|
58 | 58 | import pathlib |
59 | 59 |
|
60 | 60 | import dfetch.commands.command |
| 61 | +import dfetch.manifest.project |
61 | 62 | from dfetch.log import get_logger |
62 | 63 | from dfetch.project import create_super_project |
63 | 64 | from dfetch.project.metadata import Metadata |
64 | | -from dfetch.project.superproject import NoVcsSuperProject, RevisionRange |
65 | | -from dfetch.util.util import catch_runtime_exceptions, in_directory |
| 65 | +from dfetch.project.superproject import NoVcsSuperProject, RevisionRange, SuperProject |
| 66 | +from dfetch.util.util import in_directory |
66 | 67 |
|
67 | 68 | logger = get_logger(__name__) |
68 | 69 |
|
@@ -115,51 +116,62 @@ def __call__(self, args: argparse.Namespace) -> None: |
115 | 116 | ) |
116 | 117 |
|
117 | 118 | with in_directory(superproject.root_directory): |
118 | | - exceptions: list[str] = [] |
119 | 119 | projects = superproject.manifest.selected_projects(args.projects) |
120 | 120 | if not projects: |
121 | 121 | raise RuntimeError( |
122 | 122 | f"No (such) project found! {', '.join(args.projects)}" |
123 | 123 | ) |
| 124 | + had_errors: bool = False |
124 | 125 | for project in projects: |
125 | | - with catch_runtime_exceptions(exceptions) as exceptions: |
126 | | - if not os.path.exists(project.destination): |
127 | | - raise RuntimeError( |
128 | | - "You cannot generate a diff of a project that was never fetched" |
129 | | - ) |
130 | | - subproject = superproject.get_sub_project(project) |
131 | | - |
132 | | - if not subproject: |
133 | | - raise RuntimeError("No subproject!") |
134 | | - |
135 | | - old_rev = old_rev or superproject.get_file_revision( |
136 | | - subproject.metadata_path |
137 | | - ) |
138 | | - if not old_rev: |
139 | | - raise RuntimeError( |
140 | | - "When not providing any revisions, dfetch starts from" |
141 | | - f" the last revision to {Metadata.FILENAME} in {subproject.local_path}." |
142 | | - " Please either commit this, or specify a revision to start from with --revs" |
143 | | - ) |
144 | | - patch = superproject.diff( |
145 | | - project.destination, |
146 | | - revisions=RevisionRange(old_rev, new_rev), |
147 | | - ignore=(Metadata.FILENAME,), |
148 | | - ) |
149 | | - |
150 | | - msg = self._rev_msg(old_rev, new_rev) |
151 | | - if patch: |
152 | | - patch_path = pathlib.Path(f"{project.name}.patch") |
153 | | - logger.print_info_line( |
154 | | - project.name, |
155 | | - f"Generating patch {patch_path} {msg} in {superproject.root_directory}", |
156 | | - ) |
157 | | - patch_path.write_text(patch, encoding="UTF-8") |
158 | | - else: |
159 | | - logger.print_info_line(project.name, f"No diffs found {msg}") |
160 | | - |
161 | | - if exceptions: |
162 | | - raise RuntimeError("\n".join(exceptions)) |
| 126 | + try: |
| 127 | + self._diff_project(superproject, project, old_rev, new_rev) |
| 128 | + except RuntimeError as exc: |
| 129 | + logger.print_error_line(project.name, str(exc)) |
| 130 | + had_errors = True |
| 131 | + |
| 132 | + if had_errors: |
| 133 | + raise RuntimeError() |
| 134 | + |
| 135 | + def _diff_project( |
| 136 | + self, |
| 137 | + superproject: SuperProject, |
| 138 | + project: dfetch.manifest.project.ProjectEntry, |
| 139 | + old_rev: str, |
| 140 | + new_rev: str, |
| 141 | + ) -> None: |
| 142 | + """Generate a diff patch for a single project.""" |
| 143 | + if not os.path.exists(project.destination): |
| 144 | + raise RuntimeError( |
| 145 | + "You cannot generate a diff of a project that was never fetched" |
| 146 | + ) |
| 147 | + subproject = superproject.get_sub_project(project) |
| 148 | + |
| 149 | + if not subproject: |
| 150 | + raise RuntimeError("No subproject!") |
| 151 | + |
| 152 | + old_rev = old_rev or superproject.get_file_revision(subproject.metadata_path) |
| 153 | + if not old_rev: |
| 154 | + raise RuntimeError( |
| 155 | + "When not providing any revisions, dfetch starts from" |
| 156 | + f" the last revision to {Metadata.FILENAME} in {subproject.local_path}." |
| 157 | + " Please either commit this, or specify a revision to start from with --revs" |
| 158 | + ) |
| 159 | + patch = superproject.diff( |
| 160 | + project.destination, |
| 161 | + revisions=RevisionRange(old_rev, new_rev), |
| 162 | + ignore=(Metadata.FILENAME,), |
| 163 | + ) |
| 164 | + |
| 165 | + msg = self._rev_msg(old_rev, new_rev) |
| 166 | + if patch: |
| 167 | + patch_path = pathlib.Path(f"{project.name}.patch") |
| 168 | + logger.print_info_line( |
| 169 | + project.name, |
| 170 | + f"Generating patch {patch_path} {msg} in {superproject.root_directory}", |
| 171 | + ) |
| 172 | + patch_path.write_text(patch, encoding="UTF-8") |
| 173 | + else: |
| 174 | + logger.print_info_line(project.name, f"No diffs found {msg}") |
163 | 175 |
|
164 | 176 | @staticmethod |
165 | 177 | def _parse_revs(revs_arg: str) -> tuple[str, str]: |
|
0 commit comments