diff options
| -rw-r--r-- | patchtree/config.py | 1 | ||||
| -rw-r--r-- | patchtree/context.py | 12 | ||||
| -rw-r--r-- | patchtree/diff.py | 8 | ||||
| -rw-r--r-- | patchtree/process.py | 5 |
4 files changed, 22 insertions, 4 deletions
diff --git a/patchtree/config.py b/patchtree/config.py index 065b03c..79e82dc 100644 --- a/patchtree/config.py +++ b/patchtree/config.py @@ -11,6 +11,7 @@ DEFAULT_PROCESSORS: dict[str, type[Process]] = { "jinja": ProcessJinja2, "cocci": ProcessCoccinelle, "smpl": ProcessCoccinelle, + "touch": ProcessTouch, } DEFAULT_DIFFS: dict[str, type[Diff]] = { diff --git a/patchtree/context.py b/patchtree/context.py index 2721f9b..c864307 100644 --- a/patchtree/context.py +++ b/patchtree/context.py @@ -43,7 +43,11 @@ class DiskFS(FS): here = self.path.joinpath(file) if not here.exists(): return None - return here.read_bytes().decode() + bytes = here.read_bytes() + try: + return bytes.decode() + except: + return "" def get_mode(self, file: str) -> int: here = self.path.joinpath(file) @@ -83,7 +87,11 @@ class ZipFS(FS): info = self.get_info(file) if info is None: return None - return self.zip.read(info).decode() + bytes = self.zip.read(info) + try: + return bytes.decode() + except: + return "" def get_mode(self, file: str) -> int: info = self.get_info(file) diff --git a/patchtree/diff.py b/patchtree/diff.py index a3442ae..9712f77 100644 --- a/patchtree/diff.py +++ b/patchtree/diff.py @@ -33,11 +33,15 @@ class Diff: """ a = self.a b = self.b - fromfile = f"a/{self.file}" - tofile = f"b/{self.file}" + + if a == b: + return "" assert (a.content or b.content) is not None + fromfile = f"a/{self.file}" + tofile = f"b/{self.file}" + delta = f"diff --git {fromfile} {tofile}\n" if a.content is None: diff --git a/patchtree/process.py b/patchtree/process.py index a44886d..3ac47b1 100644 --- a/patchtree/process.py +++ b/patchtree/process.py @@ -72,3 +72,8 @@ class ProcessCoccinelle(Process): temp_sp.unlink() return b + + +class ProcessTouch(Process): + def transform(self, a, b): + return DiffFile(content=a.content, mode=b.mode) |