From 19e1ff660db8a6653d67884d10bc830babc1560d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 13 Oct 2019 17:16:35 +0200 Subject: improve patch handling in allocator.py * patches are only applied if they aren't applied already * patch no uses -p0 so git diff patches must be adjusted --- src/allocator.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/allocator.py') diff --git a/src/allocator.py b/src/allocator.py index b88b046..c418776 100644 --- a/src/allocator.py +++ b/src/allocator.py @@ -89,9 +89,17 @@ class Allocator: print_status("Patching", self.name, "...") for patch in self.patches: with open(patch.format(patchdir=self.patchdir), "rb") as patch_file: - proc = subprocess.run("patch -p1", shell=True, cwd=cwd, + patch_content = patch_file.read() + + # check if patch is already applied + proc = subprocess.run(["patch", "-R", "-p0", "-s", "-f", "--dry-run"], + cwd=cwd, stderr=None, stdout=None, + input=patch_content) + + if proc.returncode != 0: + proc = subprocess.run(["patch", "-p0"], cwd=cwd, stderr=subprocess.PIPE, stdout=stdout, - input=patch_file.read()) + input=patch_content) if proc.returncode: print_debug(proc.stderr, file=sys.stderr) @@ -115,7 +123,6 @@ class Allocator: build_needed = not os.path.isdir(self.dir) buildtimestamp_path = os.path.join(self.dir, ".buildtime") - print_status("Building", self.name, "...") if not build_needed: print_info2("Old build found. Comparing build time with mtime") @@ -133,6 +140,7 @@ class Allocator: if build_needed: self.prepare() + print_status("Building", self.name, "...") if self.build_cmds: stdout = subprocess.PIPE if src.globalvars.verbosity < 2 else None -- cgit v1.2.3