2929import pathlib
3030import re
3131
32- import patch_ng
33-
3432import dfetch .commands .command
3533import dfetch .manifest .project
3634import dfetch .project
4038from dfetch .project .subproject import SubProject
4139from dfetch .project .svnsubproject import SvnSubProject
4240from dfetch .util .util import catch_runtime_exceptions , in_directory
43- from dfetch .vcs .patch import (
44- PatchAuthor ,
45- PatchInfo ,
46- add_prefix_to_patch ,
47- convert_patch_to ,
48- dump_patch ,
49- parse_patch ,
50- )
41+ from dfetch .vcs .patch import Patch , PatchAuthor , PatchInfo , PatchType
5142
5243logger = get_logger (__name__ )
5344
@@ -112,7 +103,7 @@ def __call__(self, args: argparse.Namespace) -> None:
112103 continue
113104
114105 version = subproject .on_disk_version ()
115- for idx , patch in enumerate (subproject .patch , start = 1 ):
106+ for idx , patch_file in enumerate (subproject .patch , start = 1 ):
116107
117108 patch_info = PatchInfo (
118109 author = PatchAuthor (
@@ -125,20 +116,19 @@ def __call__(self, args: argparse.Namespace) -> None:
125116 revision = "" if not version else version .revision ,
126117 )
127118
128- corrected_patch = convert_patch_to (
129- parse_patch ( patch ), _determine_target_patch_type (subproject )
119+ patch = Patch . from_file ( patch_file ). convert_type (
120+ _determine_target_patch_type (subproject )
130121 )
131- prefixed_patch = add_prefix_to_patch (
132- corrected_patch ,
133- path_prefix = re .split (r"\*" , subproject .source , 1 )[0 ].rstrip (
134- "/"
135- ),
122+ patch .add_prefix (
123+ re .split (r"\*" , subproject .source , 1 )[0 ].rstrip ("/" )
136124 )
137125
138- output_patch_file = output_dir_path / pathlib .Path (patch ).name
126+ output_patch_file = (
127+ output_dir_path / pathlib .Path (patch_file ).name
128+ )
139129 output_patch_file .write_text (
140- subproject . create_formatted_patch_header (patch_info )
141- + dump_patch ( prefixed_patch )
130+ patch . dump_header (patch_info ) + patch . dump (),
131+ encoding = "utf-8" ,
142132 )
143133
144134 logger .print_info_line (
@@ -150,13 +140,13 @@ def __call__(self, args: argparse.Namespace) -> None:
150140 raise RuntimeError ("\n " .join (exceptions ))
151141
152142
153- def _determine_target_patch_type (subproject : SubProject ) -> str :
143+ def _determine_target_patch_type (subproject : SubProject ) -> PatchType :
154144 """Determine the subproject type for the patch."""
155145 if isinstance (subproject , GitSubProject ):
156- required_type = patch_ng .GIT
146+ required_type = PatchType .GIT
157147 elif isinstance (subproject , SvnSubProject ):
158- required_type = patch_ng .SVN
148+ required_type = PatchType .SVN
159149 else :
160- required_type = patch_ng .PLAIN
150+ required_type = PatchType .PLAIN
161151
162- return str ( required_type )
152+ return required_type
0 commit comments