Skip to content

Commit 9b0f79f

Browse files
committed
Simplify diff
1 parent 36effa8 commit 9b0f79f

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

dfetch/commands/diff.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,25 @@ def __call__(self, args: argparse.Namespace) -> None:
153153
f"No (such) project found! {', '.join(args.projects)}"
154154
)
155155
for project in projects:
156-
patch_name = f"{project.name}.patch"
157156
with catch_runtime_exceptions(exceptions) as exceptions:
158157
patch = _get_sub_project(superproject, project).diff(revs)
159158

160-
_dump_patch(
161-
superproject.root_directory, revs, project, patch_name, patch
159+
rev_range = (
160+
f"from {revs[0]} to {revs[1]}"
161+
if revs[1]
162+
else f"since {revs[0]}"
162163
)
164+
if patch:
165+
patch_path = pathlib.Path(f"{project.name}.patch")
166+
logger.print_info_line(
167+
project.name,
168+
f"Generating patch {patch_path} {rev_range} in {superproject.root_directory}",
169+
)
170+
patch_path.write_text(patch, encoding="UTF-8")
171+
else:
172+
logger.print_info_line(
173+
project.name, f"No diffs found {rev_range}"
174+
)
163175

164176
if exceptions:
165177
raise RuntimeError("\n".join(exceptions))
@@ -179,23 +191,3 @@ def _get_sub_project(superproject: SuperProject, project: ProjectEntry) -> SubPr
179191
raise RuntimeError(
180192
"Can only create patch if your project is an SVN or Git repo",
181193
)
182-
183-
184-
def _dump_patch(
185-
path: str, revs: list[str], project: ProjectEntry, patch_name: str, patch: str
186-
) -> None:
187-
"""Dump the patch to a file."""
188-
if patch:
189-
rev_range = f"from {revs[0]} to {revs[1]}" if revs[1] else f"since {revs[0]}"
190-
logger.print_info_line(
191-
project.name,
192-
f"Generating patch {patch_name} {rev_range} in {os.path.dirname(path)}",
193-
)
194-
pathlib.Path(patch_name).write_text(patch, encoding="UTF-8")
195-
else:
196-
if revs[1]:
197-
msg = f"No diffs found from {revs[0]} to {revs[1]}"
198-
else:
199-
msg = f"No diffs found since {revs[0]}"
200-
201-
logger.print_info_line(project.name, msg)

0 commit comments

Comments
 (0)