aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-10-25 16:06:20 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2025-10-25 16:06:20 +0200
commit26cb18a5caba723e75d2728cf731a6066a4d1c87 (patch)
treeabb174b5635bd0c5667cf78bcc266794dd61ce6e
parentc12e268727a44dfcbe696e6116777da305fc1046 (diff)
add #touch processor
-rw-r--r--patchtree/config.py1
-rw-r--r--patchtree/context.py12
-rw-r--r--patchtree/diff.py8
-rw-r--r--patchtree/process.py5
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)